Skip to content

Instantly share code, notes, and snippets.

@ajmas
Created July 22, 2020 18:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajmas/d28f4d4d723c6e98d5249d96334b4e03 to your computer and use it in GitHub Desktop.
Save ajmas/d28f4d4d723c6e98d5249d96334b4e03 to your computer and use it in GitHub Desktop.
Git hook for NodeJS development
#!/bin/sh
## Checks to see if the package.json changed following a checkout or merge and then automatically
## runs `npm install`. If you use yarn or pnpm, then change the line with `npm install` as needed.
##
## add this code to both .git/hooks/post-checkout and .git/hooks/post-merge
file="package.json"
if [[ $(git diff HEAD@{1}..HEAD@{0} -- "${file}" | wc -l) -gt 0 ]]
then
echo "Package.json changed, running npm install"
npm install
else
echo "No change in package.json"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment