Created
July 27, 2017 05:58
-
-
Save simonhaenisch/19a9e1bbc72e5d69e774df4eacc46dbd to your computer and use it in GitHub Desktop.
update all outdated npm packages to latest version
This file contains hidden or 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
#!/bin/bash | |
# get output | |
output=`npm outdated --long` | |
# get name and type (regular or dev dependency) of all packages | |
counter=0 | |
for token in $output | |
do | |
if [ $((counter > 6)) == 1 ] # skip first 7 tokens | |
then | |
# add package name to packages array | |
if [ $(((counter - 1) % 6)) == 0 ] | |
then | |
packages+=($token) | |
fi | |
# add dependency type to types array | |
if [ $((counter % 6)) == 0 ] | |
then | |
types+=($token) | |
fi | |
fi | |
# increment counter | |
((counter++)) | |
done | |
# make sure that both arrays have the same length | |
if [ ${#packages[@]} != ${#types[@]} ] | |
then | |
echo "error: package and types array length differs" | |
exit 1 | |
fi | |
# run `npm install <package>@latest --save(-dev)` for each package | |
for i in "${!packages[@]}" | |
do | |
if [[ ${types[$i]} == dev* ]] | |
then | |
npm install ${packages[$i]}@latest --save-dev | |
else | |
npm install ${packages[$i]}@latest --save | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment