提交 09da8d90 编写于 作者: C Corey Butler

Merge pull request #94 from sullivanpt/develop

Fixed for node v4
#define MyAppName "NVM for Windows" #define MyAppName "NVM for Windows"
#define MyAppShortName "nvm" #define MyAppShortName "nvm"
#define MyAppLCShortName "nvm" #define MyAppLCShortName "nvm"
#define MyAppVersion "1.0.6" #define MyAppVersion "1.1.0"
#define MyAppPublisher "Ecor Ventures, LLC" #define MyAppPublisher "Ecor Ventures, LLC"
#define MyAppURL "http://github.com/coreybutler/nvm" #define MyAppURL "http://github.com/coreybutler/nvm"
#define MyAppExeName "nvm.exe" #define MyAppExeName "nvm.exe"
......
...@@ -18,7 +18,7 @@ import ( ...@@ -18,7 +18,7 @@ import (
) )
const ( const (
NvmVersion = "1.0.6" NvmVersion = "1.1.0"
) )
type Environment struct { type Environment struct {
...@@ -120,11 +120,11 @@ func update() { ...@@ -120,11 +120,11 @@ func update() {
} }
func CheckVersionExceedsLatest(version string) bool{ func CheckVersionExceedsLatest(version string) bool{
content := web.GetRemoteTextFile("http://nodejs.org/dist/latest/SHASUMS.txt") content := web.GetRemoteTextFile("http://nodejs.org/dist/latest/SHASUMS256.txt")
re := regexp.MustCompile("node-v(.+)+msi") re := regexp.MustCompile("node-v(.+)+msi")
reg := regexp.MustCompile("node-v|-x.+") reg := regexp.MustCompile("node-v|-x.+")
latest := reg.ReplaceAllString(re.FindString(content),"") latest := reg.ReplaceAllString(re.FindString(content),"")
if version <= latest { if version <= latest {
return false return false
} else { } else {
...@@ -155,6 +155,14 @@ func install(version string, cpuarch string) { ...@@ -155,6 +155,14 @@ func install(version string, cpuarch string) {
cpuarch = arch.Validate(cpuarch) cpuarch = arch.Validate(cpuarch)
} }
// If user specifies "latest" version, find out what version is
if version == "latest" {
content := web.GetRemoteTextFile("http://nodejs.org/dist/latest/SHASUMS256.txt")
re := regexp.MustCompile("node-v(.+)+msi")
reg := regexp.MustCompile("node-v|-x.+")
version = reg.ReplaceAllString(re.FindString(content),"")
}
if CheckVersionExceedsLatest(version) { if CheckVersionExceedsLatest(version) {
fmt.Println("Node.js v"+version+" is not yet released or available.") fmt.Println("Node.js v"+version+" is not yet released or available.")
return return
...@@ -165,14 +173,6 @@ func install(version string, cpuarch string) { ...@@ -165,14 +173,6 @@ func install(version string, cpuarch string) {
return return
} }
// If user specifies "latest" version, find out what version is
if version == "latest" {
content := web.GetRemoteTextFile("http://nodejs.org/dist/latest/SHASUMS.txt")
re := regexp.MustCompile("node-v(.+)+msi")
reg := regexp.MustCompile("node-v|-x.+")
version = reg.ReplaceAllString(re.FindString(content),"")
}
// Check to see if the version is already installed // Check to see if the version is already installed
if !node.IsVersionInstalled(env.root,version,cpuarch) { if !node.IsVersionInstalled(env.root,version,cpuarch) {
......
...@@ -25,17 +25,21 @@ func GetCurrentVersion() (string, string) { ...@@ -25,17 +25,21 @@ func GetCurrentVersion() (string, string) {
cmd := exec.Command("node","-p","console.log(process.execPath)") cmd := exec.Command("node","-p","console.log(process.execPath)")
str, _ := cmd.Output() str, _ := cmd.Output()
file := strings.Trim(regexp.MustCompile("undefined").ReplaceAllString(string(str),"")," \n\r") file := strings.Trim(regexp.MustCompile("undefined").ReplaceAllString(string(str),"")," \n\r")
bit := arch.Bit(file) bit := arch.Bit(file)
if (bit == "?"){ if (bit == "?"){
cmd := exec.Command("node", "-e", "console.log(process.arch)" ) cmd := exec.Command("node", "-e", "console.log(process.arch)" )
str, err := cmd.Output() str, err := cmd.Output()
if (string(str) == "x64") { if (err == nil) {
bit := "64" if (string(str) == "x64") {
} else { bit = "64"
bit := "32" } else {
} bit = "32"
} }
return v, bit } else {
return v, "Unknown"
}
}
return v, bit
} }
return "Unknown","" return "Unknown",""
} }
......
...@@ -59,26 +59,42 @@ func GetNodeJS(root string, v string, a string) bool { ...@@ -59,26 +59,42 @@ func GetNodeJS(root string, v string, a string) bool {
a = arch.Validate(a) a = arch.Validate(a)
url := "" vpre := ""
vers := strings.Fields(strings.Replace(v,"."," ",-1))
main, _ := strconv.ParseInt(vers[0],0,0)
if a == "32" { if a == "32" {
url = "http://nodejs.org/dist/v"+v+"/node.exe" if main > 0 {
} else { vpre = "win-x86/"
if !IsNode64bitAvailable(v) { } else {
fmt.Println("Node.js v"+v+" is only available in 32-bit.") vpre = ""
return false }
} else if a == "64" {
if main > 0 {
vpre = "win-x64/"
} else {
vpre = "x64/"
} }
url = "http://nodejs.org/dist/v"+v+"/x64/node.exe"
} }
fileName := root+"\\v"+v+"\\node"+a+".exe"
url := getNodeUrl ( v, vpre );
fmt.Printf("Downloading node.js version "+v+" ("+a+"-bit)... ") if url == "" {
//No url should mean this version/arch isn't available
if Download(url,fileName) { fmt.Println("Node.js v"+v+" " + a + "bit isn't available right now.")
fmt.Printf("Complete\n")
return true
} else { } else {
return false fileName := root+"\\v"+v+"\\node"+a+".exe"
fmt.Printf("Downloading node.js version "+v+" ("+a+"-bit)... ")
if Download(url,fileName) {
fmt.Printf("Complete\n")
return true
} else {
return false
}
} }
return false
} }
...@@ -139,10 +155,20 @@ func IsNode64bitAvailable(v string) bool { ...@@ -139,10 +155,20 @@ func IsNode64bitAvailable(v string) bool {
return false return false
} }
// TODO: fixme. Assume a 64 bit version exists
return true
}
func getNodeUrl (v string, vpre string) string {
url := "http://nodejs.org/dist/v"+v+"/" + vpre + "/node.exe"
// Check online to see if a 64 bit version exists // Check online to see if a 64 bit version exists
res, err := client.Head("http://nodejs.org/dist/v"+v+"/x64/node.exe") res, err := client.Head( url )
if err != nil { if err != nil {
return false return ""
}
if res.StatusCode == 200 {
return url
} else {
return ""
} }
return res.StatusCode == 200
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册