| #!/bin/bash |
|
|
| |
| |
|
|
| REPO_ROOT=$(git rev-parse --show-toplevel) |
| PRE_COMMIT_HOOK="$REPO_ROOT/.git/hooks/pre-commit" |
|
|
| echo "Installing pre-commit hook for webui..." |
|
|
| |
| cat > "$PRE_COMMIT_HOOK" << 'EOF' |
| |
|
|
| |
| if git diff --cached --name-only | grep -q "^tools/server/webui/"; then |
| REPO_ROOT=$(git rev-parse --show-toplevel) |
| cd "$REPO_ROOT/tools/server/webui" |
|
|
| |
| if [ ! -f "package.json" ]; then |
| echo "Error: package.json not found in tools/server/webui" |
| exit 1 |
| fi |
|
|
| echo "Formatting and checking webui code..." |
|
|
| |
| npm run format |
| if [ $? -ne 0 ]; then |
| echo "Error: npm run format failed" |
| exit 1 |
| fi |
|
|
| |
| npm run lint |
| if [ $? -ne 0 ]; then |
| echo "Error: npm run lint failed" |
| exit 1 |
| fi |
|
|
| |
| npm run check |
| if [ $? -ne 0 ]; then |
| echo "Error: npm run check failed" |
| exit 1 |
| fi |
|
|
| echo "β
Webui code formatted and checked successfully" |
|
|
| |
| echo "Building webui..." |
| npm run build |
| if [ $? -ne 0 ]; then |
| echo "β npm run build failed" |
| exit 1 |
| fi |
|
|
| |
| cd "$REPO_ROOT" |
| git add tools/server/public/ |
|
|
| echo "β
Webui built and build output staged" |
| fi |
|
|
| exit 0 |
| EOF |
|
|
| |
| chmod +x "$PRE_COMMIT_HOOK" |
|
|
| if [ $? -eq 0 ]; then |
| echo "β
Git hook installed successfully!" |
| echo " Pre-commit: $PRE_COMMIT_HOOK" |
| echo "" |
| echo "The hook will automatically:" |
| echo " β’ Format, lint and check webui code before commits" |
| echo " β’ Build webui and stage tools/server/public/ into the same commit" |
| else |
| echo "β Failed to make hook executable" |
| exit 1 |
| fi |
|
|