blob: fe390d22a13ba9ee70eccd95bbc28aa131418a88 (
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
|
#!/bin/bash
# Enhanced TypeScript development hook
# Handles compilation checks, formatting, and test auto-run
input=$(cat)
tool_name=$(echo "$input" | jq -r '.tool_name')
file_path=$(echo "$input" | jq -r '.tool_input.file_path // empty')
# Only process TypeScript/JavaScript files
if [[ ! "$file_path" =~ \.(ts|tsx|js|jsx|mjs)$ ]]; then
exit 0
fi
# Skip node_modules and build directories
if [[ "$file_path" == *"/node_modules/"* ]] || [[ "$file_path" == *"/dist/"* ]] || [[ "$file_path" == *"/build/"* ]]; then
exit 0
fi
# Extract project directory
PROJECT_DIR="${CLAUDE_PROJECT_DIR:-$(pwd)}"
cd "$PROJECT_DIR"
# Check if this is a TypeScript project
if [ -f "tsconfig.json" ]; then
# Run TypeScript compiler in check mode (no emit)
if command -v tsc &> /dev/null; then
echo "🔍 TypeScript check for ${file_path##*/}..."
npx tsc --noEmit --skipLibCheck 2>&1 | head -20 || true
fi
fi
# Format with prettier if available
if [ -f ".prettierrc" ] || [ -f ".prettierrc.json" ] || [ -f "prettier.config.js" ]; then
if command -v prettier &> /dev/null || [ -f "node_modules/.bin/prettier" ]; then
echo "✨ Formatting ${file_path##*/}..."
npx prettier --write "$file_path" 2>/dev/null || true
fi
fi
# Run ESLint if available
if [ -f ".eslintrc.json" ] || [ -f ".eslintrc.js" ] || [ -f "eslint.config.js" ]; then
if command -v eslint &> /dev/null || [ -f "node_modules/.bin/eslint" ]; then
echo "🔧 Linting ${file_path##*/}..."
npx eslint --fix "$file_path" 2>&1 | head -10 || true
fi
fi
# Auto-run tests if this is a test file modification
if [[ "$file_path" == *".test."* ]] || [[ "$file_path" == *".spec."* ]]; then
if [ -f "package.json" ] && grep -q '"test"' package.json; then
echo "🧪 Running tests for ${file_path##*/}..."
npm test -- "$file_path" 2>&1 | head -30 || true
fi
fi
exit 0
|