Last active
March 25, 2023 20:00
-
-
Save dekadentno/b689561bc7759991e3b96884d09b1be4 to your computer and use it in GitHub Desktop.
pre commit hook
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
#!/bin/sh | |
#yorkie 2.0.0 | |
command_exists () { | |
command -v "$1" >/dev/null 2>&1 | |
} | |
has_hook_script () { | |
[ -f package.json ] && cat package.json | grep -q "\"$1\"[[:space:]]*:" | |
} | |
# OS X and Linux only | |
load_nvm () { | |
# If nvm is not loaded, load it | |
command_exists nvm || { | |
export NVM_DIR="$1" | |
[ -s "$1/nvm.sh" ] && . "$1/nvm.sh" | |
} | |
} | |
# OS X and Linux only | |
run_nvm () { | |
# If nvm has been loaded correctly, use project .nvmrc | |
command_exists nvm && [ -f .nvmrc ] && nvm use | |
} | |
cd "." | |
# Check if pre-commit is defined, skip if not | |
has_hook_script pre-commit || exit 0 | |
# Add common path where Node can be found | |
# Brew standard installation path /usr/local/bin | |
# Node standard installation path /usr/local | |
export PATH="$PATH:/usr/local/bin:/usr/local" | |
# Try to load nvm using path of standard installation | |
load_nvm /Users/mlazarevic/.nvm | |
run_nvm | |
# Export Git hook params | |
export GIT_PARAMS="$*" | |
# Run hook | |
node "./node_modules/yorkie/src/runner.js" pre-commit || { | |
echo | |
echo "pre-commit hook failed (add --no-verify to bypass)" | |
exit 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment