summaryrefslogtreecommitdiff
path: root/mcp-servers/simple-mcp-server/.claude/hooks/dev-watch.sh
blob: 1d2b5fcb3b4f6bc95c1dc4398e64a1c8e01713f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash

# Development Watch Hook for Simple MCP Server
# Automatically triggered on TypeScript file changes

set -e

# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color

echo -e "${GREEN}๐Ÿ”„ Development Watch Hook Triggered${NC}"

# Get the modified file
MODIFIED_FILE="$1"

# Skip if not a TypeScript file
if [[ ! "$MODIFIED_FILE" =~ \.ts$ ]]; then
    exit 0
fi

# Skip node_modules and dist
if [[ "$MODIFIED_FILE" =~ node_modules|dist|coverage ]]; then
    exit 0
fi

echo "๐Ÿ“ File changed: $MODIFIED_FILE"

# Type checking
echo -e "${YELLOW}โœ… Running type check...${NC}"
if npx tsc --noEmit 2>/dev/null; then
    echo -e "${GREEN}  โœ“ Type checking passed${NC}"
else
    echo -e "${RED}  โœ— Type checking failed${NC}"
    exit 1
fi

# Format with prettier
if command -v prettier &> /dev/null; then
    echo -e "${YELLOW}๐ŸŽจ Formatting with Prettier...${NC}"
    npx prettier --write "$MODIFIED_FILE" 2>/dev/null || true
    echo -e "${GREEN}  โœ“ Formatted${NC}"
fi

# Lint with ESLint
if [ -f .eslintrc.json ] || [ -f .eslintrc.js ]; then
    echo -e "${YELLOW}๐Ÿ” Linting with ESLint...${NC}"
    if npx eslint "$MODIFIED_FILE" --fix 2>/dev/null; then
        echo -e "${GREEN}  โœ“ Linting passed${NC}"
    else
        echo -e "${YELLOW}  โš  Linting warnings${NC}"
    fi
fi

# Run tests if it's a test file or if the corresponding test exists
if [[ "$MODIFIED_FILE" =~ \.test\.ts$ ]] || [[ "$MODIFIED_FILE" =~ \.spec\.ts$ ]]; then
    echo -e "${YELLOW}๐Ÿงช Running tests for $MODIFIED_FILE...${NC}"
    if npx vitest run "$MODIFIED_FILE" 2>/dev/null; then
        echo -e "${GREEN}  โœ“ Tests passed${NC}"
    else
        echo -e "${RED}  โœ— Tests failed${NC}"
        exit 1
    fi
else
    # Check if corresponding test file exists
    TEST_FILE="${MODIFIED_FILE%.ts}.test.ts"
    TEST_FILE_SPEC="${MODIFIED_FILE%.ts}.spec.ts"
    
    if [ -f "$TEST_FILE" ]; then
        echo -e "${YELLOW}๐Ÿงช Running related tests...${NC}"
        npx vitest run "$TEST_FILE" 2>/dev/null || true
    elif [ -f "$TEST_FILE_SPEC" ]; then
        echo -e "${YELLOW}๐Ÿงช Running related tests...${NC}"
        npx vitest run "$TEST_FILE_SPEC" 2>/dev/null || true
    fi
fi

# Update tool/resource counts if applicable
if [[ "$MODIFIED_FILE" =~ src/tools/ ]] || [[ "$MODIFIED_FILE" =~ src/resources/ ]] || [[ "$MODIFIED_FILE" =~ src/prompts/ ]]; then
    echo -e "${YELLOW}๐Ÿ“Š Updating capability counts...${NC}"
    
    TOOL_COUNT=$(find src/tools -name "*.ts" -not -name "index.ts" 2>/dev/null | wc -l || echo 0)
    RESOURCE_COUNT=$(find src/resources -name "*.ts" -not -name "index.ts" 2>/dev/null | wc -l || echo 0)
    PROMPT_COUNT=$(find src/prompts -name "*.ts" -not -name "index.ts" 2>/dev/null | wc -l || echo 0)
    
    echo "  Tools: $TOOL_COUNT"
    echo "  Resources: $RESOURCE_COUNT"
    echo "  Prompts: $PROMPT_COUNT"
fi

echo -e "${GREEN}โœ… Development checks complete${NC}"