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

Add io.js support and download npm from github #36

Merged
merged 6 commits into from
Jan 22, 2015
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As same as nvm now.


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';

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Download npm from github by default. And also can download npm from a mirror site like https://npm.taobao.org/mirrors/npm

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

archive npm missing npm.cmd, I need to auto create npm.cmd to fix this.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

auto create npm.cmd script is include in deepak1556@9fb3693

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