Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/sh
# Format and lint staged files only. Skip in an emergency: git commit --no-verify
root=$(git rev-parse --show-toplevel) || exit 1
cd "$root" || exit 1

staged=$(mktemp) || exit 1
trap 'rm -f "$staged" "$staged.lint"' EXIT

git diff --cached --name-only --diff-filter=ACMR -z -- \
'*.ts' '*.tsx' '*.js' '*.json' '*.scss' '*.css' '*.md' >"$staged" || exit 1
[ -s "$staged" ] || exit 0

# Re-staging a partially staged file would commit its unstaged changes too.
partial=0
while IFS= read -r file; do
if ! git diff --quiet -- "$file"; then
echo "pre-commit: $file has unstaged changes; stage or stash them first." >&2
partial=1
fi
done <<EOF
$(tr '\0' '\n' <"$staged")
EOF
[ "$partial" -eq 0 ] || exit 1

xargs -0 pnpm exec prettier --write --ignore-unknown --no-error-on-unmatched-pattern <"$staged" || exit 1

tr '\0' '\n' <"$staged" | grep -E '\.(ts|tsx|js)$' | tr '\n' '\0' >"$staged.lint"
if [ -s "$staged.lint" ]; then
xargs -0 pnpm exec eslint --fix --no-warn-ignored <"$staged.lint" || exit 1
fi

xargs -0 git add -- <"$staged"
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ store's settings don't pin a release (`theme.twilight.version`).
| `pnpm test` | Run the test suite (Vitest) |
| `pnpm check:manifest` | Validate `twilight.json` |

## Git hook

`pnpm install` sets `core.hooksPath` to `.githooks`; the pre-commit hook runs Prettier and ESLint (`--fix`) on staged files only, re-stages them, and refuses the commit on remaining lint errors.
In an emergency, skip it with `git commit --no-verify`.

## Deployment

Salla builds and publishes your theme on its own infrastructure — push to your
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"test:coverage": "vitest run --coverage",
"lint": "eslint .",
"format:check": "prettier --check .",
"knip": "knip"
"knip": "knip",
"prepare": "node scripts/install-hooks.mjs"
},
"dependencies": {
"@salla.sa/twilight-components-react": "^3.0.2",
Expand Down
7 changes: 7 additions & 0 deletions scripts/install-hooks.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { existsSync } from 'node:fs';
import { spawnSync } from 'node:child_process';

// Skip quietly outside a git checkout (CI tarballs, published packages).
if (existsSync('.git')) {
spawnSync('git', ['config', 'core.hooksPath', '.githooks'], { stdio: 'ignore' });
}
Loading