Created
July 22, 2020 18:40
-
-
Save ajmas/d28f4d4d723c6e98d5249d96334b4e03 to your computer and use it in GitHub Desktop.
Git hook for NodeJS development
This file contains hidden or 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 | |
## 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