-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode_version.go
More file actions
83 lines (63 loc) · 1.7 KB
/
node_version.go
File metadata and controls
83 lines (63 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package data
import (
"errors"
"strconv"
"github.com/Masterminds/semver/v3"
)
type Lts interface{}
type NodeVersion struct {
Version string `json:"version"`
Date string `json:"date"`
Files []string `json:"files"`
Npm string `json:"npm,omitempty"`
V8 string `json:"v8"`
Uv string `json:"uv,omitempty"`
Zlib string `json:"zlib,omitempty"`
Openssl string `json:"openssl,omitempty"`
Modules string `json:"modules,omitempty"`
Lts Lts `json:"lts"`
Security bool `json:"security"`
}
func (n NodeVersion) IsLts() bool {
switch n.Lts.(type) {
case bool:
return false
default:
return true
}
}
type NodeVersions []NodeVersion
func (n NodeVersions) GetAll() []string {
var allVersions []string
for _, version := range n {
allVersions = append(allVersions, version.Version)
}
return allVersions
}
func (n NodeVersions) GetLatest() string {
return n[0].Version
}
func (n NodeVersions) GetLatestOf(majorVersionNumber string) (*string, error) {
for _, version := range n {
versionWithoutV := version.Version[1:len(version.Version)]
nodeVersion, _ := semver.NewVersion(versionWithoutV)
majorVersionAsInt, _ := strconv.ParseUint(majorVersionNumber, 10, 64)
if majorVersionAsInt == nodeVersion.Major() {
return &version.Version, nil
}
}
return nil, errors.New("no version found for major version " + majorVersionNumber)
}
func (n NodeVersions) GetCurrentLts() string {
allLts := n.GetAllLts()
return allLts[0]
}
func (n NodeVersions) GetAllLts() []string {
var ltsVersions []string = []string{}
for _, version := range n {
if version.IsLts() {
ltsVersions = append(ltsVersions, version.Version)
}
}
return ltsVersions
}