1 | debug () {
|
2 | if [ "$HUSKY_DEBUG" = "true" ] || [ "$HUSKY_DEBUG" = "1" ]; then
|
3 | echo "husky:debug $1"
|
4 | fi
|
5 | }
|
6 |
|
7 | command_exists () {
|
8 | command -v "$1" >/dev/null 2>&1
|
9 | }
|
10 |
|
11 | run_command () {
|
12 | if command_exists "$1"; then
|
13 | "$@" husky-run $hookName "$gitParams"
|
14 |
|
15 | exitCode="$?"
|
16 | debug "$* husky-run exited with $exitCode exit code"
|
17 |
|
18 | if [ $exitCode -eq 127 ]; then
|
19 | echo "Can't find Husky, skipping $hookName hook"
|
20 | echo "You can reinstall it using 'npm install husky --save-dev' or delete this hook"
|
21 | else
|
22 | exit $exitCode
|
23 | fi
|
24 |
|
25 | else
|
26 | echo "Can't find $1 in PATH: $PATH"
|
27 | echo "Skipping $hookName hook"
|
28 | exit 0
|
29 | fi
|
30 | }
|
31 |
|
32 | hookIsDefined () {
|
33 | grep -qs $hookName \
|
34 | package.json \
|
35 | .huskyrc \
|
36 | .huskyrc.json \
|
37 | .huskyrc.yaml \
|
38 | .huskyrc.yml
|
39 | }
|
40 |
|
41 | huskyVersion="0.0.0"
|
42 | gitParams="$*"
|
43 | hookName="$(basename "$0")"
|
44 |
|
45 | debug "husky v$huskyVersion - $hookName"
|
46 |
|
47 |
|
48 | if [ "$HUSKY_SKIP_HOOKS" = "true" ] || [ "$HUSKY_SKIP_HOOKS" = "1" ]; then
|
49 | debug "HUSKY_SKIP_HOOKS is set to $HUSKY_SKIP_HOOKS, skipping hook"
|
50 | exit 0
|
51 | fi
|
52 |
|
53 |
|
54 | . "$(dirname "$0")/husky.local.sh"
|
55 | debug "Current working directory is $(pwd)"
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 | if [ ! -f .huskyrc.js ] && [ ! -f husky.config.js ] && ! hookIsDefined; then
|
62 | debug "$hookName config not found, skipping hook"
|
63 | exit 0
|
64 | fi
|
65 |
|
66 |
|
67 | if [ -f ~/.huskyrc ]; then
|
68 | debug "source ~/.huskyrc"
|
69 | . ~/.huskyrc
|
70 | fi
|
71 |
|
72 |
|
73 | case $hookName in
|
74 | "pre-push"|"post-rewrite")
|
75 | export HUSKY_GIT_STDIN="$(cat)";;
|
76 | esac
|
77 |
|
78 |
|
79 | if command_exists winpty && test -t 1; then
|
80 | exec < /dev/tty
|
81 | fi
|
82 |
|
83 |
|
84 | case $packageManager in
|
85 | "npm") run_command npx --no-install;;
|
86 | "npminstall") run_command npx --no-install;;
|
87 | "pnpm") run_command pnpx --no-install;;
|
88 | "yarn") run_command yarn run --silent;;
|
89 | *) echo "Unknown package manager: $packageManager"; exit 0;;
|
90 | esac
|