ソースを参照

Setup git hooks by Claude Code

jerryliao 2 日 前
コミット
9be6a112cf
3 ファイル変更55 行追加4 行削除
  1. 29 0
      .githooks/pre-commit
  2. 24 3
      README.md
  3. 2 1
      deno.json

+ 29 - 0
.githooks/pre-commit

@@ -0,0 +1,29 @@
+#!/bin/sh
+
+# Pre-commit hook: ensures formatting and tests pass before committing
+
+echo "Running pre-commit checks..."
+
+# 1. Check formatting on staged files
+STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.(ts|tsx|js|jsx|json|md)$')
+
+if [ -n "$STAGED_FILES" ]; then
+  echo "Checking format..."
+  echo "$STAGED_FILES" | xargs deno fmt --check
+  if [ $? -ne 0 ]; then
+    echo ""
+    echo "Format check failed. Run 'deno fmt' to fix, then stage the changes."
+    exit 1
+  fi
+fi
+
+# 2. Run all tests
+echo "Running tests..."
+deno task test
+if [ $? -ne 0 ]; then
+  echo ""
+  echo "Tests failed. Fix the failing tests before committing."
+  exit 1
+fi
+
+echo "All checks passed."

+ 24 - 3
README.md

@@ -19,6 +19,27 @@ build a docker image or use `Deno Deploy` officially recommended in
 ## Development
 
 Install `deno` runtime according to [this doc](https://docs.deno.com/runtime/),
-then execute `deno task dev` in the project root, all the dependencies should be
-automatically installed. Then check `localhost:8000` in your browser for the
-website
+then run the setup task to install dependencies and enable git hooks:
+
+```bash
+deno task setup
+```
+
+Start the dev server and visit `localhost:8000`:
+
+```bash
+deno task dev
+```
+
+### Available tasks
+
+- `deno task dev` - Start the development server
+- `deno task test` - Run all tests (backend + UI)
+- `deno task check` - Check formatting, linting, and types
+- `deno task setup` - Install dependencies and configure git hooks
+
+### Git hooks
+
+A pre-commit hook is configured via `.githooks/` to automatically check
+formatting and run tests before each commit. The `deno task setup` command
+enables this by setting `core.hooksPath` to `.githooks/`.

+ 2 - 1
deno.json

@@ -6,7 +6,8 @@
     "build": "vite build",
     "start": "deno serve -A _fresh/server.js",
     "update": "deno run -A -r jsr:@fresh/update .",
-    "test": "deno test -A --ignore=tests/ui && deno test -A --no-check --config tests/ui/deno.json tests/ui/"
+    "test": "deno test -A --ignore=tests/ui && deno test -A --no-check --config tests/ui/deno.json tests/ui/",
+    "setup": "git config core.hooksPath .githooks && deno install"
   },
   "lint": {
     "rules": {