oh-my-posh/src/segment_angular.go

55 lines
1.5 KiB
Go
Raw Normal View History

2021-10-13 00:05:29 -07:00
package main
import (
"encoding/json"
"fmt"
)
2021-10-13 00:05:29 -07:00
type angular struct {
2021-12-03 11:19:57 -08:00
language
2021-10-13 00:05:29 -07:00
}
func (a *angular) string() string {
segmentTemplate := a.language.props.getString(SegmentTemplate, "{{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }}")
return a.language.string(segmentTemplate, a)
2021-10-13 00:05:29 -07:00
}
2022-01-01 11:09:52 -08:00
func (a *angular) init(props Properties, env Environment) {
2021-12-03 11:19:57 -08:00
a.language = language{
2021-10-13 00:05:29 -07:00
env: env,
props: props,
extensions: []string{"angular.json"},
commands: []*cmd{
{
regex: `(?:(?P<version>((?P<major>[0-9]+).(?P<minor>[0-9]+).(?P<patch>[0-9]+))))`,
getVersion: func() (string, error) {
const fileName string = "package.json"
const fileFolder string = "/node_modules/@angular/core"
2022-01-20 04:35:46 -08:00
angularFilePath := a.language.env.pwd() + fileFolder
if !a.language.env.hasFilesInDir(angularFilePath, fileName) {
return "", fmt.Errorf("%s not found in %s", fileName, angularFilePath)
}
// parse file
objmap := map[string]json.RawMessage{}
2022-01-20 04:35:46 -08:00
content := a.language.env.getFileContent(a.language.env.pwd() + fileFolder + "/" + fileName)
err := json.Unmarshal([]byte(content), &objmap)
if err != nil {
return "", err
}
var str string
err = json.Unmarshal(objmap["version"], &str)
if err != nil {
return "", err
}
return str, nil
},
2021-10-13 00:05:29 -07:00
},
},
2022-01-23 09:48:55 -08:00
versionURLTemplate: "https://github.com/angular/angular/releases/tag/{{.Full}}",
2021-10-13 00:05:29 -07:00
}
}
func (a *angular) enabled() bool {
return a.language.enabled()
}