This repository has been archived by the owner on Dec 24, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 179
Add io.js support and download npm from github #36
Merged
+243
−54
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c65dd94
Add io.js support and download npm from github
fengmk2 de24de1
Detect npm version from iojs.org/dist/index.json if install iojs
fengmk2 98b9c9a
Alias node to iojs
fengmk2 0172da1
support latest version
fengmk2 68ab444
Change cli api to nvm does
fengmk2 6e4c27d
Keep node version folder save path as before
fengmk2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %* | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. archive npm missing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. auto create |
||
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); | ||
}); | ||
}); | ||
}); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.