Skip to content

Commit

Permalink
lefthookへ乗り換え
Browse files Browse the repository at this point in the history
  • Loading branch information
huuyafwww committed Feb 10, 2025
1 parent 63d711e commit e60032e
Show file tree
Hide file tree
Showing 7 changed files with 233 additions and 310 deletions.
61 changes: 61 additions & 0 deletions .husky/_/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/sh

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"
echo "ERROR: Operation is aborted due to lefthook settings."
echo "Make sure lefthook is available in your environment and re-try."
echo "To skip these checks use --no-verify git argument or set LEFTHOOK=0 env variable."
exit 1
fi
fi
}

call_lefthook run "pre-commit" "$@"
61 changes: 61 additions & 0 deletions .husky/_/prepare-commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/sh

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"
echo "ERROR: Operation is aborted due to lefthook settings."
echo "Make sure lefthook is available in your environment and re-try."
echo "To skip these checks use --no-verify git argument or set LEFTHOOK=0 env variable."
exit 1
fi
fi
}

call_lefthook run "prepare-commit-msg" "$@"
1 change: 0 additions & 1 deletion .husky/pre-commit

This file was deleted.

1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
strict-peer-dependencies=false
provenance=true
side-effects-cache=false
9 changes: 9 additions & 0 deletions lefthook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
assert_lefthook_installed: true

pre-commit:
parallel: true
jobs:
- name: Sort package.json
run: pnpm run sort:package
glob: '{package.json,**/package.json}'
stage_fixed: true
11 changes: 2 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,21 @@
},
"license": "MIT",
"scripts": {
"build": "turbo run build",
"build": "turbo run build --parallel",
"build:watch": "turbo run build:watch",
"clean": "turbo run clean",
"lint:code": "turbo lint:code --parallel",
"lint:type": "turbo lint:type --parallel",
"prepare": "husky",
"sort:package": "sort-package-json 'package.json' 'packages/*/package.json'",
"version": "changeset",
"version:apply": "changeset version",
"version:publish": "changeset publish"
},
"lint-staged": {
"{package.json,**/package.json}": [
"bash -c 'pnpm run sort:package'"
]
},
"devDependencies": {
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "^2.27.11",
"@huuyafwww/tsconfig-common": "^1.1.1",
"husky": "^9.1.7",
"lint-staged": "^15.4.1",
"lefthook": "^1.10.10",
"sort-package-json": "^2.14.0",
"turbo": "^2.3.3",
"typescript": "^5.7.3"
Expand Down
Loading

0 comments on commit e60032e

Please sign in to comment.