75 lines
2.1 KiB
Go
75 lines
2.1 KiB
Go
package gsp
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
type Manifest struct {
|
|
GSPVersion string `json:"gspVersion,omitempty" yaml:"gspVersion"`
|
|
ToolkitVersion string `json:"toolkitVersion,omitempty" yaml:"toolkitVersion"`
|
|
Project string `json:"project,omitempty" yaml:"project"`
|
|
Entry []string `json:"entry,omitempty" yaml:"entry"`
|
|
Scan []string `json:"scan,omitempty" yaml:"scan"`
|
|
StageRules map[string]StageRule `json:"stageRules,omitempty" yaml:"stageRules"`
|
|
Types []string `json:"types,omitempty" yaml:"types"`
|
|
Output string `json:"output,omitempty" yaml:"output"`
|
|
CustomFieldPolicy string `json:"customFieldPolicy,omitempty" yaml:"customFieldPolicy"`
|
|
FieldRegistry string `json:"fieldRegistry,omitempty" yaml:"fieldRegistry"`
|
|
File string `json:"file,omitempty" yaml:"-"`
|
|
}
|
|
|
|
type StageRule struct {
|
|
MinResolution string `json:"minResolution,omitempty" yaml:"minResolution"`
|
|
}
|
|
|
|
func loadManifest(root string) (*Manifest, error) {
|
|
path := filepath.Join(root, "gsp.manifest")
|
|
data, err := os.ReadFile(path)
|
|
if err != nil {
|
|
if os.IsNotExist(err) {
|
|
return nil, nil
|
|
}
|
|
return nil, err
|
|
}
|
|
var manifest Manifest
|
|
if err := yaml.Unmarshal(data, &manifest); err != nil {
|
|
return nil, err
|
|
}
|
|
manifest.File = relPath(root, path)
|
|
return &manifest, nil
|
|
}
|
|
|
|
func (m *Manifest) scanEntries() []string {
|
|
if m == nil || len(m.Scan) == 0 {
|
|
return []string{"design"}
|
|
}
|
|
return m.Scan
|
|
}
|
|
|
|
func (m *Manifest) minResolution(stage string) (string, bool) {
|
|
if m != nil && m.StageRules != nil {
|
|
if rule, ok := m.StageRules[stage]; ok && rule.MinResolution != "" {
|
|
return rule.MinResolution, true
|
|
}
|
|
}
|
|
value, ok := defaultStageRules[stage]
|
|
return value, ok
|
|
}
|
|
|
|
func (m *Manifest) customFieldPolicy() string {
|
|
if m == nil || m.CustomFieldPolicy == "" {
|
|
return "strict"
|
|
}
|
|
return m.CustomFieldPolicy
|
|
}
|
|
|
|
func (m *Manifest) fieldRegistryPath() string {
|
|
if m == nil || m.FieldRegistry == "" {
|
|
return "gsp.fields"
|
|
}
|
|
return m.FieldRegistry
|
|
}
|