代码拉取完成,页面将自动刷新
var util = require('util'),
fs = require('fs'),
path = require('path'),
wget = require('./wget');
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 || 'http://npm.taobao.org/mirrors/npm';
var BASE_URL = NVMW_NPM_MIRROR + '/v%s.zip';
var targetDir = process.argv[2];
var versions = process.argv[3].split('/');
var binType = versions[0];
var binVersion = versions[1];
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) {
return noNpmAndExit();
}
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 = "https://npm.taobao.org/mirrors/node/index.json";
wget(pkgUri, function (filename, pkg) {
if (filename === null) {
return noNpmAndExit();
}
var _pkg = JSON.parse(pkg);
for(var i = 0,n=_pkg.length;i<n;i++){
var obj = _pkg[i];
if(obj.version == binVersion){
downloadNpmZip(obj.npm);
}
}
});
}
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) {
if (filename === null) {
console.error('Can\'t get npm: ' + uri);
process.exit(1);
}
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);
});
});
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。