Skip to content

Commit

Permalink
chore(deps): use lefthook instead of lint-staged
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroppy committed Jan 5, 2025
1 parent 340c29e commit cf2c146
Show file tree
Hide file tree
Showing 14 changed files with 197 additions and 350 deletions.
57 changes: 56 additions & 1 deletion .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -1,2 +1,57 @@
#!/bin/sh
npx lint-staged

if [ "$LEFTHOOK_VERBOSE" = "1" -o "$LEFTHOOK_VERBOSE" = "true" ]; then
set -x
fi

if [ "$LEFTHOOK" = "0" ]; then
exit 0
fi

call_lefthook()
{
if test -n "$LEFTHOOK_BIN"
then
"$LEFTHOOK_BIN" "$@"
elif lefthook -h >/dev/null 2>&1
then
lefthook "$@"
else
dir="$(git rev-parse --show-toplevel)"
osArch=$(uname | tr '[:upper:]' '[:lower:]')
cpuArch=$(uname -m | sed 's/aarch64/arm64/;s/x86_64/x64/')
if test -f "$dir/node_modules/lefthook-${osArch}-${cpuArch}/bin/lefthook"
then
"$dir/node_modules/lefthook-${osArch}-${cpuArch}/bin/lefthook" "$@"
elif test -f "$dir/node_modules/@evilmartians/lefthook/bin/lefthook-${osArch}-${cpuArch}/lefthook"
then
"$dir/node_modules/@evilmartians/lefthook/bin/lefthook-${osArch}-${cpuArch}/lefthook" "$@"
elif test -f "$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook"
then
"$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook" "$@"
elif test -f "$dir/node_modules/lefthook/bin/index.js"
then
"$dir/node_modules/lefthook/bin/index.js" "$@"

elif bundle exec lefthook -h >/dev/null 2>&1
then
bundle exec lefthook "$@"
elif yarn lefthook -h >/dev/null 2>&1
then
yarn lefthook "$@"
elif pnpm lefthook -h >/dev/null 2>&1
then
pnpm lefthook "$@"
elif swift package plugin lefthook >/dev/null 2>&1
then
swift package --disable-sandbox plugin lefthook "$@"
elif command -v mint >/dev/null 2>&1
then
mint run csjones/lefthook-plugin "$@"
else
echo "Can't find lefthook in PATH"
fi
fi
}

call_lefthook run "pre-commit" "$@"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.githooks

node_modules
coverage

Expand Down
4 changes: 2 additions & 2 deletions .internal/site/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ export default defineConfig({
{ icon: "twitter", link: "https://x.com/about_hiroppy" },
],
editLink: {
// TODO
pattern: "https://github.com/vuejs/vitepress/edit/main/docs/:path",
pattern:
"https://github.com/hiroppy/web-app-template/tree/main/.internal/site/src/:path",
text: "Edit this page on GitHub",
},
lastUpdated: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ These are the main libraries that are installed. However, Playwright and OpenTel
| | <div align="center"><img src="/images/libs/zod.svg" alt="zod" width="42"><br>Zod </div> | <div align="center"><img src="/images/libs/otel.png" alt="otel" width="42"><br>OpenTelemetry </div> | <div align="center"><img src="/images/libs/prisma.png" alt="prisma" width="42"><br>Prisma </div> | <div align="center"><img src="/images/libs/postgresql.png" alt="prisma" width="42"><br>PostgreSQL</div> |
| | | | |
| **Tools** | <div align="center"><img src="/images/libs/typescript.png" alt="typescirpt" width="42"><br>TypeScript</div> | <div align="center"><img src="/images/libs/pnpm.svg" alt="pnpm" width="42"><br>pnpm</div> | <div align="center"><img src="/images/libs/biome.png" alt="biome" width="42"><br>Biome </div> | <div align="center"><img src="/images/libs/prettier.png" alt="prettier" width="42"><br> Prettier</div> |
| | <div align="center"><img src="/images/libs/editorconfig.png" alt="editorconfig" width="42"><br> EditorConfig </div> | <div align="center"><img src="/images/libs/lint-staged.png" alt="lint-staged" width="42"><br> lint-staged</div> | <div align="center"><img src="/images/libs/docker.png" alt="docker" width="42"><br> Docker </div> | |
| | <div align="center"><img src="/images/libs/editorconfig.png" alt="editorconfig" width="42"><br> EditorConfig </div> | <div align="center"><img src="/images/libs/lefthook.png" alt="lefthook" width="42"><br> lefthook</div> | <div align="center"><img src="/images/libs/docker.png" alt="docker" width="42"><br> Docker </div> | |
| | | | |
| **Testing** | <div align="center"><img src="/images/libs/vitest.png" alt="vitest" width="42"><br> Vitest</div> | <div align="center"><img src="/images/libs/testing-library.png" alt="testing-library" width="42"><br> Testing Library</div> | <div align="center"><img src="/images/libs/playwright.png" alt="playwright" width="42"><br> Playwright</div> | <div align="center"><img src="/images/libs/testcontainers.png" alt="testcontainers" width="42"><br> Testcontainers</div> |
| | | |
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 5 additions & 2 deletions .internal/tests/common.test.mjs.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ exports[`common > should put files 1`] = `
"internal-tests-output-common/.env.sample",
"internal-tests-output-common/.env.test",
"internal-tests-output-common/.githooks/pre-commit",
"internal-tests-output-common/.githooks/prepare-commit-msg",
"internal-tests-output-common/.github/actions/setup-db/action.yml",
"internal-tests-output-common/.github/actions/setup-node/action.yml",
"internal-tests-output-common/.github/actions/setup-prisma/action.yml",
Expand All @@ -19,7 +20,7 @@ exports[`common > should put files 1`] = `
"internal-tests-output-common/README.md",
"internal-tests-output-common/biome.json",
"internal-tests-output-common/compose.yml",
"internal-tests-output-common/lint-staged.config.mjs",
"internal-tests-output-common/lefthook.yml",
"internal-tests-output-common/next.config.ts",
"internal-tests-output-common/otel-collector-config.yml",
"internal-tests-output-common/package.json",
Expand Down Expand Up @@ -128,6 +129,8 @@ exports[`common > should update .github/workflows/ci.yml 1`] = `

exports[`common > should update .gitignore 1`] = `
[
".githooks",
"",
"node_modules",
"coverage",
"",
Expand Down Expand Up @@ -307,7 +310,7 @@ exports[`common > should update dependencies 1`] = `
"dotenv",
"dotenv-cli",
"jsdom",
"lint-staged",
"lefthook",
"postcss",
"prettier",
"prisma",
Expand Down
3 changes: 2 additions & 1 deletion .internal/tests/no-docker.test.mjs.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ exports[`no-docker > should put files 1`] = `
"internal-tests-output-no-docker/.env.sample",
"internal-tests-output-no-docker/.env.test",
"internal-tests-output-no-docker/.githooks/pre-commit",
"internal-tests-output-no-docker/.githooks/prepare-commit-msg",
"internal-tests-output-no-docker/.github/actions/setup-db/action.yml",
"internal-tests-output-no-docker/.github/actions/setup-node/action.yml",
"internal-tests-output-no-docker/.github/actions/setup-prisma/action.yml",
Expand All @@ -18,7 +19,7 @@ exports[`no-docker > should put files 1`] = `
"internal-tests-output-no-docker/README.md",
"internal-tests-output-no-docker/biome.json",
"internal-tests-output-no-docker/compose.yml",
"internal-tests-output-no-docker/lint-staged.config.mjs",
"internal-tests-output-no-docker/lefthook.yml",
"internal-tests-output-no-docker/next.config.ts",
"internal-tests-output-no-docker/otel-collector-config.yml",
"internal-tests-output-no-docker/package.json",
Expand Down
7 changes: 5 additions & 2 deletions .internal/tests/no-e2e.test.mjs.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ exports[`no-e2e > should put files 1`] = `
"internal-tests-output-no-e2e/.env.sample",
"internal-tests-output-no-e2e/.env.test",
"internal-tests-output-no-e2e/.githooks/pre-commit",
"internal-tests-output-no-e2e/.githooks/prepare-commit-msg",
"internal-tests-output-no-e2e/.github/actions/setup-db/action.yml",
"internal-tests-output-no-e2e/.github/actions/setup-node/action.yml",
"internal-tests-output-no-e2e/.github/actions/setup-prisma/action.yml",
Expand All @@ -19,7 +20,7 @@ exports[`no-e2e > should put files 1`] = `
"internal-tests-output-no-e2e/README.md",
"internal-tests-output-no-e2e/biome.json",
"internal-tests-output-no-e2e/compose.yml",
"internal-tests-output-no-e2e/lint-staged.config.mjs",
"internal-tests-output-no-e2e/lefthook.yml",
"internal-tests-output-no-e2e/next.config.ts",
"internal-tests-output-no-e2e/otel-collector-config.yml",
"internal-tests-output-no-e2e/package.json",
Expand Down Expand Up @@ -116,6 +117,8 @@ exports[`no-e2e > should update .github/workflows/ci.yml 1`] = `

exports[`no-e2e > should update .gitignore 1`] = `
[
".githooks",
"",
"node_modules",
"coverage",
"",
Expand Down Expand Up @@ -234,7 +237,7 @@ exports[`no-e2e > should update dependencies 1`] = `
"dotenv",
"dotenv-cli",
"jsdom",
"lint-staged",
"lefthook",
"postcss",
"prettier",
"prisma",
Expand Down
5 changes: 3 additions & 2 deletions .internal/tests/no-otel.test.mjs.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ exports[`no-otel > should put files 1`] = `
"internal-tests-output-no-otel/.env.sample",
"internal-tests-output-no-otel/.env.test",
"internal-tests-output-no-otel/.githooks/pre-commit",
"internal-tests-output-no-otel/.githooks/prepare-commit-msg",
"internal-tests-output-no-otel/.github/actions/setup-db/action.yml",
"internal-tests-output-no-otel/.github/actions/setup-node/action.yml",
"internal-tests-output-no-otel/.github/actions/setup-prisma/action.yml",
Expand All @@ -19,7 +20,7 @@ exports[`no-otel > should put files 1`] = `
"internal-tests-output-no-otel/README.md",
"internal-tests-output-no-otel/biome.json",
"internal-tests-output-no-otel/compose.yml",
"internal-tests-output-no-otel/lint-staged.config.mjs",
"internal-tests-output-no-otel/lefthook.yml",
"internal-tests-output-no-otel/next.config.ts",
"internal-tests-output-no-otel/package.json",
"internal-tests-output-no-otel/playwright.config.ts",
Expand Down Expand Up @@ -151,7 +152,7 @@ exports[`no-otel > should update dependencies 1`] = `
"dotenv",
"dotenv-cli",
"jsdom",
"lint-staged",
"lefthook",
"postcss",
"prettier",
"prisma",
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
| | <div align="center"><img src=".internal/site/src/public/images/libs/zod.svg" alt="zod" width="42"><br>Zod </div> | <div align="center"><img src=".internal/site/src/public/images/libs/otel.png" alt="otel" width="42"><br>OpenTelemetry </div> | <div align="center"><img src=".internal/site/src/public/images/libs/prisma.png" alt="prisma" width="42"><br>Prisma </div> | <div align="center"><img src=".internal/site/src/public/images/libs/postgresql.png" alt="prisma" width="42"><br>PostgreSQL</div> |
| | | | |
| **Tools** | <div align="center"><img src=".internal/site/src/public/images/libs/typescript.png" alt="typescirpt" width="42"><br>TypeScript</div> | <div align="center"><img src=".internal/site/src/public/images/libs/pnpm.svg" alt="pnpm" width="42"><br>pnpm</div> | <div align="center"><img src=".internal/site/src/public/images/libs/biome.png" alt="biome" width="42"><br>Biome </div> | <div align="center"><img src=".internal/site/src/public/images/libs/prettier.png" alt="prettier" width="42"><br> Prettier</div> |
| | <div align="center"><img src=".internal/site/src/public/images/libs/editorconfig.png" alt="editorconfig" width="42"><br> EditorConfig </div> | <div align="center"><img src=".internal/site/src/public/images/libs/lint-staged.png" alt="lint-staged" width="42"><br> lint-staged</div> | <div align="center"><img src=".internal/site/src/public/images/libs/docker.png" alt="docker" width="42"><br> Docker </div> | |
| | <div align="center"><img src=".internal/site/src/public/images/libs/editorconfig.png" alt="editorconfig" width="42"><br> EditorConfig </div> | <div align="center"><img src=".internal/site/src/public/images/libs/lefthook.png" alt="lefthook" width="42"><br> lefthook</div> | <div align="center"><img src=".internal/site/src/public/images/libs/docker.png" alt="docker" width="42"><br> Docker </div> | |
| | | | |
| **Testing** | <div align="center"><img src=".internal/site/src/public/images/libs/vitest.png" alt="vitest" width="42"><br> Vitest</div> | <div align="center"><img src=".internal/site/src/public/images/libs/testing-library.png" alt="testing-library" width="42"><br> Testing Library</div> | <div align="center"><img src=".internal/site/src/public/images/libs/playwright.png" alt="playwright" width="42"><br> Playwright</div> | <div align="center"><img src=".internal/site/src/public/images/libs/testcontainers.png" alt="testcontainers" width="42"><br> Testcontainers</div> |
| | | |
Expand Down
18 changes: 18 additions & 0 deletions lefthook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
pre-commit:
parallel: true
commands:
biome:
glob: "*.{js,ts,cjs,mjs,d.cts,d.mts,jsx,tsx,json,jsonc}"
run: |
npx biome check --write --no-errors-on-unmatched {staged_files}
stage_fixed: true
prettier:
glob: "*.{md,yml}"
run: |
npx prettier --write {staged_files}
stage_fixed: true
prisma:
glob: "*.prisma"
run: |
npx prisma format {staged_files}
stage_fixed: true
7 changes: 0 additions & 7 deletions lint-staged.config.mjs

This file was deleted.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "",
"packageManager": "pnpm@9.15.2",
"scripts": {
"setup": "git config --local core.hooksPath .githooks && corepack enable pnpm",
"setup": "lefthook install && corepack enable pnpm",
"dev": "pnpm db:up && pnpm db:migrate && pnpm generate:client && next dev",
"start": "next start",
"build": "pnpm generate:client && next build",
Expand Down Expand Up @@ -56,7 +56,7 @@
"dotenv": "16.4.7",
"dotenv-cli": "8.0.0",
"jsdom": "25.0.1",
"lint-staged": "15.3.0",
"lefthook": "1.10.1",
"postcss": "8.4.49",
"prettier": "3.4.2",
"prisma": "6.1.0",
Expand Down
Loading

0 comments on commit cf2c146

Please sign in to comment.