-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
373 additions
and
297 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
debug () { | ||
if [ "$HUSKY_DEBUG" = "true" ] || [ "$HUSKY_DEBUG" = "1" ]; then | ||
echo "husky:debug $1" | ||
fi | ||
} | ||
|
||
command_exists () { | ||
command -v "$1" >/dev/null 2>&1 | ||
} | ||
|
||
run_command () { | ||
if command_exists "$1"; then | ||
"$@" husky-run $hookName "$gitParams" | ||
|
||
exitCode="$?" | ||
debug "$* husky-run exited with $exitCode exit code" | ||
|
||
if [ $exitCode -eq 127 ]; then | ||
echo "Can't find Husky, skipping $hookName hook" | ||
echo "You can reinstall it using 'npm install husky --save-dev' or delete this hook" | ||
else | ||
exit $exitCode | ||
fi | ||
|
||
else | ||
echo "Can't find $1 in PATH: $PATH" | ||
echo "Skipping $hookName hook" | ||
exit 0 | ||
fi | ||
} | ||
|
||
hookIsDefined () { | ||
grep -qs $hookName \ | ||
package.json \ | ||
.huskyrc \ | ||
.huskyrc.json \ | ||
.huskyrc.yaml \ | ||
.huskyrc.yml \ | ||
.huskyrc.js \ | ||
husky.config.js | ||
} | ||
|
||
huskyVersion="0.0.0" | ||
gitParams="$*" | ||
hookName="$(basename "$0")" | ||
|
||
debug "husky v$huskyVersion - $hookName" | ||
|
||
# Skip if HUSKY_SKIP_HOOKS is set | ||
if [ "$HUSKY_SKIP_HOOKS" = "true" ] || [ "$HUSKY_SKIP_HOOKS" = "1" ]; then | ||
debug "HUSKY_SKIP_HOOKS is set to $HUSKY_SKIP_HOOKS, skipping hook" | ||
exit 0 | ||
fi | ||
|
||
# Source user var and change directory | ||
. "$(dirname $0)/husky.local.sh" | ||
debug "Current working directory is $(pwd)" | ||
|
||
# Skip fast if hookName is not defined | ||
if ! hookIsDefined; then | ||
debug "$hookName config not found, skip" | ||
exit 0 | ||
fi | ||
|
||
# Source user ~/.huskyrc | ||
if [ -f ~/.huskyrc ]; then | ||
debug "source ~/.huskyrc" | ||
. ~/.huskyrc | ||
fi | ||
|
||
# Set HUSKY_GIT_STDIN from stdin | ||
case $hookName in | ||
"pre-push"|"pre-receive"|"post-receive"|"post-rewrite") | ||
export HUSKY_GIT_STDIN="$(cat)";; | ||
esac | ||
|
||
# Windows 10, Git Bash and Yarn 1 installer | ||
if command_exists winpty && test -t 1; then | ||
exec < /dev/tty | ||
fi | ||
|
||
# Run husky-run with the package manager used to install Husky | ||
case $packageManager in | ||
"npm") run_command npx --no-install;; | ||
"pnpm") run_command pnpx --no-install;; | ||
"yarn") run_command yarn run --silent;; | ||
"*") echo "Unknown package manager: $packageManager"; exit 0;; | ||
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import './__env__' | ||
import { getHookScript } from '../hooks' | ||
import { getLocalScript } from '../localScript' | ||
import { getMainScript } from '../mainScript' | ||
|
||
describe('hookScript', (): void => { | ||
it('should match snapshot', (): void => { | ||
const script = getHookScript() | ||
expect(script).toMatchSnapshot() | ||
}) | ||
}) | ||
|
||
describe('localScript', (): void => { | ||
it('should match snapshot', (): void => { | ||
const script = getLocalScript('npm', '.') | ||
expect(script).toMatchSnapshot() | ||
}) | ||
}) | ||
|
||
describe('mainScript', (): void => { | ||
it('should match snapshot', (): void => { | ||
const script = getMainScript() | ||
expect(script).toMatchSnapshot() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import path = require('path') | ||
import { readPkg } from '../read-pkg' | ||
|
||
export function getBanner(): string { | ||
const pkgHomepage = process.env.npm_package_homepage | ||
const pkgDirectory = process.env.PWD | ||
|
||
const { homepage: huskyHomepage, version: huskyVersion } = readPkg( | ||
path.join(__dirname, '../..') | ||
) | ||
|
||
const createdAt = new Date().toLocaleString() | ||
return `# Created by Husky v${huskyVersion} (${huskyHomepage}) | ||
# At: ${createdAt} | ||
# From: ${pkgDirectory} (${pkgHomepage})` | ||
} |
Oops, something went wrong.