Skip to content
This repository has been archived by the owner on Dec 24, 2018. It is now read-only.

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 #30 #27
  • Loading branch information
fengmk2 committed Jan 18, 2015
1 parent c6dec83 commit c65dd94
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 38 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/v1.0.2 Install a specific version number of io.js
nvmw use iojs/v1.0.2 Use the specific version of io.js

Mirror nodejs dist
nvmw install v0.10.35 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
21 changes: 15 additions & 6 deletions get_npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,26 @@ var util = require('util'),
path = require('path'),
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';
var NPM_PKG_JSON_URL = 'https://raw.githubusercontent.com/%s/%s/deps/npm/package.json';
// 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];
var versions = process.argv[3].split('/');
var binType = versions[0];
var binVersion = versions[1];

var pkgUri;
if (binType === 'iojs') {
pkgUri = util.format(NPM_PKG_JSON_URL, 'iojs/io.js', binVersion + '-release');
} else {
pkgUri = util.format(NPM_PKG_JSON_URL, 'joyent/node', binVersion);
}

var pkgUri = util.format(NPM_PKG_JSON_URL, nodeVersion);
wget(pkgUri, function (filename, pkg) {
if (filename === null) {
console.error('node %s does not include npm', nodeVersion);
console.error('%s %s does not include npm', binType, binVersion);
process.exit(1);
}
var npmVersion = JSON.parse(pkg).version;
Expand Down
120 changes: 92 additions & 28 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,10 +67,12 @@ 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 v0.10.29 x86 Install a 32-bit version
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.35 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 All @@ -105,17 +128,20 @@ if not exist "%NODE_EXE_FILE%" (
) else (
echo Start install npm

"%NODE_EXE_FILE%" "%NVMW_HOME%\get_npm.js" "%NODE_HOME%" %NODE_VERSION%
"%NODE_EXE_FILE%" "%NVMW_HOME%\get_npm.js" "%NODE_HOME%" "%NODE_TYPE%/%NODE_VERSION%"
if not exist %NPM_ZIP_FILE% (
exit /b 0;
)

set "CD_ORG=%CD%"
cd "%NODE_HOME%"
cscript "%NVMW_HOME%\unzip.js" "%NPM_ZIP_FILE%" "%NODE_HOME%"
mkdir "%NODE_HOME%\node_modules"
move npm-* "%NODE_HOME%\node_modules\npm"
copy "%NODE_HOME%\node_modules\npm\bin\npm.cmd" "%NODE_HOME%\npm.cmd"
cd "%CD_ORG%"
if not exist "%NODE_HOME%\npm.cmd" goto install_error
echo npm %NPM_VERSION% install ok
echo npm install ok

echo Finished
endlocal
Expand All @@ -132,29 +158,38 @@ 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%" (
echo Cannot uninstall currently-active Node version, %NODE_VERSION%
echo Cannot uninstall currently-active %NODE_TYPE%/%NODE_VERSION%
exit /b 1
)

set "NODE_HOME=%NVMW_HOME%\%NODE_VERSION%"
set "NODE_HOME=%NVMW_HOME%\%NODE_TYPE%\%NODE_VERSION%"
set "NODE_EXE_FILE=%NODE_HOME%\node.exe"

if not exist "%NODE_HOME%" (
echo %NODE_VERSION% is not installed
echo %NODE_TYPE%/%NODE_VERSION% is not installed
exit /b 1
) else (
rd /Q /S "%NODE_HOME%"
if ERRORLEVEL == 1 (
echo Cannot uninstall Node version, %NODE_VERSION%
echo Cannot uninstall %NODE_TYPE%/%NODE_VERSION%
exit /b 1
) else (
echo Uninstalled Node %NODE_VERSION%
echo Uninstalled %NODE_TYPE%/%NODE_VERSION%
endlocal
exit /b 0
)
Expand All @@ -165,38 +200,67 @@ 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

::===========================================================
:: ls : List installed versions
::===========================================================
:ls
setlocal
dir "%NVMW_HOME%\v*" /b /ad

echo node:
if exist "%NVMW_HOME%\node" (
dir "%NVMW_HOME%\node\v*" /b /ad
)
echo;
echo iojs:
if exist "%NVMW_HOME%\iojs" (
dir "%NVMW_HOME%\iojs\v*" /b /ad
)
echo;

if not defined NVMW_CURRENT (
set NVMW_CURRENT_V=none
) 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 c65dd94

Please sign in to comment.