Add GSP project manifest and design layout
This commit is contained in:
58
toolkit/internal/gsp/manifest.go
Normal file
58
toolkit/internal/gsp/manifest.go
Normal file
@@ -0,0 +1,58 @@
|
||||
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"`
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user