Skip to content

Instantly share code, notes, and snippets.

@assaf
Created July 9, 2014 00:43
Show Gist options
  • Save assaf/6bc56255459aa75f27b3 to your computer and use it in GitHub Desktop.
Save assaf/6bc56255459aa75f27b3 to your computer and use it in GitHub Desktop.
.git/hook/pre-commit
#!/bin/sh
#
# Run npm shrinkwrap on every commit, make sure we have the most recent
# dependencies checked into git.
DEPTH=10 # Set this to N to include more descendants in shrinkwrap
PATH=/usr/local/bin:$PATH
# Success or error, npm shrinkwrap will output to both stdout and stderr.
# We're only interested in what stderr has to say when it fails.
npm prune > /dev/null
error=$(npm shrinkwrap --depth=$DEPTH 2>&1 > /dev/null)
if [[ $? -ne 0 ]] ; then
echo -e "$error"
exit 1
fi
# If modified, adds file, will be included in commit.
diff=$(git diff npm-shrinkwrap.json)
if [[ -n "$diff" ]] ; then
echo "Updated npm-shrinkwrap.json"
git add npm-shrinkwrap.json
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment