Skip to content

Instantly share code, notes, and snippets.

@buo
Created January 2, 2018 08:15
Show Gist options
  • Save buo/b04a9378ef136cdfbf56a7d45f6ef2c6 to your computer and use it in GitHub Desktop.
Save buo/b04a9378ef136cdfbf56a7d45f6ef2c6 to your computer and use it in GitHub Desktop.
Update outdated NPM packages and commit the changes
#!/bin/bash
npm install
for info in $(npm outdated --parseable --depth=0);
do
pkg=$(echo "$info" | cut -d: -f4 | cut -d@ -f1)
current=$(echo "$info" | cut -d: -f3 | cut -d@ -f2)
wanted=$(echo "$info" | cut -d: -f2 | cut -d@ -f2)
if [ "$current" != "$wanted" ]; then
echo "$pkg: $current -> $wanted"
npm update -S $pkg
git add package*
git commit -am "Update $pkg from $current to $wanted"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment