@localtech/claude-code-toolkit 1.0.3 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/install.d.ts.map +1 -1
- package/dist/commands/install.js +8 -7
- package/dist/commands/install.js.map +1 -1
- package/package.json +1 -1
- package/templates/.claude/hooks/README.md +342 -0
- package/templates/.claude/hooks/custom/intelligent-workflows.sh +336 -0
- package/templates/.claude/hooks/hook-manager.sh +300 -0
- package/templates/.claude/hooks/post-commit/smart-automations.sh +249 -0
- package/templates/.claude/hooks/pre-commit/code-quality-guardian.sh +257 -0
- package/templates/.claude/hooks/pre-push/deployment-guardian.sh +334 -0
- package/templates/.claude/memory/context.md +39 -0
- package/templates/.claude/memory/decisions.md +29 -0
- package/templates/.claude/memory/learnings.md +31 -0
- package/templates/.claude/memory/patterns.md +72 -0
- package/templates/.claude/memory/preferences.md +23 -0
- package/templates/.claude/skills/claude-code-hooks-master/SKILL.md +358 -0
- package/templates/.claude/skills/mobile-ui-ux-master/MobileCardGrid.tsx +270 -0
- package/templates/.claude/skills/mobile-ui-ux-master/SKILL.md +172 -0
- package/templates/.claude/skills/mobile-ui-ux-master/card-grid-template.html +260 -0
- package/templates/.claude/skills/mobile-ui-ux-master/mobile-ux-checklist.md +140 -0
- package/templates/.claude/skills/professional-documentation-writer/SKILL.md +42 -0
- package/templates/AGENTS.md +127 -0
- package/templates/CLAUDE.md +101 -0
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# HOOK: post-commit-smart-automations
|
|
3
|
+
# DESCRIPTION: Intelligent post-commit automations for documentation, notifications, and workflow optimization
|
|
4
|
+
# AUTHOR: Claude Code Hooks Master
|
|
5
|
+
# VERSION: 1.0.0
|
|
6
|
+
|
|
7
|
+
set -e
|
|
8
|
+
|
|
9
|
+
# Colors for output
|
|
10
|
+
GREEN='\033[0;32m'
|
|
11
|
+
BLUE='\033[0;34m'
|
|
12
|
+
YELLOW='\033[1;33m'
|
|
13
|
+
RED='\033[0;31m'
|
|
14
|
+
NC='\033[0m'
|
|
15
|
+
|
|
16
|
+
log_info() {
|
|
17
|
+
echo -e "${BLUE}[AUTO]${NC} $1"
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
log_success() {
|
|
21
|
+
echo -e "${GREEN}[DONE]${NC} $1"
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
log_warn() {
|
|
25
|
+
echo -e "${YELLOW}[WARN]${NC} $1"
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
# Get commit information
|
|
29
|
+
get_commit_info() {
|
|
30
|
+
COMMIT_HASH=$(git rev-parse HEAD)
|
|
31
|
+
COMMIT_MSG=$(git log -1 --pretty=%B)
|
|
32
|
+
COMMIT_AUTHOR=$(git log -1 --pretty=%an)
|
|
33
|
+
COMMIT_EMAIL=$(git log -1 --pretty=%ae)
|
|
34
|
+
CHANGED_FILES=$(git diff --name-only HEAD~1)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
# Analyze commit type and impact
|
|
38
|
+
analyze_commit_impact() {
|
|
39
|
+
local commit_msg="$1"
|
|
40
|
+
local changed_files="$2"
|
|
41
|
+
|
|
42
|
+
# Determine commit type
|
|
43
|
+
if echo "$commit_msg" | grep -q -i "feat\|feature\|add"; then
|
|
44
|
+
COMMIT_TYPE="feature"
|
|
45
|
+
elif echo "$commit_msg" | grep -q -i "fix\|bug\|hotfix"; then
|
|
46
|
+
COMMIT_TYPE="fix"
|
|
47
|
+
elif echo "$commit_msg" | grep -q -i "docs\|documentation"; then
|
|
48
|
+
COMMIT_TYPE="docs"
|
|
49
|
+
elif echo "$commit_msg" | grep -q -i "test\|spec"; then
|
|
50
|
+
COMMIT_TYPE="test"
|
|
51
|
+
elif echo "$commit_msg" | grep -q -i "refactor\|style"; then
|
|
52
|
+
COMMIT_TYPE="refactor"
|
|
53
|
+
else
|
|
54
|
+
COMMIT_TYPE="other"
|
|
55
|
+
fi
|
|
56
|
+
|
|
57
|
+
# Determine impact level
|
|
58
|
+
if echo "$changed_files" | grep -q -E "(package\.json|core|config|src/index)"; then
|
|
59
|
+
IMPACT_LEVEL="high"
|
|
60
|
+
elif echo "$changed_files" | grep -q -E "(src/|components/|api/)"; then
|
|
61
|
+
IMPACT_LEVEL="medium"
|
|
62
|
+
else
|
|
63
|
+
IMPACT_LEVEL="low"
|
|
64
|
+
fi
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
# Documentation automation
|
|
68
|
+
run_docs_automation() {
|
|
69
|
+
log_info "Running documentation automation..."
|
|
70
|
+
|
|
71
|
+
# Check if documentation needs updating
|
|
72
|
+
if echo "$CHANGED_FILES" | grep -q -E "\.(js|ts|py)$"; then
|
|
73
|
+
log_info "Code changes detected - checking documentation needs..."
|
|
74
|
+
|
|
75
|
+
# Trigger Claude Code documentation skill
|
|
76
|
+
if command -v claude_code_run_skill &> /dev/null; then
|
|
77
|
+
log_info "Using Claude Code documentation skill..."
|
|
78
|
+
claude_code_run_skill "professional-documentation-writer" "update-api-docs" || true
|
|
79
|
+
else
|
|
80
|
+
log_warn "Claude Code skills not available - skipping automated docs"
|
|
81
|
+
fi
|
|
82
|
+
fi
|
|
83
|
+
|
|
84
|
+
# Update README if necessary
|
|
85
|
+
if echo "$CHANGED_FILES" | grep -q -E "(README|readme)"; then
|
|
86
|
+
log_info "README changes detected - validating format..."
|
|
87
|
+
# Could add README validation here
|
|
88
|
+
fi
|
|
89
|
+
|
|
90
|
+
log_success "Documentation automation completed"
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
# Memory system integration
|
|
94
|
+
update_memory_system() {
|
|
95
|
+
log_info "Updating project memory system..."
|
|
96
|
+
|
|
97
|
+
local memory_dir=".claude/memory"
|
|
98
|
+
if [ ! -d "$memory_dir" ]; then
|
|
99
|
+
log_warn "Memory system not found - skipping memory updates"
|
|
100
|
+
return 0
|
|
101
|
+
fi
|
|
102
|
+
|
|
103
|
+
# Add to decisions memory for architectural decisions
|
|
104
|
+
if echo "$COMMIT_MSG" | grep -q -i "decision\|architect\|design"; then
|
|
105
|
+
{
|
|
106
|
+
echo "## $(date '+%Y-%m-%d %H:%M:%S') - Architecture Decision"
|
|
107
|
+
echo "**Decision**: $COMMIT_MSG"
|
|
108
|
+
echo "**Files Changed**: $CHANGED_FILES"
|
|
109
|
+
echo "**Impact**: $IMPACT_LEVEL"
|
|
110
|
+
echo
|
|
111
|
+
} >> "$memory_dir/decisions.md"
|
|
112
|
+
log_success "Added to decisions memory"
|
|
113
|
+
fi
|
|
114
|
+
|
|
115
|
+
# Add to learnings memory for insights
|
|
116
|
+
if echo "$COMMIT_MSG" | grep -q -i "learn\|discover\|find\|improve"; then
|
|
117
|
+
{
|
|
118
|
+
echo "## $(date '+%Y-%m-%d %H:%M:%S') - Development Learning"
|
|
119
|
+
echo "**Insight**: $COMMIT_MSG"
|
|
120
|
+
echo "**Context**: Commit $COMMIT_HASH"
|
|
121
|
+
echo "**Files**: $CHANGED_FILES"
|
|
122
|
+
echo
|
|
123
|
+
} >> "$memory_dir/learnings.md"
|
|
124
|
+
log_success "Added to learnings memory"
|
|
125
|
+
fi
|
|
126
|
+
|
|
127
|
+
# Update context with recent changes
|
|
128
|
+
{
|
|
129
|
+
echo "## Recent Changes"
|
|
130
|
+
echo "- $(date '+%Y-%m-%d'): $COMMIT_MSG"
|
|
131
|
+
echo " - Type: $COMMIT_TYPE, Impact: $IMPACT_LEVEL"
|
|
132
|
+
echo " - Files: $(echo "$CHANGED_FILES" | wc -l) files changed"
|
|
133
|
+
} >> "$memory_dir/context.md"
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
# Notification system
|
|
137
|
+
send_notifications() {
|
|
138
|
+
log_info "Sending notifications..."
|
|
139
|
+
|
|
140
|
+
# Skip notifications for low-impact changes
|
|
141
|
+
if [ "$IMPACT_LEVEL" = "low" ] && [ "$COMMIT_TYPE" = "other" ]; then
|
|
142
|
+
log_info "Low-impact change - skipping notifications"
|
|
143
|
+
return 0
|
|
144
|
+
fi
|
|
145
|
+
|
|
146
|
+
# In a real implementation, you would integrate with:
|
|
147
|
+
# - Slack/Discord webhooks
|
|
148
|
+
# - Email notifications
|
|
149
|
+
# - Project management tools (Jira, Linear, etc.)
|
|
150
|
+
# - CI/CD status updates
|
|
151
|
+
|
|
152
|
+
log_info "Would notify team about: $COMMIT_TYPE change ($IMPACT_LEVEL impact)"
|
|
153
|
+
log_info "Commit: $COMMIT_HASH by $COMMIT_AUTHOR"
|
|
154
|
+
|
|
155
|
+
# Example notification payload (you would send this to your notification service)
|
|
156
|
+
local notification_data="{
|
|
157
|
+
\"commit\": \"$COMMIT_HASH\",
|
|
158
|
+
\"author\": \"$COMMIT_AUTHOR\",
|
|
159
|
+
\"message\": \"$COMMIT_MSG\",
|
|
160
|
+
\"type\": \"$COMMIT_TYPE\",
|
|
161
|
+
\"impact\": \"$IMPACT_LEVEL\",
|
|
162
|
+
\"files_changed\": $(echo "$CHANGED_FILES" | wc -l)
|
|
163
|
+
}"
|
|
164
|
+
|
|
165
|
+
# For now, just log what would be sent
|
|
166
|
+
log_success "Notification prepared (integrate with your notification service)"
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
# Backup automation
|
|
170
|
+
run_backup_automation() {
|
|
171
|
+
# Only backup for significant changes
|
|
172
|
+
if [ "$IMPACT_LEVEL" != "high" ]; then
|
|
173
|
+
return 0
|
|
174
|
+
fi
|
|
175
|
+
|
|
176
|
+
log_info "Running backup automation for high-impact change..."
|
|
177
|
+
|
|
178
|
+
local backup_dir=".claude/backups"
|
|
179
|
+
mkdir -p "$backup_dir"
|
|
180
|
+
|
|
181
|
+
local timestamp=$(date '+%Y%m%d_%H%M%S')
|
|
182
|
+
local backup_file="$backup_dir/backup_$timestamp.tar.gz"
|
|
183
|
+
|
|
184
|
+
# Create backup of critical files
|
|
185
|
+
if [ -d "src" ] && [ -d "package.json" ]; then
|
|
186
|
+
tar -czf "$backup_file" src/ package.json tsconfig.json 2>/dev/null || true
|
|
187
|
+
log_success "Backup created: $backup_file"
|
|
188
|
+
fi
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
# Performance monitoring
|
|
192
|
+
update_performance_metrics() {
|
|
193
|
+
local metrics_file=".claude/metrics/commit-metrics.json"
|
|
194
|
+
|
|
195
|
+
mkdir -p "$(dirname "$metrics_file")"
|
|
196
|
+
|
|
197
|
+
# Calculate some basic metrics
|
|
198
|
+
local commit_size=$(echo "$CHANGED_FILES" | wc -l)
|
|
199
|
+
local test_files=$(echo "$CHANGED_FILES" | grep -c "\.test\." || echo "0")
|
|
200
|
+
local config_files=$(echo "$CHANGED_FILES" | grep -c -E "(package\.json|config|\.env)" || echo "0")
|
|
201
|
+
|
|
202
|
+
# Create/update metrics
|
|
203
|
+
local metrics="{
|
|
204
|
+
\"timestamp\": \"$(date -Iseconds)\",
|
|
205
|
+
\"commit_hash\": \"$COMMIT_HASH\",
|
|
206
|
+
\"commit_type\": \"$COMMIT_TYPE\",
|
|
207
|
+
\"impact_level\": \"$IMPACT_LEVEL\",
|
|
208
|
+
\"files_changed\": $commit_size,
|
|
209
|
+
\"test_files\": $test_files,
|
|
210
|
+
\"config_files\": $config_files,
|
|
211
|
+
\"author\": \"$COMMIT_AUTHOR\"
|
|
212
|
+
}"
|
|
213
|
+
|
|
214
|
+
echo "$metrics" >> "$metrics_file"
|
|
215
|
+
log_success "Performance metrics updated"
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
# Main execution
|
|
219
|
+
main() {
|
|
220
|
+
log_info "🤖 Claude Code Smart Automations - Post-commit Hook"
|
|
221
|
+
echo "======================================================="
|
|
222
|
+
|
|
223
|
+
# Get commit information
|
|
224
|
+
get_commit_info
|
|
225
|
+
|
|
226
|
+
# Analyze commit
|
|
227
|
+
analyze_commit_impact "$COMMIT_MSG" "$CHANGED_FILES"
|
|
228
|
+
|
|
229
|
+
log_info "Commit Analysis:"
|
|
230
|
+
echo " Type: $COMMIT_TYPE"
|
|
231
|
+
echo " Impact: $IMPACT_LEVEL"
|
|
232
|
+
echo " Author: $COMMIT_AUTHOR"
|
|
233
|
+
echo " Files: $(echo "$CHANGED_FILES" | wc -l)"
|
|
234
|
+
echo
|
|
235
|
+
|
|
236
|
+
# Run automations based on commit characteristics
|
|
237
|
+
run_docs_automation
|
|
238
|
+
update_memory_system
|
|
239
|
+
send_notifications
|
|
240
|
+
run_backup_automation
|
|
241
|
+
update_performance_metrics
|
|
242
|
+
|
|
243
|
+
echo
|
|
244
|
+
log_success "🎉 All post-commit automations completed successfully!"
|
|
245
|
+
log_info "Commit $COMMIT_HASH processed and automated workflows triggered"
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
# Run main function
|
|
249
|
+
main "$@"
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# HOOK: pre-commit-code-quality-guardian
|
|
3
|
+
# DESCRIPTION: Comprehensive code quality checks before commits
|
|
4
|
+
# AUTHOR: Claude Code Hooks Master
|
|
5
|
+
# VERSION: 1.0.0
|
|
6
|
+
# DEPENDS: node, npm, eslint, prettier, typescript
|
|
7
|
+
|
|
8
|
+
set -e
|
|
9
|
+
|
|
10
|
+
# Colors for output
|
|
11
|
+
RED='\033[0;31m'
|
|
12
|
+
GREEN='\033[0;32m'
|
|
13
|
+
YELLOW='\033[1;33m'
|
|
14
|
+
BLUE='\033[0;34m'
|
|
15
|
+
NC='\033[0m'
|
|
16
|
+
|
|
17
|
+
# Logging functions
|
|
18
|
+
log_info() {
|
|
19
|
+
echo -e "${BLUE}[QUALITY]${NC} $1"
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
log_success() {
|
|
23
|
+
echo -e "${GREEN}[PASS]${NC} $1"
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
log_warn() {
|
|
27
|
+
echo -e "${YELLOW}[WARN]${NC} $1"
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
log_error() {
|
|
31
|
+
echo -e "${RED}[FAIL]${NC} $1"
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
# Timer function
|
|
35
|
+
start_timer() {
|
|
36
|
+
start_time=$(date +%s)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
end_timer() {
|
|
40
|
+
end_time=$(date +%s)
|
|
41
|
+
duration=$((end_time - start_time))
|
|
42
|
+
echo -e "${BLUE}[TIME]${NC} Completed in ${duration}s"
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
# Check if file exists and is executable
|
|
46
|
+
check_dependency() {
|
|
47
|
+
if ! command -v "$1" &> /dev/null; then
|
|
48
|
+
log_error "Required dependency '$1' not found"
|
|
49
|
+
return 1
|
|
50
|
+
fi
|
|
51
|
+
return 0
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
# Get staged files for analysis
|
|
55
|
+
get_staged_files() {
|
|
56
|
+
git diff --cached --name-only --diff-filter=ACM | grep -E '\.(js|ts|jsx|tsx|vue|svelte)$' || true
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
# Lint staged files
|
|
60
|
+
run_linter() {
|
|
61
|
+
local files=("$@")
|
|
62
|
+
if [ ${#files[@]} -eq 0 ]; then
|
|
63
|
+
log_info "No JavaScript/TypeScript files to lint"
|
|
64
|
+
return 0
|
|
65
|
+
fi
|
|
66
|
+
|
|
67
|
+
log_info "Running ESLint on ${#files[@]} files..."
|
|
68
|
+
start_timer
|
|
69
|
+
|
|
70
|
+
if npx eslint "${files[@]}" --quiet; then
|
|
71
|
+
log_success "ESLint checks passed"
|
|
72
|
+
end_timer
|
|
73
|
+
return 0
|
|
74
|
+
else
|
|
75
|
+
log_error "ESLint found issues. Please fix them before committing."
|
|
76
|
+
log_info "Tip: Run 'npx eslint --fix' to auto-fix some issues"
|
|
77
|
+
return 1
|
|
78
|
+
fi
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
# Format staged files
|
|
82
|
+
run_formatter() {
|
|
83
|
+
local files=("$@")
|
|
84
|
+
if [ ${#files[@]} -eq 0 ]; then
|
|
85
|
+
log_info "No files to format"
|
|
86
|
+
return 0
|
|
87
|
+
fi
|
|
88
|
+
|
|
89
|
+
log_info "Running Prettier on ${#files[@]} files..."
|
|
90
|
+
start_timer
|
|
91
|
+
|
|
92
|
+
if npx prettier --check "${files[@]}"; then
|
|
93
|
+
log_success "Code formatting is correct"
|
|
94
|
+
end_timer
|
|
95
|
+
return 0
|
|
96
|
+
else
|
|
97
|
+
log_error "Code formatting issues found."
|
|
98
|
+
log_info "Tip: Run 'npx prettier --write' to auto-format"
|
|
99
|
+
return 1
|
|
100
|
+
fi
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
# Type checking for TypeScript
|
|
104
|
+
run_type_check() {
|
|
105
|
+
if [ -f "tsconfig.json" ]; then
|
|
106
|
+
log_info "Running TypeScript type checking..."
|
|
107
|
+
start_timer
|
|
108
|
+
|
|
109
|
+
if npx tsc --noEmit; then
|
|
110
|
+
log_success "TypeScript compilation successful"
|
|
111
|
+
end_timer
|
|
112
|
+
return 0
|
|
113
|
+
else
|
|
114
|
+
log_error "TypeScript errors found. Please fix type issues."
|
|
115
|
+
return 1
|
|
116
|
+
fi
|
|
117
|
+
else
|
|
118
|
+
log_info "No tsconfig.json found, skipping TypeScript checks"
|
|
119
|
+
return 0
|
|
120
|
+
fi
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
# Security vulnerability check
|
|
124
|
+
run_security_check() {
|
|
125
|
+
log_info "Running security vulnerability check..."
|
|
126
|
+
start_timer
|
|
127
|
+
|
|
128
|
+
# Check for common security issues
|
|
129
|
+
local staged_files
|
|
130
|
+
mapfile -t staged_files < <(get_staged_files)
|
|
131
|
+
|
|
132
|
+
local has_security_issues=false
|
|
133
|
+
|
|
134
|
+
for file in "${staged_files[@]}"; do
|
|
135
|
+
# Check for console.log in production code
|
|
136
|
+
if grep -q "console\." "$file" && [[ "$file" != *".test."* ]] && [[ "$file" != *".spec."* ]]; then
|
|
137
|
+
log_warn "console statements found in $file (remove for production)"
|
|
138
|
+
has_security_issues=true
|
|
139
|
+
fi
|
|
140
|
+
|
|
141
|
+
# Check for debugger statements
|
|
142
|
+
if grep -q "debugger" "$file"; then
|
|
143
|
+
log_warn "debugger statement found in $file"
|
|
144
|
+
has_security_issues=true
|
|
145
|
+
fi
|
|
146
|
+
|
|
147
|
+
# Check for potential secrets
|
|
148
|
+
if grep -i -q "password\|secret\|token\|key" "$file" && grep -q "=" "$file"; then
|
|
149
|
+
log_warn "Potential secret exposure in $file - review carefully"
|
|
150
|
+
has_security_issues=true
|
|
151
|
+
fi
|
|
152
|
+
done
|
|
153
|
+
|
|
154
|
+
if [ "$has_security_issues" = false ]; then
|
|
155
|
+
log_success "Security check passed"
|
|
156
|
+
fi
|
|
157
|
+
|
|
158
|
+
end_timer
|
|
159
|
+
return 0 # Don't fail commit for warnings
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
# Performance check
|
|
163
|
+
run_performance_check() {
|
|
164
|
+
log_info "Running basic performance checks..."
|
|
165
|
+
start_timer
|
|
166
|
+
|
|
167
|
+
local staged_files
|
|
168
|
+
mapfile -t staged_files < <(get_staged_files)
|
|
169
|
+
|
|
170
|
+
local has_performance_issues=false
|
|
171
|
+
|
|
172
|
+
for file in "${staged_files[@]}"; do
|
|
173
|
+
# Check bundle size for large files
|
|
174
|
+
local file_size
|
|
175
|
+
file_size=$(stat -f%z "$file" 2>/dev/null || stat -c%s "$file" 2>/dev/null || echo "0")
|
|
176
|
+
|
|
177
|
+
if [ "$file_size" -gt 1000000 ]; then # 1MB
|
|
178
|
+
log_warn "Large file detected: $file (${file_size} bytes)"
|
|
179
|
+
has_performance_issues=true
|
|
180
|
+
fi
|
|
181
|
+
|
|
182
|
+
# Check for inefficient patterns
|
|
183
|
+
if grep -q "for.*in.*array\|for.*in.*object" "$file"; then
|
|
184
|
+
log_warn "Potential inefficient loop in $file - consider alternatives"
|
|
185
|
+
has_performance_issues=true
|
|
186
|
+
fi
|
|
187
|
+
done
|
|
188
|
+
|
|
189
|
+
if [ "$has_performance_issues" = false ]; then
|
|
190
|
+
log_success "Performance check passed"
|
|
191
|
+
fi
|
|
192
|
+
|
|
193
|
+
end_timer
|
|
194
|
+
return 0
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
# Main execution
|
|
198
|
+
main() {
|
|
199
|
+
log_info "🛡️ Claude Code Quality Guardian - Pre-commit Hook"
|
|
200
|
+
echo "=================================================="
|
|
201
|
+
|
|
202
|
+
# Check dependencies
|
|
203
|
+
local deps=("node" "npm" "npx")
|
|
204
|
+
for dep in "${deps[@]}"; do
|
|
205
|
+
if ! check_dependency "$dep"; then
|
|
206
|
+
log_error "Missing required dependency: $dep"
|
|
207
|
+
exit 1
|
|
208
|
+
fi
|
|
209
|
+
done
|
|
210
|
+
|
|
211
|
+
# Get staged files
|
|
212
|
+
local staged_files
|
|
213
|
+
mapfile -t staged_files < <(get_staged_files)
|
|
214
|
+
|
|
215
|
+
if [ ${#staged_files[@]} -eq 0 ]; then
|
|
216
|
+
log_info "No JavaScript/TypeScript files staged for commit"
|
|
217
|
+
exit 0
|
|
218
|
+
fi
|
|
219
|
+
|
|
220
|
+
log_info "Checking ${#staged_files[@]} files: ${staged_files[*]}"
|
|
221
|
+
echo
|
|
222
|
+
|
|
223
|
+
# Run all quality checks
|
|
224
|
+
local checks_passed=true
|
|
225
|
+
|
|
226
|
+
if ! run_linter "${staged_files[@]}"; then
|
|
227
|
+
checks_passed=false
|
|
228
|
+
fi
|
|
229
|
+
|
|
230
|
+
if ! run_formatter "${staged_files[@]}"; then
|
|
231
|
+
checks_passed=false
|
|
232
|
+
fi
|
|
233
|
+
|
|
234
|
+
if ! run_type_check; then
|
|
235
|
+
checks_passed=false
|
|
236
|
+
fi
|
|
237
|
+
|
|
238
|
+
run_security_check
|
|
239
|
+
run_performance_check
|
|
240
|
+
|
|
241
|
+
echo
|
|
242
|
+
if [ "$checks_passed" = true ]; then
|
|
243
|
+
log_success "🎉 All quality checks passed! Your code is ready for commit."
|
|
244
|
+
exit 0
|
|
245
|
+
else
|
|
246
|
+
log_error "❌ Quality checks failed. Please fix the issues and try again."
|
|
247
|
+
echo
|
|
248
|
+
log_info "Quick fixes:"
|
|
249
|
+
echo " • Run 'npx eslint --fix' to auto-fix linting issues"
|
|
250
|
+
echo " • Run 'npx prettier --write' to auto-format code"
|
|
251
|
+
echo " • Check TypeScript errors with 'npx tsc --noEmit'"
|
|
252
|
+
exit 1
|
|
253
|
+
fi
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
# Run main function
|
|
257
|
+
main "$@"
|