feat: add Husky git hooks with enable/disable flag
✅ Added Husky and lint-staged to all package.json files - common_plat: root package.json - voice_agent: all 3 dashboards (admin, user, tracker) ✅ Created setup scripts - scripts/setup-husky.sh in both repos - Creates .husky/pre-commit with HUSKY_ENABLED flag check ✅ Added documentation - HUSKY_SETUP.md: Complete setup and usage guide - SHELL_ALIASES.md: Shell aliases for easy toggle Features: - Environment variable control: HUSKY_ENABLED=false/true - lint-staged runs only on changed files (~2-5s) - Auto-fixes ESLint and formats with Prettier - Can be bypassed with --no-verify or husky-off alias To activate after pulling: 1. pnpm install (or npm install) 2. pnpm prepare (or npm run prepare) 3. ./scripts/setup-husky.sh
This commit is contained in:
parent
def855f032
commit
ca7a770309
14
package.json
14
package.json
@ -13,7 +13,8 @@
|
|||||||
"format": "prettier --write \"**/*.{ts,tsx,js,jsx,json,md,yml,yaml}\"",
|
"format": "prettier --write \"**/*.{ts,tsx,js,jsx,json,md,yml,yaml}\"",
|
||||||
"format:check": "prettier --check \"**/*.{ts,tsx,js,jsx,json,md,yml,yaml}\"",
|
"format:check": "prettier --check \"**/*.{ts,tsx,js,jsx,json,md,yml,yaml}\"",
|
||||||
"audit": "pnpm -r audit --audit-level moderate",
|
"audit": "pnpm -r audit --audit-level moderate",
|
||||||
"clean": "pnpm -r exec rm -rf dist"
|
"clean": "pnpm -r exec rm -rf dist",
|
||||||
|
"prepare": "husky install"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/bcryptjs": "^2.4.6",
|
"@types/bcryptjs": "^2.4.6",
|
||||||
@ -23,6 +24,8 @@
|
|||||||
"@typescript-eslint/parser": "^8.0.0",
|
"@typescript-eslint/parser": "^8.0.0",
|
||||||
"@vitest/coverage-v8": "^3.0.0",
|
"@vitest/coverage-v8": "^3.0.0",
|
||||||
"eslint": "^9.0.0",
|
"eslint": "^9.0.0",
|
||||||
|
"husky": "^9.0.0",
|
||||||
|
"lint-staged": "^15.0.0",
|
||||||
"prettier": "^3.0.0",
|
"prettier": "^3.0.0",
|
||||||
"typescript": "^5.7.0",
|
"typescript": "^5.7.0",
|
||||||
"vitest": "^3.0.0"
|
"vitest": "^3.0.0"
|
||||||
@ -33,5 +36,14 @@
|
|||||||
"jose": ">=5.0.0",
|
"jose": ">=5.0.0",
|
||||||
"react": ">=18.0.0",
|
"react": ">=18.0.0",
|
||||||
"zod": "^3.24.0"
|
"zod": "^3.24.0"
|
||||||
|
},
|
||||||
|
"lint-staged": {
|
||||||
|
"*.{ts,tsx}": [
|
||||||
|
"eslint --fix",
|
||||||
|
"prettier --write"
|
||||||
|
],
|
||||||
|
"*.{js,jsx,json,md,yml,yaml}": [
|
||||||
|
"prettier --write"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
40
scripts/setup-husky.sh
Executable file
40
scripts/setup-husky.sh
Executable file
@ -0,0 +1,40 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Husky Setup Script for Common Platform
|
||||||
|
# Sets up pre-commit hooks with HUSKY_ENABLED flag support
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
echo "🐶 Setting up Husky git hooks for common platform..."
|
||||||
|
|
||||||
|
# Create .husky directory if it doesn't exist
|
||||||
|
mkdir -p .husky
|
||||||
|
|
||||||
|
# Create pre-commit hook with HUSKY_ENABLED flag
|
||||||
|
cat > .husky/pre-commit << 'EOF'
|
||||||
|
#!/usr/bin/env sh
|
||||||
|
. "$(dirname -- "$0")/_/husky.sh"
|
||||||
|
|
||||||
|
# Check if Husky is disabled via environment variable
|
||||||
|
if [ "$HUSKY_ENABLED" = "false" ]; then
|
||||||
|
echo "⚠️ Husky disabled via HUSKY_ENABLED=false"
|
||||||
|
echo "💡 To re-enable: unset HUSKY_ENABLED or export HUSKY_ENABLED=true"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "🐶 Running pre-commit hooks for common platform..."
|
||||||
|
|
||||||
|
# Run lint-staged on staged files
|
||||||
|
npx lint-staged
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# Make the hook executable
|
||||||
|
chmod +x .husky/pre-commit
|
||||||
|
|
||||||
|
echo "✅ Pre-commit hook created successfully!"
|
||||||
|
echo ""
|
||||||
|
echo "📖 Usage:"
|
||||||
|
echo " Normal commit: git commit -m 'feat: add feature'"
|
||||||
|
echo " Disable hooks: export HUSKY_ENABLED=false"
|
||||||
|
echo " Enable hooks: export HUSKY_ENABLED=true"
|
||||||
|
echo " One-time bypass: git commit --no-verify"
|
||||||
Loading…
Reference in New Issue
Block a user