|
6 | 6 | "regexp"
|
7 | 7 | "io/ioutil"
|
8 | 8 | "encoding/json"
|
9 |
| - "sort" |
10 | 9 | "../arch"
|
11 | 10 | "../file"
|
12 | 11 | "../web"
|
@@ -70,7 +69,7 @@ func IsVersionInstalled(root string, version string, cpu string) bool {
|
70 | 69 |
|
71 | 70 | func IsVersionAvailable(v string) bool {
|
72 | 71 | // Check the service to make sure the version is available
|
73 |
| - avail, _, _ := GetAvailable() |
| 72 | + avail, _, _, _ := GetAvailable() |
74 | 73 |
|
75 | 74 | for _, b := range avail {
|
76 | 75 | if b == v {
|
@@ -108,65 +107,37 @@ func (s BySemanticVersion) Less(i, j int) bool {
|
108 | 107 | return v1.GTE(v2)
|
109 | 108 | }
|
110 | 109 |
|
111 |
| -func GetAvailabeVersions() (map[string]interface{}, map[string]interface{},map[string]interface{}){ |
112 |
| - // Check the service to make sure the version is available |
113 |
| - // modified by lzm at 4-7-2016, to chinese guys github maybe blocked at anytime.why not use the http://nodejs.org/dist/index.json? |
114 |
| - //text := web.GetRemoteTextFile("https://raw.githubusercontent.com/coreybutler/nodedistro/master/nodeversions.json") |
| 110 | +func GetAvailable() ([]string, []string, []string, map[string]string) { |
| 111 | + all := make([]string,0) |
| 112 | + lts := make([]string,0) |
| 113 | + stable := make([]string,0) |
| 114 | + npm := make(map[string]string) |
115 | 115 | url := web.GetFullNodeUrl("index.json")
|
| 116 | + // Check the service to make sure the version is available |
116 | 117 | text := web.GetRemoteTextFile(url)
|
| 118 | + |
117 | 119 | // Parse
|
118 |
| - var data interface{} |
| 120 | + var data = make([]map[string]interface{}, 0) |
119 | 121 | json.Unmarshal([]byte(text), &data);
|
120 | 122 |
|
121 |
| - //body := data.(map[string]interface{}) |
122 |
| - //_all := body["all"] |
123 |
| - //_stable := body["stable"] |
124 |
| - //_unstable := body["unstable"] |
125 |
| - //allkeys := _all.(map[string]interface{}) |
126 |
| - //stablekeys := _stable.(map[string]interface{}) |
127 |
| - //unstablekeys := _unstable.(map[string]interface{}) |
128 |
| - |
129 |
| - body := data.([]interface{}) |
130 |
| - allkeys := make(map[string]interface{}) |
131 |
| - stablekeys := make(map[string]interface{}) |
132 |
| - unstablekeys := make(map[string]interface{}) |
133 |
| - for _, temp := range body { |
134 |
| - item := temp.(map[string]interface{}) |
135 |
| - key := strings.TrimLeft(item["version"].(string), "v") |
136 |
| - value := item["npm"] |
137 |
| - if value != nil{ |
138 |
| - allkeys[key] = value.(string) |
139 |
| - version,_ := semver.New(key) |
140 |
| - if (version.Major!=0 && version.Major % 2 ==0) || version.Minor % 2==0{ |
141 |
| - stablekeys[key] = value.(string) |
142 |
| - } else{ |
143 |
| - unstablekeys[key] = value.(string) |
144 |
| - } |
145 |
| - } |
146 |
| - } |
147 |
| - return allkeys, stablekeys, unstablekeys |
148 |
| -} |
| 123 | + for _,element := range data { |
149 | 124 |
|
150 |
| -func GetAvailable() ([]string, []string, []string) { |
151 |
| - all := make([]string,0) |
152 |
| - stable := make([]string,0) |
153 |
| - unstable := make([]string,0) |
| 125 | + var version = element["version"].(string)[1:] |
| 126 | + all = append(all, version) |
154 | 127 |
|
155 |
| - allkeys, stablekeys, unstablekeys := GetAvailabeVersions() |
| 128 | + if val, ok := element["npm"].(string); ok { |
| 129 | + npm[version] = val |
| 130 | + } |
156 | 131 |
|
157 |
| - for nodev, _ := range allkeys { |
158 |
| - all = append(all,nodev) |
159 |
| - } |
160 |
| - for nodev, _ := range stablekeys { |
161 |
| - stable = append(stable,nodev) |
162 |
| - } |
163 |
| - for nodev, _ := range unstablekeys { |
164 |
| - unstable = append(unstable,nodev) |
| 132 | + switch v := element["lts"].(type) { |
| 133 | + case bool: |
| 134 | + if v == false { |
| 135 | + stable = append(stable, version) |
| 136 | + } |
| 137 | + case string: |
| 138 | + lts = append(lts, version) |
| 139 | + } |
165 | 140 | }
|
166 | 141 |
|
167 |
| - sort.Sort(BySemanticVersion(all)) |
168 |
| - sort.Sort(BySemanticVersion(stable)) |
169 |
| - sort.Sort(BySemanticVersion(unstable)) |
170 |
| - |
171 |
| - return all, stable, unstable |
| 142 | + return all, lts, stable, npm |
172 | 143 | }
|
0 commit comments