Last active
April 14, 2019 20:29
-
-
Save svewag/4db7e1fb6b27ac5253453b4500a09829 to your computer and use it in GitHub Desktop.
reinstall node-modules after package-lock.json or .nvmrc has changed
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
#!/usr/bin/env bash | |
files=("package-lock.json" ".nvmrc") | |
for file in "${files[@]}"; do | |
# The HEAD@{1} is a special notation for the commit that HEAD used to be | |
# at prior to the original reset commit (1 change ago) | |
# See more: https://git-scm.com/docs/git-reflog | |
if [[ $(git diff HEAD@{1}..HEAD@{0} -- "${file}" | wc -l) -gt 0 ]]; then | |
echo | |
echo -e "======> \e[33;1m»${file}« has changed!\e[0m" | |
echo -e "======> \e[33;1mreinstalling (dev-)dependencies by running »npm ci«\e[0m" | |
echo | |
npm ci | |
break | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In order to reinstall the node-modules when the
package-lock.json
or the.nvmrc
has changed after a git checkout, merge or rebase, you have to setup the following git hooks: