Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions hook
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ if [[ -z "$HAS_NODE" ]]; then
source_home_file ".bash_profile" || source_home_file ".zshrc" || source_home_file ".bashrc" || true
fi

[ "$NVM_DIR" = "" ] && export NVM_DIR="$HOME/.nvm"
if [ -f "$NVM_DIR/nvm.sh" ]; then
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
nvm install
nvm use
fi

NVMNODE=`nvm which node 2> /dev/null`
NODE=`which node 2> /dev/null`
NODEJS=`which nodejs 2> /dev/null`
IOJS=`which iojs 2> /dev/null`
Expand All @@ -27,7 +36,9 @@ BINARY=
#
# Figure out which binary we need to use for our script execution.
#
if [[ -n "$NODE" ]]; then
if [[ -n "$NVMNODE" ]]; then
BINARY="$NVMNODE"
elif [[ -n "$NODE" ]]; then
BINARY="$NODE"
elif [[ -n "$NODEJS" ]]; then
BINARY="$NODEJS"
Expand All @@ -37,8 +48,12 @@ elif [[ -x "$LOCAL" ]]; then
BINARY="$LOCAL"
fi

if [ ! -f "$BINARY" ]; then
echo "something wrong: node not exist"
exit 1
fi
#
# Add --dry-run cli flag support so we can execute this hook without side effects
# Add --dry-run cli flag support so we can execute this hook without side affects
# and see if it works in the current environment
#
if [[ $* == *--dry-run* ]]; then
Expand All @@ -47,4 +62,4 @@ if [[ $* == *--dry-run* ]]; then
fi
else
"$BINARY" "$("$BINARY" -e "console.log(require.resolve('pre-commit'))")"
fi
fi