Skip to content

Commit

Permalink
Add io.js support and download npm from github
Browse files Browse the repository at this point in the history
Install iojs just like nvm does, nvm-sh/nvm#590

    nvmw install iojs/1.0.2
    nvmw use iojs/1.0.2

Fixes hakobera#30 hakobera#27
  • Loading branch information
fengmk2 committed Jan 17, 2015
1 parent c6dec83 commit 6217ebf
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 25 deletions.
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions get_npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
88 changes: 69 additions & 19 deletions nvmw.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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" == "" (
Expand Down Expand Up @@ -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

Expand All @@ -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%"
)

Expand Down Expand Up @@ -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%" (
Expand Down Expand Up @@ -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

::===========================================================
Expand All @@ -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

0 comments on commit 6217ebf

Please sign in to comment.