Skip to content

Instantly share code, notes, and snippets.

@aaronmccall
Last active August 29, 2015 13:57
Show Gist options
  • Save aaronmccall/9897398 to your computer and use it in GitHub Desktop.
Save aaronmccall/9897398 to your computer and use it in GitHub Desktop.
bash script to npm i --save-exact an npm package/module in every repo in a directory
#!/bin/bash
if [ $# -lt 2 ]; then
echo "Usage: update_package <directory> <package> [optional: <version>]"
exit 1
fi
if [ "$3" ]; then
version=$3
else
version="latest"
fi
echo "looking for: /^\s+\"${2}\":/ in package.json"
for arg in $( ls $1 | egrep '^dsm-' ); do
(
cd "$arg"
if egrep -q "\"${2}\":" package.json; then
echo "$arg has $2"
echo "running: npm i $2@$version --save-exact"
npm i "$2@$version" --save-exact
fi
)
done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment