Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement