summaryrefslogtreecommitdiff
path: root/mcp-servers/simple-mcp-server/.claude/hooks/pre-build.sh
blob: a72ff45dd8741ac490a932aa89418ab6ab57ab93 (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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/bin/bash

# Pre-Build Hook for Simple MCP Server
# Runs before building for production

set -e

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

echo -e "${BLUE}๐Ÿ”จ Pre-Build Hook${NC}"
echo "======================================"

# Check for uncommitted changes
if git diff --quiet && git diff --staged --quiet; then
    echo -e "${GREEN}โœ“ Working directory clean${NC}"
else
    echo -e "${YELLOW}โš  Warning: Uncommitted changes detected${NC}"
    git status --short
fi

# Lint check
echo -e "\n${YELLOW}๐Ÿ” Running lint check...${NC}"
if npx eslint src --ext .ts 2>/dev/null; then
    echo -e "${GREEN}  โœ“ Linting passed${NC}"
else
    echo -e "${RED}  โœ— Linting failed${NC}"
    echo "  Run 'npm run lint:fix' to fix issues"
    exit 1
fi

# Type validation
echo -e "\n${YELLOW}๐Ÿ“ Running type check...${NC}"
if npx tsc --noEmit; then
    echo -e "${GREEN}  โœ“ Type checking passed${NC}"
else
    echo -e "${RED}  โœ— Type checking failed${NC}"
    exit 1
fi

# Test suite
echo -e "\n${YELLOW}๐Ÿงช Running tests...${NC}"
if npm test 2>/dev/null; then
    echo -e "${GREEN}  โœ“ All tests passed${NC}"
else
    echo -e "${RED}  โœ— Tests failed${NC}"
    exit 1
fi

# Dependency audit
echo -e "\n${YELLOW}๐Ÿ”’ Checking dependencies...${NC}"
AUDIT_RESULT=$(npm audit --production 2>&1)
if echo "$AUDIT_RESULT" | grep -q "found 0 vulnerabilities"; then
    echo -e "${GREEN}  โœ“ No vulnerabilities found${NC}"
else
    echo -e "${YELLOW}  โš  Security vulnerabilities detected${NC}"
    echo "  Run 'npm audit fix' to resolve"
fi

# Version validation
echo -e "\n${YELLOW}๐Ÿท๏ธ Checking version...${NC}"
PACKAGE_VERSION=$(node -p "require('./package.json').version")
echo "  Current version: $PACKAGE_VERSION"

# Check if version tag exists
if git rev-parse "v$PACKAGE_VERSION" >/dev/null 2>&1; then
    echo -e "${GREEN}  โœ“ Version tag exists${NC}"
else
    echo -e "${YELLOW}  โš  Version tag v$PACKAGE_VERSION not found${NC}"
    echo "  Create with: git tag v$PACKAGE_VERSION"
fi

# Check package.json required fields
echo -e "\n${YELLOW}๐Ÿ“ฆ Validating package.json...${NC}"
NAME=$(node -p "require('./package.json').name" 2>/dev/null)
DESCRIPTION=$(node -p "require('./package.json').description" 2>/dev/null)
MAIN=$(node -p "require('./package.json').main" 2>/dev/null)

if [ -z "$NAME" ]; then
    echo -e "${RED}  โœ— Missing 'name' field${NC}"
    exit 1
fi

if [ -z "$DESCRIPTION" ]; then
    echo -e "${YELLOW}  โš  Missing 'description' field${NC}"
fi

if [ -z "$MAIN" ]; then
    echo -e "${YELLOW}  โš  Missing 'main' field${NC}"
fi

echo -e "${GREEN}  โœ“ Package metadata valid${NC}"

# MCP specific checks
echo -e "\n${YELLOW}๐Ÿ”Œ Checking MCP implementation...${NC}"

# Check for required MCP files
if [ -f "src/index.ts" ]; then
    echo -e "${GREEN}  โœ“ Entry point exists${NC}"
else
    echo -e "${RED}  โœ— Missing src/index.ts${NC}"
    exit 1
fi

# Count capabilities
TOOL_COUNT=0
RESOURCE_COUNT=0
PROMPT_COUNT=0

if [ -d "src/tools" ]; then
    TOOL_COUNT=$(find src/tools -name "*.ts" -not -name "index.ts" | wc -l)
fi

if [ -d "src/resources" ]; then
    RESOURCE_COUNT=$(find src/resources -name "*.ts" -not -name "index.ts" | wc -l)
fi

if [ -d "src/prompts" ]; then
    PROMPT_COUNT=$(find src/prompts -name "*.ts" -not -name "index.ts" | wc -l)
fi

echo "  Capabilities:"
echo "    - Tools: $TOOL_COUNT"
echo "    - Resources: $RESOURCE_COUNT"
echo "    - Prompts: $PROMPT_COUNT"

if [ $TOOL_COUNT -eq 0 ] && [ $RESOURCE_COUNT -eq 0 ] && [ $PROMPT_COUNT -eq 0 ]; then
    echo -e "${YELLOW}  โš  No MCP capabilities implemented${NC}"
fi

# Final summary
echo ""
echo "======================================"
echo -e "${GREEN}โœ… Pre-build checks complete${NC}"
echo "Ready to build for production!"
echo ""
echo "Next steps:"
echo "  1. npm run build"
echo "  2. npm test"
echo "  3. npm publish (if deploying to npm)"