Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # get output
  4. output=`npm outdated --long`
  5.  
  6. # get name and type (regular or dev dependency) of all packages
  7. counter=0
  8. for token in $output
  9. do
  10. if [ $((counter > 6)) == 1 ] # skip first 7 tokens
  11. then
  12. # add package name to packages array
  13. if [ $(((counter - 1) % 6)) == 0 ]
  14. then
  15. packages+=($token)
  16. fi
  17.  
  18. # add dependency type to types array
  19. if [ $((counter % 6)) == 0 ]
  20. then
  21. types+=($token)
  22. fi
  23. fi
  24.  
  25. # increment counter
  26. ((counter++))
  27. done
  28.  
  29. # make sure that both arrays have the same length
  30. if [ ${#packages[@]} != ${#types[@]} ]
  31. then
  32. echo "error: package and types array length differs"
  33. exit 1
  34. fi
  35.  
  36. # run `npm install <package>@latest --save(-dev)` for each package
  37. for i in "${!packages[@]}"
  38. do
  39. if [[ ${types[$i]} == dev* ]]
  40. then
  41. npm install ${packages[$i]}@latest --save-dev
  42. else
  43. npm install ${packages[$i]}@latest --save
  44. fi
  45. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement