2020-09-17 07:43:45 -07:00
|
|
|
package main
|
|
|
|
|
2021-04-17 04:47:28 -07:00
|
|
|
import "fmt"
|
|
|
|
|
2020-10-01 11:57:02 -07:00
|
|
|
type node struct {
|
2021-04-17 04:47:28 -07:00
|
|
|
language *language
|
|
|
|
packageManagerIcon string
|
2020-09-17 07:43:45 -07:00
|
|
|
}
|
|
|
|
|
2021-04-17 04:47:28 -07:00
|
|
|
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"
|
|
|
|
)
|
|
|
|
|
2020-10-01 11:57:02 -07:00
|
|
|
func (n *node) string() string {
|
2021-04-17 04:47:28 -07:00
|
|
|
version := n.language.string()
|
|
|
|
return fmt.Sprintf("%s%s", version, n.packageManagerIcon)
|
2020-09-17 07:43:45 -07:00
|
|
|
}
|
|
|
|
|
2020-10-01 11:57:02 -07:00
|
|
|
func (n *node) init(props *properties, env environmentInfo) {
|
2020-11-14 11:04:04 -08:00
|
|
|
n.language = &language{
|
2021-02-03 10:11:32 -08:00
|
|
|
env: env,
|
|
|
|
props: props,
|
2021-02-15 11:51:48 -08:00
|
|
|
extensions: []string{"*.js", "*.ts", "package.json", ".nvmrc"},
|
2021-02-03 10:11:32 -08:00
|
|
|
commands: []*cmd{
|
|
|
|
{
|
|
|
|
executable: "node",
|
|
|
|
args: []string{"--version"},
|
|
|
|
regex: `(?:v(?P<version>((?P<major>[0-9]+).(?P<minor>[0-9]+).(?P<patch>[0-9]+))))`,
|
|
|
|
},
|
2021-01-10 03:14:43 -08:00
|
|
|
},
|
2021-02-03 10:11:32 -08:00
|
|
|
versionURLTemplate: "[%[1]s](https://github.com/nodejs/node/blob/master/doc/changelogs/CHANGELOG_V%[2]s.md#%[1]s)",
|
2021-02-06 22:06:24 -08:00
|
|
|
matchesVersionFile: n.matchesVersionFile,
|
2021-04-17 04:47:28 -07:00
|
|
|
loadContext: n.loadContext,
|
2020-11-14 11:04:04 -08:00
|
|
|
}
|
2020-09-17 07:43:45 -07:00
|
|
|
}
|
|
|
|
|
2020-10-01 11:57:02 -07:00
|
|
|
func (n *node) enabled() bool {
|
2020-11-14 11:04:04 -08:00
|
|
|
return n.language.enabled()
|
2020-09-17 07:43:45 -07:00
|
|
|
}
|
2021-02-06 22:06:24 -08:00
|
|
|
|
2021-04-17 04:47:28 -07:00
|
|
|
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")
|
|
|
|
}
|
|
|
|
if n.language.env.hasFiles("package-lock.json") || n.language.env.hasFiles("package.json") {
|
|
|
|
n.packageManagerIcon = n.language.props.getString(NPMIcon, " \uE71E")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-06 22:06:24 -08:00
|
|
|
func (n *node) matchesVersionFile() bool {
|
2021-02-15 11:51:48 -08:00
|
|
|
fileVersion := n.language.env.getFileContent(".nvmrc")
|
|
|
|
if len(fileVersion) == 0 {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return fileVersion == n.language.activeCommand.version.full
|
2021-02-06 22:06:24 -08:00
|
|
|
}
|