mirror of
https://github.com/coreybutler/nvm-windows.git
synced 2026-01-14 07:03:17 +08:00
Merge pull request #162 from fredericosilva/master
list available: show LTS and STABLE
This commit is contained in:
41
src/nvm.go
41
src/nvm.go
@@ -8,7 +8,6 @@ import (
|
||||
"io/ioutil"
|
||||
"regexp"
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
"./nvm/web"
|
||||
"./nvm/arch"
|
||||
@@ -401,29 +400,35 @@ func list(listtype string) {
|
||||
fmt.Println("No installations recognized.")
|
||||
}
|
||||
} else {
|
||||
_, stable, unstable := node.GetAvailable()
|
||||
_, lts, stable, _ := node.GetAvailable()
|
||||
|
||||
releases := 15
|
||||
|
||||
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")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -478,17 +483,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) {
|
||||
|
||||
@@ -6,7 +6,6 @@ import(
|
||||
"regexp"
|
||||
"io/ioutil"
|
||||
"encoding/json"
|
||||
"sort"
|
||||
"../arch"
|
||||
"../file"
|
||||
"../web"
|
||||
@@ -71,7 +70,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 +108,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)
|
||||
|
||||
// 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
|
||||
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)
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
sort.Sort(BySemanticVersion(all))
|
||||
sort.Sort(BySemanticVersion(stable))
|
||||
sort.Sort(BySemanticVersion(unstable))
|
||||
|
||||
return all, stable, unstable
|
||||
return all, lts, stable, npm
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user