From ce5ca30a03b6e59ecadc02153af57fd4db8995a7 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 22 Jan 2026 22:38:46 +0000 Subject: [PATCH] feat: add pre-commit hook setup script - Add `scripts/setup-pre-commit.sh` to install a git pre-commit hook. - The hook runs `npm run lint` and `npm run build:css` to enforce quality and build consistency. - Update `CONTRIBUTING.md` to document the new hook setup under Development Setup. --- CONTRIBUTING.md | 6 ++++++ scripts/setup-pre-commit.sh | 38 +++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100755 scripts/setup-pre-commit.sh diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a233dbc2..d2351564 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -74,6 +74,12 @@ To set up the project locally: npm run lint ``` +5. **Git Hooks (Optional)**: + We provide a script to set up a git pre-commit hook that runs linting and CSS builds automatically before you commit. + ```bash + ./scripts/setup-pre-commit.sh + ``` + For a full guide, see the [Local Setup section in README.md](./README.md#local-setup). ## Dev Container diff --git a/scripts/setup-pre-commit.sh b/scripts/setup-pre-commit.sh new file mode 100755 index 00000000..93ee06c6 --- /dev/null +++ b/scripts/setup-pre-commit.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +HOOK_FILE=".git/hooks/pre-commit" + +if [ ! -d ".git" ]; then + echo "Error: .git directory not found. This script must be run from the repository root." + exit 1 +fi + +echo "Setting up pre-commit hook at $HOOK_FILE..." + +cat > "$HOOK_FILE" << 'EOF' +#!/bin/sh +# pre-commit hook to run lint and build checks + +echo "Running pre-commit checks..." + +# Run lint +echo "Running lint..." +npm run lint +if [ $? -ne 0 ]; then + echo "Lint failed. Please fix errors before committing." + exit 1 +fi + +# Run CSS build to ensure consistency +echo "Running CSS build..." +npm run build:css +if [ $? -ne 0 ]; then + echo "CSS build failed. Please fix errors before committing." + exit 1 +fi + +echo "Pre-commit checks passed." +EOF + +chmod +x "$HOOK_FILE" +echo "Pre-commit hook installed successfully."