oh-my-posh/src/segment_angular.go

54 lines
1.3 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 {
return a.language.string()
}
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"
angularFilePath := a.language.env.getcwd() + 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{}
content := a.language.env.getFileContent(a.language.env.getcwd() + 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
},
},
versionURLTemplate: "[%s](https://github.com/angular/angular/releases/tag/%s.%s.%s)",
}
}
func (a *angular) enabled() bool {
return a.language.enabled()
}