Guest User

Untitled

a guest
May 25th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. @echo off
  2. SETLOCAL EnableDelayedExpansion
  3.  
  4. if [%1] == ["latest"] (
  5. echo Pass in the version you would like to install, or "latest" to install the latest npm version.
  6. ) else (
  7. set wanted_version="latest"
  8.  
  9. if "!wanted_version!" == "latest" (
  10. for /f %%i in ('npm show npm version') do set wanted_version=%%i
  11. )
  12.  
  13. for /f %%i in ('npm -g -v') do set cur_version=%%i
  14.  
  15. if "!cur_version!" == "!wanted_version!" (
  16. echo Already on npm version !wanted_version!.
  17. ) else (
  18. echo Updating to !wanted_version!...
  19.  
  20. set node_path=!PROGRAMFILES!\nodejs
  21.  
  22. rename "!node_path!\npm" npm2
  23. rename "!node_path!\npm.cmd" npm2.cmd
  24. rename "!node_path!\node_modules\npm" npm2
  25. node "!node_path!\node_modules\npm2\bin\npm-cli.js" i npm@!wanted_version! -g
  26.  
  27. for /f %%i in ('npm -g -v') do set new_version=%%i
  28.  
  29. echo New version installed is !new_version!
  30.  
  31. if "!new_version!" == "!wanted_version!" (
  32. echo Successfully updated to !wanted_version!. Cleaning up backups...
  33. del "!node_path!\npm2"
  34. del "!node_path!\npm2.cmd"
  35. @RD /S /Q "!node_path!\node_modules\npm2"
  36. echo Update complete.
  37. ) else (
  38. echo Something went wrong. Rolling back.
  39. if exist "!node_path!\npm" (
  40. del "!node_path!\npm"
  41. )
  42. if exist "!node_path!\npm.cmd" (
  43. del "!node_path!\npm.cmd"
  44. )
  45. if exist "!node_path!\node_modules\npm" (
  46. @RD /S /Q "!node_path!\node_modules\npm"
  47. )
  48. rename "!node_path!\npm2" npm
  49. rename "!node_path!\npm2.cmd" npm.cmd
  50. rename "!node_path!\node_modules\npm2" npm
  51. )
  52. )
  53. )
Add Comment
Please, Sign In to add comment