From 6217ebf7c7ff804f80b3612ac755045c6734d575 Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Sat, 17 Jan 2015 18:17:05 +0800 Subject: [PATCH] Add io.js support and download npm from github Install iojs just like nvm does, https://github.com/creationix/nvm/issues/590 nvmw install iojs/1.0.2 nvmw use iojs/1.0.2 Fixes #30 #27 --- README.md | 18 ++++++++--- get_npm.js | 5 ++-- nvmw.bat | 88 ++++++++++++++++++++++++++++++++++++++++++------------ 3 files changed, 86 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 1a1e9c2..882a115 100644 --- a/README.md +++ b/README.md @@ -34,17 +34,27 @@ Usage Example: nvmw install v0.6.0 Install a specific version number nvmw use v0.6.0 Use the specific version + nvmw install iojs/v0.6.0 Install a specific version number of io.js + nvmw use iojs/v0.6.0 Use the specific version of io.js -Mirror nodejs dist + nvmw install v0.10.29 x86 Install a 32-bit version + +Mirror node.js/io.js/npm dist ------------------ To use a mirror of the node binaries, set `$NVMW_NODEJS_ORG_MIRROR`. -e.g.: In China, you use this mirror: +e.g.: In China, you can use these mirrors: ```bash -set "NVMW_NODEJS_ORG_MIRROR=http://dist.u.qiniudn.com" -nvmw install 0.11.12 +set "NVMW_NODEJS_ORG_MIRROR=http://npm.taobao.org/mirrors/node" +set "NVMW_IOJS_ORG_MIRROR=http://npm.taobao.org/mirrors/iojs" +set "NVMW_NPM_MIRROR=http://npm.taobao.org/mirrors/npm" + +nvmw install 0.11.14 +nvmw install node/v0.11.15 +nvmw install iojs/v1.0.2 +nvmw install iojs/latest ``` FAQ diff --git a/get_npm.js b/get_npm.js index de71ac9..09c6e25 100644 --- a/get_npm.js +++ b/get_npm.js @@ -4,8 +4,9 @@ var util = require('util'), wget = require('./wget'); var NPM_PKG_JSON_URL = 'https://raw.githubusercontent.com/joyent/node/%s/deps/npm/package.json'; -var NVMW_NODEJS_ORG_MIRROR = process.env.NVMW_NODEJS_ORG_MIRROR || 'http://nodejs.org/dist'; -var BASE_URL = NVMW_NODEJS_ORG_MIRROR + '/npm/npm-%s.zip'; +// https://github.com/npm/npm/tags +var NVMW_NPM_MIRROR = process.env.NVMW_NPM_MIRROR || 'https://github.com/npm/npm/archive'; +var BASE_URL = NVMW_NPM_MIRROR + '/v%s.zip'; var targetDir = process.argv[2]; var nodeVersion = process.argv[3]; diff --git a/nvmw.bat b/nvmw.bat index 44436aa..6b080d7 100644 --- a/nvmw.bat +++ b/nvmw.bat @@ -20,7 +20,11 @@ if %IS64% == TRUE ( ) if not defined NVMW_NODEJS_ORG_MIRROR ( - set "NVMW_NODEJS_ORG_MIRROR=http://nodejs.org/dist" + set "NVMW_NODEJS_ORG_MIRROR=https://nodejs.org/dist" +) + +if not defined NVMW_IOJS_ORG_MIRROR ( + set "NVMW_IOJS_ORG_MIRROR=https://iojs.org/dist" ) if "%1" == "install" if not "%2" == "" ( @@ -63,9 +67,11 @@ echo nvmw use [version] Modify PATH to use [version] echo nvmw ls List installed versions echo; echo Example: -echo nvmw install v0.10.21 Install a specific version number +echo nvmw install v0.10.21 Install a specific version number of node.js echo nvmw use v0.10.21 Use the specific version -echo +echo nvmw install iojs/v1.0.2 Install a specific version number of io.js +echo nvmw use iojs/v1.0.2 Use the specific version io.js +echo; echo nvmw install v0.10.29 x86 Install a 32-bit version exit /b 0 @@ -75,27 +81,44 @@ exit /b 0 :install setlocal +set NODE_TYPE="node" set NODE_VERSION=%1 + +if %NODE_VERSION:~4,1% == / ( + for /f "tokens=1,2,* delims=/" %%a in ("%NODE_VERSION%") do ( + set NODE_TYPE=%%a + set NODE_VERSION=%%b + ) +) + if not %NODE_VERSION:~0,1% == v ( - set NODE_VERSION=v%1 + set NODE_VERSION=v%NODE_VERSION% ) -if %OS_ARCH% == 32 ( - set NODE_EXE_URL=%NVMW_NODEJS_ORG_MIRROR%/%NODE_VERSION%/node.exe +if %NODE_TYPE% == iojs ( + set DIST_URL=%% + if %OS_ARCH% == 32 ( + set NODE_EXE_URL=%NVMW_IOJS_ORG_MIRROR%/%NODE_VERSION%/win-x86/iojs.exe + ) else ( + set NODE_EXE_URL=%NVMW_IOJS_ORG_MIRROR%/%NODE_VERSION%/win-x64/iojs.exe + ) ) else ( - set NODE_EXE_URL=%NVMW_NODEJS_ORG_MIRROR%/%NODE_VERSION%/x64/node.exe + if %OS_ARCH% == 32 ( + set NODE_EXE_URL=%NVMW_NODEJS_ORG_MIRROR%/%NODE_VERSION%/node.exe + ) else ( + set NODE_EXE_URL=%NVMW_NODEJS_ORG_MIRROR%/%NODE_VERSION%/x64/node.exe + ) ) -echo Start installing Node %NODE_VERSION% (x%OS_ARCH%) - -set "NODE_HOME=%NVMW_HOME%%NODE_VERSION%" +set "NODE_HOME=%NVMW_HOME%%NODE_TYPE%\%NODE_VERSION%" mkdir "%NODE_HOME%" +echo Start installing %NODE_TYPE%/%NODE_VERSION% (x%OS_ARCH%) to %NODE_HOME% + set "NODE_EXE_FILE=%NODE_HOME%\node.exe" set "NPM_ZIP_FILE=%NODE_HOME%\npm.zip" if not exist "%NODE_EXE_FILE%" ( - :: download node.exe cscript "%NVMW_HOME%\fget.js" %NODE_EXE_URL% "%NODE_EXE_FILE%" ) @@ -132,9 +155,18 @@ if not exist "%NODE_EXE_FILE%" ( :uninstall setlocal +set NODE_TYPE="node" set NODE_VERSION=%1 + +if %NODE_VERSION:~4,1% == / ( + for /f "tokens=1,2,* delims=/" %%a in ("%NODE_VERSION%") do ( + set NODE_TYPE=%%a + set NODE_VERSION=%%b + ) +) + if not %NODE_VERSION:~0,1% == v ( - set NODE_VERSION=v%1 + set NODE_VERSION=v%NODE_VERSION% ) if "%NVMW_CURRENT%" == "%NODE_VERSION%" ( @@ -165,25 +197,43 @@ if not exist "%NODE_HOME%" ( ::=========================================================== :use setlocal + +set NODE_TYPE="node" set NODE_VERSION=%1 + +if %NODE_VERSION:~4,1% == / ( + for /f "tokens=1,2,* delims=/" %%a in ("%NODE_VERSION%") do ( + set NODE_TYPE=%%a + set NODE_VERSION=%%b + ) +) + if not %NODE_VERSION:~0,1% == v ( - set NODE_VERSION=v%1 + set NODE_VERSION=v%NODE_VERSION% ) -set "NODE_HOME=%NVMW_HOME%%NODE_VERSION%" +set "NODE_HOME=%NVMW_HOME%%NODE_TYPE%\%NODE_VERSION%" if not exist "%NODE_HOME%" ( - echo Node %NODE_VERSION% is not installed + echo %NODE_TYPE%/%NODE_VERSION% is not installed exit /b 1 ) endlocal +set NVMW_CURRENT_TYPE="node" set NVMW_CURRENT=%1 +if %NVMW_CURRENT:~4,1% == / ( + for /f "tokens=1,2,* delims=/" %%a in ("%NVMW_CURRENT%") do ( + set NVMW_CURRENT_TYPE=%%a + set NVMW_CURRENT=%%b + ) +) + if not %NVMW_CURRENT:~0,1% == v ( - set NVMW_CURRENT=v%1 + set NVMW_CURRENT=v%NVMW_CURRENT% ) -echo Now using Node %NVMW_CURRENT% -set "PATH=%NVMW_HOME%;%NVMW_HOME%\%NVMW_CURRENT%;%PATH_ORG%" +echo Now using %NVMW_CURRENT_TYPE% %NVMW_CURRENT% +set "PATH=%NVMW_HOME%;%NVMW_HOME%\%NVMW_CURRENT_TYPE%\%NVMW_CURRENT%;%PATH_ORG%" exit /b 0 ::=========================================================== @@ -197,6 +247,6 @@ if not defined NVMW_CURRENT ( ) else ( set NVMW_CURRENT_V=%NVMW_CURRENT% ) -echo Current: %NVMW_CURRENT_V% +echo Current: %NVMW_CURRENT_TYPE%/%NVMW_CURRENT_V% endlocal exit /b 0