提交 d786051d 编写于 作者: F Frederico Silva

list available: show LTS and STABLE

load versions from https://nodejs.org/download/release/index.json
上级 6edd36b4
...@@ -8,7 +8,6 @@ import ( ...@@ -8,7 +8,6 @@ import (
"io/ioutil" "io/ioutil"
"regexp" "regexp"
"bytes" "bytes"
"encoding/json"
"strconv" "strconv"
"./nvm/web" "./nvm/web"
"./nvm/arch" "./nvm/arch"
...@@ -401,29 +400,35 @@ func list(listtype string) { ...@@ -401,29 +400,35 @@ func list(listtype string) {
fmt.Println("No installations recognized.") fmt.Println("No installations recognized.")
} }
} else { } else {
_, stable, unstable := node.GetAvailable() _, lts, stable, _ := node.GetAvailable()
releases := 15 releases := 15
fmt.Println("\nShowing the "+strconv.Itoa(releases)+" latest available releases.\n") fmt.Println("\nShowing the "+strconv.Itoa(releases)+" latest available releases.\n")
fmt.Println(" STABLE | UNSTABLE ") fmt.Println(" LTS | STABLE ")
fmt.Println(" ---------------------------") fmt.Println(" ---------------------------")
for i := 0; i < releases; i++ { for i := 0; i < releases; i++ {
str := "v"+stable[i] str := " "
for ii := 10-len(str); ii > 0; ii-- { if len(lts) > i {
str = " "+str str = "v"+lts[i]
for ii := 10-len(str); ii > 0; ii-- {
str = " "+str
}
} }
str = str+" | "
str2 := "v"+unstable[i] str2 := ""
for ii := 10-len(str2); ii > 0; ii-- { if len(stable) > i {
str2 = " "+str2 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")
} }
} }
...@@ -478,17 +483,9 @@ func help() { ...@@ -478,17 +483,9 @@ func help() {
// Given a node.js version, returns the associated npm version // Given a node.js version, returns the associated npm version
func getNpmVersion(nodeversion string) string { func getNpmVersion(nodeversion string) string {
// Get raw text _, _, _, npm := node.GetAvailable()
text := web.GetRemoteTextFile("https://raw.githubusercontent.com/coreybutler/nodedistro/master/nodeversions.json")
// 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) { func updateRootDir(path string) {
......
...@@ -6,7 +6,6 @@ import( ...@@ -6,7 +6,6 @@ import(
"regexp" "regexp"
"io/ioutil" "io/ioutil"
"encoding/json" "encoding/json"
"sort"
"../arch" "../arch"
"../file" "../file"
"../web" "../web"
...@@ -71,7 +70,7 @@ func IsVersionInstalled(root string, version string, cpu string) bool { ...@@ -71,7 +70,7 @@ func IsVersionInstalled(root string, version string, cpu string) bool {
func IsVersionAvailable(v string) bool { func IsVersionAvailable(v string) bool {
// Check the service to make sure the version is available // Check the service to make sure the version is available
avail, _, _ := GetAvailable() avail, _, _, _ := GetAvailable()
for _, b := range avail { for _, b := range avail {
if b == v { if b == v {
...@@ -109,38 +108,37 @@ func (s BySemanticVersion) Less(i, j int) bool { ...@@ -109,38 +108,37 @@ func (s BySemanticVersion) Less(i, j int) bool {
return v1.GTE(v2) return v1.GTE(v2)
} }
func GetAvailable() ([]string, []string, []string) { func GetAvailable() ([]string, []string, []string, map[string]string) {
all := make([]string,0) all := make([]string,0)
lts := make([]string,0)
stable := make([]string,0) stable := make([]string,0)
unstable := make([]string,0) npm := make(map[string]string)
// Check the service to make sure the version is available // 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("https://nodejs.org/download/release/index.json")
// Parse // Parse
var data interface{} var data = make([]map[string]interface{}, 0)
json.Unmarshal([]byte(text), &data); 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)
}
sort.Sort(BySemanticVersion(all)) for _,element := range data {
sort.Sort(BySemanticVersion(stable))
sort.Sort(BySemanticVersion(unstable)) var version = element["version"].(string)[1:]
all = append(all, version)
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
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册