-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
segment_node.go
65 lines (57 loc) · 1.72 KB
/
segment_node.go
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
package main
import "fmt"
type node struct {
language *language
packageManagerIcon string
}
const (
// YarnIcon illustrates Yarn is used
YarnIcon Property = "yarn_icon"
// NPMIcon illustrates NPM is used
NPMIcon Property = "npm_icon"
// DisplayPackageManager shows if NPM or Yarn is used
DisplayPackageManager Property = "display_package_manager"
)
func (n *node) string() string {
version := n.language.string()
return fmt.Sprintf("%s%s", version, n.packageManagerIcon)
}
func (n *node) init(props *properties, env environmentInfo) {
n.language = &language{
env: env,
props: props,
extensions: []string{"*.js", "*.ts", "package.json", ".nvmrc"},
commands: []*cmd{
{
executable: "node",
args: []string{"--version"},
regex: `(?:v(?P<version>((?P<major>[0-9]+).(?P<minor>[0-9]+).(?P<patch>[0-9]+))))`,
},
},
versionURLTemplate: "[%[1]s](https://github.com/nodejs/node/blob/master/doc/changelogs/CHANGELOG_V%[2]s.md#%[1]s)",
matchesVersionFile: n.matchesVersionFile,
loadContext: n.loadContext,
}
}
func (n *node) enabled() bool {
return n.language.enabled()
}
func (n *node) loadContext() {
if !n.language.props.getBool(DisplayPackageManager, false) {
return
}
if n.language.env.hasFiles("yarn.lock") {
n.packageManagerIcon = n.language.props.getString(YarnIcon, " \uF61A")
return
}
if n.language.env.hasFiles("package-lock.json") || n.language.env.hasFiles("package.json") {
n.packageManagerIcon = n.language.props.getString(NPMIcon, " \uE71E")
}
}
func (n *node) matchesVersionFile() bool {
fileVersion := n.language.env.getFileContent(".nvmrc")
if len(fileVersion) == 0 {
return true
}
return fileVersion == n.language.activeCommand.version.full
}