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

Commit

Permalink
Merge pull request #36 from fengmk2/iojs-support
Browse files Browse the repository at this point in the history
Add io.js support and download npm from github
  • Loading branch information
hakobera committed Jan 22, 2015
2 parents c6dec83 + 6e4c27d commit 2c20d4c
Show file tree
Hide file tree
Showing 4 changed files with 243 additions and 54 deletions.
19 changes: 15 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,28 @@ Usage
Example:
nvmw install v0.6.0 Install a specific version number
nvmw use v0.6.0 Use the specific version
nvmw install iojs Install the latest version of io.js
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
nvmw install iojs-v1.0.2
```

FAQ
Expand Down
6 changes: 6 additions & 0 deletions alias-node.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
:: Created by nvmw, please don't edit manually.
@IF EXIST "%~dp0\iojs.exe" (
"%~dp0\iojs.exe" %*
) ELSE (
iojs %*
)
76 changes: 58 additions & 18 deletions get_npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,67 @@ 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 = util.format(NPM_PKG_JSON_URL, nodeVersion);
wget(pkgUri, function (filename, pkg) {
if (binType === 'iojs') {
// detect npm version from https://iojs.org/dist/index.json
var NVMW_IOJS_ORG_MIRROR = process.env.NVMW_IOJS_ORG_MIRROR || 'https://iojs.org/dist';
var pkgUri = NVMW_IOJS_ORG_MIRROR + '/index.json';
wget(pkgUri, function (filename, content) {
if (filename === null) {
console.error('node %s does not include npm', nodeVersion);
process.exit(1);
return noNpmAndExit();
}
var npmVersion = JSON.parse(pkg).version;
var uri = util.format(BASE_URL, npmVersion);
wget(uri, function (filename, data) {
fs.writeFile(path.join(targetDir, 'npm.zip'), data, function (err) {
if (err) {
return console.log(err.message);
}
console.log('Download npm %s is done', npmVersion);
});
var npmVersion;
var items = JSON.parse(content);
for (var i = 0; i < items.length; i++) {
var item = items[i];
if (!npmVersion) {
// make sure has a npm version
npmVersion = item.npm;
}
if (item.version === binVersion && item.npm) {
npmVersion = item.npm;
break;
}
}

if (!npmVersion) {
return noNpmAndExit();
}
downloadNpmZip(npmVersion);
});
} else {
var pkgUri = util.format(NPM_PKG_JSON_URL, 'joyent/node',
binVersion === 'latest' ? 'master' : binVersion);
wget(pkgUri, function (filename, pkg) {
if (filename === null) {
return noNpmAndExit();
}
downloadNpmZip(JSON.parse(pkg).version);
});
}

function noNpmAndExit() {
console.error('%s %s does not include npm', binType, binVersion);
process.exit(1);
}

function downloadNpmZip(version) {
var uri = util.format(BASE_URL, version);
wget(uri, function (filename, data) {
fs.writeFile(path.join(targetDir, 'npm.zip'), data, function (err) {
if (err) {
return console.error(err.message);
}
console.log('Download npm %s is done', version);
});
});
});
}
Loading

0 comments on commit 2c20d4c

Please sign in to comment.