Skip to content

Instantly share code, notes, and snippets.

@digitaljhelms
Last active February 4, 2024 14:15
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save digitaljhelms/7901283 to your computer and use it in GitHub Desktop.
Save digitaljhelms/7901283 to your computer and use it in GitHub Desktop.
Git hook to call `bower install` and `npm install` automatically.
#!/bin/sh
echo "[post-rewrite hook: $1]"
# by noahgrant & digitaljhelms
#
# quick script to call "bower install" and "npm install" automatically if
# bower.json or package.json are changed, respectively
#
# this assumes one top-level file for each
changedfiles=( `git diff-tree --no-commit-id --name-only HEAD@{1} HEAD` )
if [[ "${changedfiles[*]}" =~ "bower.json" ]]; then
echo "bower installing"
bower install && bower update
fi
if [[ "${changedfiles[*]}" =~ "package.json" ]]; then
echo "npm installing"
npm install
fi
@giosh94mhz
Copy link

Thanks for sharing!

There is a minor issue: you should change #!/bin/sh to #!/bin/bash, or you'll get a syntax error. Maybe something is not POSIX compliant, and does not work with "basic" shells like dash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment