提交 19f8b228 编写于 作者: C Corey Butler

Merge branch 'master' of github.com:coreybutler/nvm-windows

### My Environment
- [ ] Windows 7 or below (not truly supported due to EOL)
- [ ] Windows 8
- [ ] Windows 8.1
- [ ] Windows 10
- [ ] Windows 10 IoT Core
- [ ] Windows Server 2012
- [ ] Windows Server 2012 R2
- [ ] Windows Server 2016
- [ ] My Windows installation is non-English.
### I have already...
- [ ] read the README to be aware of npm gotchas & antivirus issues.
- [ ] reviewed the [wiki](https://github.com/coreybutler/nvm-windows/wiki) to make sure my issue hasn't already been resolved.
- [ ] verified I'm using an account with administrative privileges.
- [ ] searched the issues (open and closed) to make sure this isn't a duplicate.
- [ ] made sure this isn't a question about how to use NVM for Windows, since [gitter](https://gitter.im/coreybutler/nvm-windows?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) is used for questions and comments.
### My issue is related to (check only those which apply):
- [ ] settings.txt
- [ ] proxy support
- [ ] 32 or 64 bit support
### Expected Behavior
Fill me in...
### Actual Behavior
Fill me in...
### Steps to reproduce the problem:
Fill me in...
......@@ -29,3 +29,6 @@ bin/*.exe
!bin/buildtools/*
bin/*.zip
bin/nvm/*
!.gitignore
......@@ -2,5 +2,4 @@
There have been a lot of duplicate issues filed. Please do a simple search for your issue before posting something new.
If you just have a question and no real problem, please use the Gitter channel instead of clogging up the bug tracker
with questions.
If you just have a question and no real problem, please use the [Gitter channel](https://gitter.im/coreybutler/nvm-windows) instead of clogging up the bug tracker with questions.
......@@ -2,13 +2,29 @@
[1.1]: http://i.imgur.com/wWzX9uB.png (Tweet about NVM for Windows)
[1]: https://twitter.com/intent/tweet?hashtags=nodejs&original_referer=http%3A%2F%2F127.0.0.1%3A91%2F&text=Check%20out%20NVM%20for%20Windows!&tw_p=tweetbutton&url=http%3A%2F%2Fgithub.com%2Fcoreybutler%2Fnvm-windows&via=goldglovecb
## NOTICE: SEEKING CORE CONTRIBUTORS & MAINTAINERS
_Are you multilingual?_
I am particularly interested in finding people who can speak something other than English. Several problems have come up with non-latin character sets (Chinese, Japanese, Arabic, etc). I am also interested in producing language packs/translations for the installers.
_Are you outside of the US/UK/Canada?_
Custom mirroring capabilities are available in the master branch, but I would like to work with folks in different geographic regions to assure node is accessible everywhere.
_Other (Anywhere)_
The core concepts of this version manager are pretty simple, so the core code base is pretty focused/simple. I've done some work to make this project available on all operating systems. The only reason it's been so slow to release is anticipation of an explosion of new installers (chocolatey, homebrew, rpm, .deb, .msi, etc). I've partnered up with BitRock to simplify creation of some of these, but the BitRock installers don't support all of these.
Of course, I would also love to have additional maintainers. If you're new to Go, that's OK - I was too, and that's what code reviews are for.
# Node Version Manager (nvm) for Windows
[![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/coreybutler/nvm-windows?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) (I post development updates here)
Manage multiple installations of node.js on a Windows computer.
**tl;dr** [nvm](https://github.com/creationix/nvm), but for Windows, with an installer. [Download Now](https://github.com/coreybutler/nvm/releases)! No io.js support, since [iojs is merging back with node](http://blog.nodejs.org/2015/05/15/node-leaders-are-building-an-open-foundation/), there is no longer a need to add special support for it.
**tl;dr** [nvm](https://github.com/creationix/nvm), but for Windows, with an installer. [Download Now](https://github.com/coreybutler/nvm/releases)! This has always been a node version manager, not an io.js manager, so there is no back-support for io.js. However, node 4+ is supported.
![NVM for Windows](http://coreybutler.github.io/nvm-windows/images/installlatest.jpg)
......@@ -22,6 +38,13 @@ bleeding edge version without uninstalling the stable version of node, this util
It comes with an installer (and uninstaller), because getting it should be easy. Please note, you need to uninstall any existing versions of node.js before installing NVM for Windows.
You should also delete the existing npm install location (e.g. "C:\Users\<user>\AppData\Roaming\npm") so that the nvm install location will be correctly used instead. After install, reinstalling global utilities (e.g. gulp) will have to be done for each installed version of node:
`nvm use 4.4.0`
`npm install gulp-cli -g`
`nvm use 0.10.33`
`npm install gulp-cli -g`
[Download the latest installer from the releases](https://github.com/coreybutler/nvm/releases).
![NVM for Windows Installer](http://coreybutler.github.io/nvm-windows/images/installer.jpg)
......@@ -50,6 +73,10 @@ NVM for Windows is a command line tool. Simply type `nvm` in the console for hel
Please note that any global npm modules you may have installed are **not** shared between the various versions of node.js you have installed.
Additionally, some npm modules may not be supported in the version of node you're using, so be aware of your environment as you work.
### Antivirus
Users have reported some problems using antivirus, specifically McAffee. It appears the antivirus software is manipulating access to the VBScript engine. See [issue #133](https://github.com/coreybutler/nvm-windows/issues/133) for details and resolution.
---
## Why another version manager?
......@@ -106,7 +133,7 @@ MIT.
## Thanks
Thanks to everyone who has submitted issues on and off Github, made suggestions, and generally helped make this a better project. Special thanks to [@vkbansal](https://github.com/vkbansal), who has actively provided feedback throughout the releases.
Thanks to everyone who has submitted issues on and off Github, made suggestions, and generally helped make this a better project. Special thanks to [@vkbansal](https://github.com/vkbansal), who has actively provided feedback throughout the releases. Thanks also go to [@rainabba](https://github.com/rainabba) and [@sullivanpt](https://github.com/sullivanpt) for getting Node v4 support integrated.
## Alternatives
......
......@@ -306,7 +306,7 @@ end;
[Run]
Filename: "{cmd}"; Parameters: "/C ""mklink /D ""{code:getSymLink}"" ""{code:getCurrentVersion}"""" "; Check: isNodeAlreadyInUse; Flags: runhidden;
Filename: "{cmd}"; Parameters: "/K ""set PATH={app};%PATH% && cls && nvm"""; Flags: runasoriginaluser postinstall;
Filename: "{cmd}"; Parameters: "/K ""set PATH={app};%PATH% && cls && nvm"""; Flags: runasoriginaluser postinstall skipifsilent;
[UninstallDelete]
Type: files; Name: "{app}\nvm.exe";
......
......@@ -8,7 +8,6 @@ import (
"io/ioutil"
"regexp"
"bytes"
"encoding/json"
"strconv"
"./nvm/web"
"./nvm/arch"
......@@ -26,6 +25,8 @@ type Environment struct {
root string
symlink string
arch string
node_mirror string
npm_mirror string
proxy string
originalpath string
originalversion string
......@@ -36,6 +37,8 @@ var env = &Environment{
root: "",
symlink: os.Getenv("NVM_SYMLINK"),
arch: os.Getenv("PROCESSOR_ARCHITECTURE"),
node_mirror: "",
npm_mirror: "",
proxy: "none",
originalpath: "",
originalversion: "",
......@@ -50,7 +53,7 @@ func main() {
// Capture any additional arguments
if len(args) > 2 {
detail = strings.ToLower(args[2])
detail = args[2]
}
if len(args) > 3 {
procarch = args[3]
......@@ -120,7 +123,9 @@ func update() {
}
func CheckVersionExceedsLatest(version string) bool{
content := web.GetRemoteTextFile("http://nodejs.org/dist/latest/SHASUMS256.txt")
//content := web.GetRemoteTextFile("http://nodejs.org/dist/latest/SHASUMS256.txt")
url := web.GetFullNodeUrl("latest/SHASUMS256.txt");
content := web.GetRemoteTextFile(url)
re := regexp.MustCompile("node-v(.+)+msi")
reg := regexp.MustCompile("node-v|-x.+")
latest := reg.ReplaceAllString(re.FindString(content),"")
......@@ -157,7 +162,8 @@ func install(version string, cpuarch string) {
// If user specifies "latest" version, find out what version is
if version == "latest" {
content := web.GetRemoteTextFile("http://nodejs.org/dist/latest/SHASUMS256.txt")
url := web.GetFullNodeUrl("latest/SHASUMS256.txt");
content := web.GetRemoteTextFile(url)
re := regexp.MustCompile("node-v(.+)+msi")
reg := regexp.MustCompile("node-v|-x.+")
version = reg.ReplaceAllString(re.FindString(content),"")
......@@ -401,29 +407,35 @@ func list(listtype string) {
fmt.Println("No installations recognized.")
}
} else {
_, stable, unstable := node.GetAvailable()
_, lts, stable, _ := node.GetAvailable()
releases := 15
releases := len(stable)
fmt.Println("\nShowing the "+strconv.Itoa(releases)+" latest available releases.\n")
fmt.Println(" STABLE | UNSTABLE ")
fmt.Println(" LTS | STABLE ")
fmt.Println(" ---------------------------")
for i := 0; i < releases; i++ {
str := "v"+stable[i]
for ii := 10-len(str); ii > 0; ii-- {
str = " "+str
str := " "
if len(lts) > i {
str = "v"+lts[i]
for ii := 10-len(str); ii > 0; ii-- {
str = " "+str
}
}
str = str+" | "
str2 := "v"+unstable[i]
for ii := 10-len(str2); ii > 0; ii-- {
str2 = " "+str2
str2 := ""
if len(stable) > i {
str2 = "v"+stable[i]
for ii := 10-len(str2); ii > 0; ii-- {
str2 = " "+str2
}
}
fmt.Println(" "+str+str2)
fmt.Println(" "+str + " | " + str2)
}
fmt.Println("\nFor a complete list, visit http://coreybutler.github.io/nodedistro")
fmt.Println("\nFor a complete list, visit https://nodejs.org/download/release")
}
}
......@@ -465,6 +477,8 @@ func help() {
fmt.Println(" nvm off : Disable node.js version management.")
fmt.Println(" nvm proxy [url] : Set a proxy to use for downloads. Leave [url] blank to see the current proxy.")
fmt.Println(" Set [url] to \"none\" to remove the proxy.")
fmt.Println(" nvm node_mirror [url] : Set a mirror to https://nodejs.org/dist/. Leave [url] blank to use default url.")
fmt.Println(" nvm npm_mirror [url] : Set a mirror to https://github.com/npm/npm/archive/. Leave [url] blank to default url.")
fmt.Println(" nvm uninstall <version> : The version must be a specific version.")
// fmt.Println(" nvm update : Automatically update nvm to the latest version.")
fmt.Println(" nvm use [version] [arch] : Switch to use the specified version. Optionally specify 32/64bit architecture.")
......@@ -478,17 +492,9 @@ func help() {
// Given a node.js version, returns the associated npm version
func getNpmVersion(nodeversion string) string {
// Get raw text
text := web.GetRemoteTextFile("https://raw.githubusercontent.com/coreybutler/nodedistro/master/nodeversions.json")
_, _, _, npm := node.GetAvailable()
// Parse
var data interface{}
json.Unmarshal([]byte(text), &data);
body := data.(map[string]interface{})
all := body["all"]
npm := all.(map[string]interface{})
return npm[nodeversion].(string)
return npm[nodeversion]
}
func updateRootDir(path string) {
......@@ -505,6 +511,7 @@ func updateRootDir(path string) {
func saveSettings() {
content := "root: "+strings.Trim(env.root," \n\r")+"\r\narch: "+strings.Trim(env.arch," \n\r")+"\r\nproxy: "+strings.Trim(env.proxy," \n\r")+"\r\noriginalpath: "+strings.Trim(env.originalpath," \n\r")+"\r\noriginalversion: "+strings.Trim(env.originalversion," \n\r")
content = content + "node_mirror: "+strings.Trim(env.node_mirror," \n\r")+ "npm_mirror: "+strings.Trim(env.npm_mirror," \n\r")
ioutil.WriteFile(env.settings, []byte(content), 0644)
}
......@@ -525,6 +532,10 @@ func Setup() {
env.originalversion = strings.Trim(regexp.MustCompile("originalversion:").ReplaceAllString(line,"")," \r\n")
} else if strings.Contains(line,"arch:"){
env.arch = strings.Trim(regexp.MustCompile("arch:").ReplaceAllString(line,"")," \r\n")
} else if strings.Contains(line, "node_mirror:"){
env.node_mirror = strings.Trim(regexp.MustCompile("node_mirror:").ReplaceAllString(line,"")," \r\n")
} else if strings.Contains(line, "npm_mirror:"){
env.npm_mirror = strings.Trim(regexp.MustCompile("npm_mirror:").ReplaceAllString(line,"")," \r\n")
} else if strings.Contains(line,"proxy:"){
env.proxy = strings.Trim(regexp.MustCompile("proxy:").ReplaceAllString(line,"")," \r\n")
if env.proxy != "none" && env.proxy != "" {
......@@ -535,7 +546,7 @@ func Setup() {
}
}
}
web.SetMirrors(env.node_mirror, env.npm_mirror)
env.arch = arch.Validate(env.arch)
// Make sure the directories exist
......
......@@ -6,7 +6,6 @@ import(
"regexp"
"io/ioutil"
"encoding/json"
"sort"
"../arch"
"../file"
"../web"
......@@ -17,7 +16,6 @@ import(
* Returns version, architecture
*/
func GetCurrentVersion() (string, string) {
cmd := exec.Command("node","-v")
str, err := cmd.Output()
if err == nil {
......@@ -71,7 +69,7 @@ func IsVersionInstalled(root string, version string, cpu string) bool {
func IsVersionAvailable(v string) bool {
// Check the service to make sure the version is available
avail, _, _ := GetAvailable()
avail, _, _, _ := GetAvailable()
for _, b := range avail {
if b == v {
......@@ -109,38 +107,37 @@ func (s BySemanticVersion) Less(i, j int) bool {
return v1.GTE(v2)
}
func GetAvailable() ([]string, []string, []string) {
func GetAvailable() ([]string, []string, []string, map[string]string) {
all := make([]string,0)
lts := make([]string,0)
stable := make([]string,0)
unstable := make([]string,0)
npm := make(map[string]string)
url := web.GetFullNodeUrl("index.json")
// Check the service to make sure the version is available
text := web.GetRemoteTextFile("https://raw.githubusercontent.com/coreybutler/nodedistro/master/nodeversions.json")
text := web.GetRemoteTextFile(url)
// Parse
var data interface{}
var data = make([]map[string]interface{}, 0)
json.Unmarshal([]byte(text), &data);
body := data.(map[string]interface{})
_all := body["all"]
_stable := body["stable"]
_unstable := body["unstable"]
allkeys := _all.(map[string]interface{})
stablekeys := _stable.(map[string]interface{})
unstablekeys := _unstable.(map[string]interface{})
for nodev, _ := range allkeys {
all = append(all,nodev)
}
for nodev, _ := range stablekeys {
stable = append(stable,nodev)
}
for nodev, _ := range unstablekeys {
unstable = append(unstable,nodev)
}
for _,element := range data {
var version = element["version"].(string)[1:]
all = append(all, version)
sort.Sort(BySemanticVersion(all))
sort.Sort(BySemanticVersion(stable))
sort.Sort(BySemanticVersion(unstable))
if val, ok := element["npm"].(string); ok {
npm[version] = val
}
switch v := element["lts"].(type) {
case bool:
if v == false {
stable = append(stable, version)
}
case string:
lts = append(lts, version)
}
}
return all, stable, unstable
return all, lts, stable, npm
}
......@@ -14,6 +14,8 @@ import(
)
var client = &http.Client{}
var nodeBaseAddress = "https://nodejs.org/dist/"
var npmBaseAddress = "https://github.com/npm/npm/archive/"
func SetProxy(p string){
if p != "" && p != "none" {
......@@ -24,6 +26,29 @@ func SetProxy(p string){
}
}
func SetMirrors(node_mirror string, npm_mirror string){
if node_mirror != "" && node_mirror != "none"{
nodeBaseAddress = node_mirror;
if strings.ToLower(nodeBaseAddress[0:4]) != "http" {
nodeBaseAddress = "http://"+nodeBaseAddress
}
}
if npm_mirror != "" && npm_mirror != "none"{
npmBaseAddress = npm_mirror;
if strings.ToLower(npmBaseAddress[0:4]) != "http" {
npmBaseAddress = "http://"+npmBaseAddress
}
}
}
func GetFullNodeUrl(path string) string{
return nodeBaseAddress+ path;
}
func GetFullNpmUrl(path string) string{
return npmBaseAddress + path;
}
func Download(url string, target string) bool {
output, err := os.Create(target)
......@@ -99,7 +124,8 @@ func GetNodeJS(root string, v string, a string) bool {
}
func GetNpm(root string, v string) bool {
url := "https://github.com/npm/npm/archive/v"+v+".zip"
//url := "https://github.com/npm/npm/archive/v"+v+".zip"
url := GetFullNpmUrl("v"+v+".zip")
// temp directory to download the .zip file
tempDir := root+"\\temp"
......@@ -160,15 +186,12 @@ func IsNode64bitAvailable(v string) bool {
}
func getNodeUrl (v string, vpre string) string {
url := "http://nodejs.org/dist/v"+v+"/" + vpre + "/node.exe"
//url := "http://nodejs.org/dist/v"+v+"/" + vpre + "/node.exe"
url := GetFullNodeUrl("v"+v+"/" + vpre + "/node.exe")
// Check online to see if a 64 bit version exists
res, err := client.Head( url )
_, err := client.Head( url )
if err != nil {
return ""
}
if res.StatusCode == 200 {
return url
} else {
return ""
}
return url;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册