Skip to content

Commit 324b72b

Browse files
committed
Add setup scripts for Git hooks in package.json and update README with development instructions
- Added "prepare" and "setup:hooks" scripts to package.json for configuring Git hooks. - Updated README to include instructions on running `pnpm install` for hook setup and details about the pre-commit hook functionality.
1 parent 1e4ef93 commit 324b72b

4 files changed

Lines changed: 55 additions & 0 deletions

File tree

.githooks/pre-commit

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
repo_root="$(git rev-parse --show-toplevel)"
6+
cd "$repo_root"
7+
8+
staged_files=()
9+
while IFS= read -r -d '' file; do
10+
case "$file" in
11+
*.cjs|*.css|*.cts|*.html|*.js|*.json|*.jsonc|*.jsx|*.md|*.mdx|*.mjs|*.mts|*.scss|*.ts|*.tsx|*.yaml|*.yml)
12+
if [[ -f "$file" ]]; then
13+
staged_files+=("$file")
14+
fi
15+
;;
16+
esac
17+
done < <(git diff --cached --name-only --diff-filter=ACMR -z)
18+
19+
if (( ${#staged_files[@]} == 0 )); then
20+
exit 0
21+
fi
22+
23+
echo "Formatting staged files with oxfmt"
24+
pnpm exec oxfmt --write -- "${staged_files[@]}"
25+
git add -- "${staged_files[@]}"

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ A fully typed, in-memory graph database. Vertices and edges are strongly typed a
3838
pnpm add @codemix/graph
3939
```
4040

41+
### Development
42+
43+
Running `pnpm install` in the monorepo configures Git to use the tracked hooks in `.githooks`.
44+
45+
The pre-commit hook formats staged supported source files with `oxfmt` and restages them automatically. You can re-run the hook setup at any time with `pnpm run setup:hooks`.
46+
4147
### Quick Start
4248

4349
```typescript

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
"scripts": {
1212
"build": "pnpm run -r build",
1313
"changeset": "changeset",
14+
"prepare": "sh ./scripts/setup-git-hooks.sh",
1415
"version-packages": "changeset version",
1516
"release": "pnpm build && changeset publish",
17+
"setup:hooks": "sh ./scripts/setup-git-hooks.sh",
1618
"typecheck": "pnpm run -r typecheck",
1719
"test": "vitest",
1820
"test:coverage": "vitest run --coverage",

scripts/setup-git-hooks.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env sh
2+
3+
set -eu
4+
5+
if ! command -v git >/dev/null 2>&1; then
6+
exit 0
7+
fi
8+
9+
if ! git rev-parse --show-toplevel >/dev/null 2>&1; then
10+
exit 0
11+
fi
12+
13+
repo_root="$(git rev-parse --show-toplevel)"
14+
cd "$repo_root"
15+
16+
current_hooks_path="$(git config --get core.hooksPath || true)"
17+
if [ "$current_hooks_path" = ".githooks" ]; then
18+
exit 0
19+
fi
20+
21+
git config core.hooksPath .githooks
22+
echo "Configured Git hooks to use .githooks"

0 commit comments

Comments
 (0)