Skip to content

Instantly share code, notes, and snippets.

@navarroaxel
Created February 8, 2017 01:48
Show Gist options
  • Save navarroaxel/575d131713bc88e681034a963b3e51df to your computer and use it in GitHub Desktop.
Save navarroaxel/575d131713bc88e681034a963b3e51df to your computer and use it in GitHub Desktop.
#!/bin/sh
#husky 0.13.1
command_exists () {
command -v "$1" >/dev/null 2>&1
}
load_nvm () {
export $1=$2
[ -s "$1/nvm.sh" ] && . $1/nvm.sh
exists nvm && [ -f .nvmrc ] && nvm use
}
has_hook_script () {
[ -f package.json ] && cat package.json | grep -q "\"$1\"[[:space:]]*:"
}
cd .
has_hook_script precommit || exit 0
command_exists npm || load_nvm NVM_DIR /home/anavarro/.nvm
command_exists npm || {
echo >&2 "> husky - Can't find npm in PATH. Skipping precommit script in package.json"
exit 0
}
echo
echo "> husky - npm run -s precommit"
echo
export GIT_PARAMS="$*"
npm run -s precommit || {
echo
echo "> husky - pre-commit hook failed (add --no-verify to bypass)"
echo "> husky - to debug, use 'npm run precommit'"
exit 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment