diff --git a/Docs/Web-Development.md b/Docs/Web-Development.md index 0aff173..7cd32f2 100644 --- a/Docs/Web-Development.md +++ b/Docs/Web-Development.md @@ -111,6 +111,34 @@ The script returns: - **Exit 2:** Backend is not accessible (set `BANGUI_BACKEND_URL` if needed) - **Exit 3:** Type generation failed +### Pre-Commit Hook Setup (Local Development) + +To catch type drift locally before committing, set up a Git pre-commit hook: + +1. **Create `.git/hooks/pre-commit`:** + ```bash + #!/bin/bash + # Validate types before commit + cd frontend + npm run validate:types + if [ $? -ne 0 ] && [ $? -ne 2 ]; then # Allow hook to skip if backend unavailable + echo "❌ Types out of sync. Run 'npm run generate:types' and commit the changes." + exit 1 + fi + ``` + +2. **Make it executable:** + ```bash + chmod +x .git/hooks/pre-commit + ``` + +3. **Alternative: Use Husky** (if your project has Husky configured) + ```bash + npx husky add .husky/pre-commit "cd frontend && npm run validate:types" + ``` + +**Note:** The pre-commit hook is optional and local only. The CI/CD pipeline will always validate types, so types cannot drift even without a local hook. + --- ## 3. Type Safety in API Calls