Skip to content

Commit 6a06462

Browse files
committed
chore: install lefthook
1 parent 41fb1bd commit 6a06462

File tree

5 files changed

+238
-4
lines changed

5 files changed

+238
-4
lines changed

.husky/pre-commit

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,53 @@
11
#!/bin/sh
2-
. "$(dirname "$0")/_/husky.sh"
32

4-
yarn prettier
3+
if [ "$LEFTHOOK_VERBOSE" = "1" -o "$LEFTHOOK_VERBOSE" = "true" ]; then
4+
set -x
5+
fi
6+
7+
if [ "$LEFTHOOK" = "0" ]; then
8+
exit 0
9+
fi
10+
11+
call_lefthook()
12+
{
13+
dir="$(git rev-parse --show-toplevel)"
14+
osArch=$(uname | tr '[:upper:]' '[:lower:]')
15+
cpuArch=$(uname -m | sed 's/aarch64/arm64/')
16+
17+
if test -n "$LEFTHOOK_BIN"
18+
then
19+
"$LEFTHOOK_BIN" "$@"
20+
elif lefthook -h >/dev/null 2>&1
21+
then
22+
lefthook "$@"
23+
elif test -f "$dir/node_modules/lefthook/bin/index.js"
24+
then
25+
"$dir/node_modules/lefthook/bin/index.js" "$@"
26+
elif test -f "$dir/node_modules/@evilmartians/lefthook/bin/lefthook_${osArch}_${cpuArch}/lefthook"
27+
then
28+
"$dir/node_modules/@evilmartians/lefthook/bin/lefthook_${osArch}_${cpuArch}/lefthook" "$@"
29+
elif test -f "$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook_${osArch}_${cpuArch}/lefthook"
30+
then
31+
"$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook_${osArch}_${cpuArch}/lefthook" "$@"
32+
33+
elif bundle exec lefthook -h >/dev/null 2>&1
34+
then
35+
bundle exec lefthook "$@"
36+
elif yarn lefthook -h >/dev/null 2>&1
37+
then
38+
yarn lefthook "$@"
39+
elif pnpm lefthook -h >/dev/null 2>&1
40+
then
41+
pnpm lefthook "$@"
42+
elif swift package plugin lefthook >/dev/null 2>&1
43+
then
44+
swift package --disable-sandbox plugin lefthook "$@"
45+
elif command -v npx >/dev/null 2>&1
46+
then
47+
npx lefthook "$@"
48+
else
49+
echo "Can't find lefthook in PATH"
50+
fi
51+
}
52+
53+
call_lefthook run "pre-commit" "$@"

.husky/prepare-commit-msg

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/sh
2+
3+
if [ "$LEFTHOOK_VERBOSE" = "1" -o "$LEFTHOOK_VERBOSE" = "true" ]; then
4+
set -x
5+
fi
6+
7+
if [ "$LEFTHOOK" = "0" ]; then
8+
exit 0
9+
fi
10+
11+
call_lefthook()
12+
{
13+
dir="$(git rev-parse --show-toplevel)"
14+
osArch=$(uname | tr '[:upper:]' '[:lower:]')
15+
cpuArch=$(uname -m | sed 's/aarch64/arm64/')
16+
17+
if test -n "$LEFTHOOK_BIN"
18+
then
19+
"$LEFTHOOK_BIN" "$@"
20+
elif lefthook -h >/dev/null 2>&1
21+
then
22+
lefthook "$@"
23+
elif test -f "$dir/node_modules/lefthook/bin/index.js"
24+
then
25+
"$dir/node_modules/lefthook/bin/index.js" "$@"
26+
elif test -f "$dir/node_modules/@evilmartians/lefthook/bin/lefthook_${osArch}_${cpuArch}/lefthook"
27+
then
28+
"$dir/node_modules/@evilmartians/lefthook/bin/lefthook_${osArch}_${cpuArch}/lefthook" "$@"
29+
elif test -f "$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook_${osArch}_${cpuArch}/lefthook"
30+
then
31+
"$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook_${osArch}_${cpuArch}/lefthook" "$@"
32+
33+
elif bundle exec lefthook -h >/dev/null 2>&1
34+
then
35+
bundle exec lefthook "$@"
36+
elif yarn lefthook -h >/dev/null 2>&1
37+
then
38+
yarn lefthook "$@"
39+
elif pnpm lefthook -h >/dev/null 2>&1
40+
then
41+
pnpm lefthook "$@"
42+
elif swift package plugin lefthook >/dev/null 2>&1
43+
then
44+
swift package --disable-sandbox plugin lefthook "$@"
45+
elif command -v npx >/dev/null 2>&1
46+
then
47+
npx lefthook "$@"
48+
else
49+
echo "Can't find lefthook in PATH"
50+
fi
51+
}
52+
53+
call_lefthook run "prepare-commit-msg" "$@"

lefthook.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# EXAMPLE USAGE:
2+
#
3+
# Refer for explanation to following link:
4+
# https://github.com/evilmartians/lefthook/blob/master/docs/configuration.md
5+
6+
pre-commit:
7+
parallel: true
8+
commands:
9+
prettier:
10+
glob: '*.{yaml,yml,md}'
11+
run: pkgx +nodejs.org@20 +pnpm.io pnpm prettier --write {staged_files}
12+
stage_fixed: true

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
{
2-
"name": "website",
2+
"name": "@logchimp/docs",
33
"private": true,
44
"scripts": {
55
"prettier": "prettier --write \"**/*.{yaml,yml,md}\"",
66
"prepare": "husky install"
77
},
88
"engines": {
9-
"node": ">=12"
9+
"node": ">=20"
1010
},
1111
"devDependencies": {
1212
"husky": "7.0.4",
13+
"lefthook": "^1.6.7",
1314
"prettier": "2.6.2"
1415
}
1516
}

pnpm-lock.yaml

Lines changed: 119 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)