It's been a while since I published my article on Automatically Install NPM Dependencies on Git Pull. After receiving a lot of positive feedback, I put all that stuff into an NPM package that automatically checks for changes and runs commands or scripts if there are any.
The package must be integrated with Husky to be executed during the post-merge
git hook. A pattern must be specified to match files when pulling changes. If any change matches the specified pattern, the provided command or script will be executed automatically.
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
# matches the package-lock.json inside project directory
# executes command npm install
# runs script post-merge
npx git-pull-run -p "package-lock.json" -c "npm install" -s "post-merge"
This executes the npm install
command and runs the npm run post-merge
script and prints the following output to the console.
Recently I received an issue on my GitHub repository with a request to print a message on the console if changes were found during the git pull. This was already possible with the command option -c 'echo "message"'
, but can be quite tricky because the quotes have to be escaped properly. Today I released a new version that enables this feature natively with a dedicated message option.
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
# matches only the package-lock.json inside project directory
# prints message to the console
npx git-pull-run -p "package-lock.json" -m "Some packages were changed. Run 'npm i' to update your dependencies"
This prints the specified message to the console when git changes are pulled, and does not execute any commands or scripts.
I hope this package might be useful to someone and would appreciate your feedback and opinion.
Top comments (0)