|
6 | 6 | "regexp"
|
7 | 7 | "io/ioutil"
|
8 | 8 | "encoding/json"
|
9 |
| - "sort" |
10 | 9 | "../arch"
|
11 | 10 | "../file"
|
12 | 11 | "../web"
|
@@ -71,7 +70,7 @@ func IsVersionInstalled(root string, version string, cpu string) bool {
|
71 | 70 |
|
72 | 71 | func IsVersionAvailable(v string) bool {
|
73 | 72 | // Check the service to make sure the version is available
|
74 |
| - avail, _, _ := GetAvailable() |
| 73 | + avail, _, _, _ := GetAvailable() |
75 | 74 |
|
76 | 75 | for _, b := range avail {
|
77 | 76 | if b == v {
|
@@ -109,38 +108,37 @@ func (s BySemanticVersion) Less(i, j int) bool {
|
109 | 108 | return v1.GTE(v2)
|
110 | 109 | }
|
111 | 110 |
|
112 |
| -func GetAvailable() ([]string, []string, []string) { |
| 111 | +func GetAvailable() ([]string, []string, []string, map[string]string) { |
113 | 112 | all := make([]string,0)
|
| 113 | + lts := make([]string,0) |
114 | 114 | stable := make([]string,0)
|
115 |
| - unstable := make([]string,0) |
| 115 | + npm := make(map[string]string) |
116 | 116 |
|
117 | 117 | // Check the service to make sure the version is available
|
118 |
| - text := web.GetRemoteTextFile("https://raw.githubusercontent.com/coreybutler/nodedistro/master/nodeversions.json") |
| 118 | + text := web.GetRemoteTextFile("https://nodejs.org/download/release/index.json") |
119 | 119 |
|
120 | 120 | // Parse
|
121 |
| - var data interface{} |
| 121 | + var data = make([]map[string]interface{}, 0) |
122 | 122 | json.Unmarshal([]byte(text), &data);
|
123 |
| - body := data.(map[string]interface{}) |
124 |
| - _all := body["all"] |
125 |
| - _stable := body["stable"] |
126 |
| - _unstable := body["unstable"] |
127 |
| - allkeys := _all.(map[string]interface{}) |
128 |
| - stablekeys := _stable.(map[string]interface{}) |
129 |
| - unstablekeys := _unstable.(map[string]interface{}) |
130 |
| - |
131 |
| - for nodev, _ := range allkeys { |
132 |
| - all = append(all,nodev) |
133 |
| - } |
134 |
| - for nodev, _ := range stablekeys { |
135 |
| - stable = append(stable,nodev) |
136 |
| - } |
137 |
| - for nodev, _ := range unstablekeys { |
138 |
| - unstable = append(unstable,nodev) |
139 |
| - } |
140 | 123 |
|
141 |
| - sort.Sort(BySemanticVersion(all)) |
142 |
| - sort.Sort(BySemanticVersion(stable)) |
143 |
| - sort.Sort(BySemanticVersion(unstable)) |
| 124 | + for _,element := range data { |
| 125 | + |
| 126 | + var version = element["version"].(string)[1:] |
| 127 | + all = append(all, version) |
| 128 | + |
| 129 | + if val, ok := element["npm"].(string); ok { |
| 130 | + npm[version] = val |
| 131 | + } |
| 132 | + |
| 133 | + switch v := element["lts"].(type) { |
| 134 | + case bool: |
| 135 | + if v == false { |
| 136 | + stable = append(stable, version) |
| 137 | + } |
| 138 | + case string: |
| 139 | + lts = append(lts, version) |
| 140 | + } |
| 141 | + } |
144 | 142 |
|
145 |
| - return all, stable, unstable |
| 143 | + return all, lts, stable, npm |
146 | 144 | }
|
0 commit comments