-
Notifications
You must be signed in to change notification settings - Fork 4
/
template.go
84 lines (73 loc) · 2.32 KB
/
template.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package project
import (
"fmt"
"strings"
"projectforge.dev/projectforge/app/lib/theme"
"projectforge.dev/projectforge/app/project/export/model"
"projectforge.dev/projectforge/app/util"
)
type TemplateContext struct {
Key string `json:"key"`
Name string `json:"name,omitempty"`
Exec string `json:"exec,omitempty"`
Version string `json:"version"`
Package string `json:"package,omitempty"`
Args string `json:"args,omitempty"`
Port int `json:"port,omitempty"`
ConfigVars util.KeyTypeDescs `json:"configVars,omitempty"`
PortOffsets map[string]int `json:"portOffsets,omitempty"`
Ignore []string `json:"ignore,omitempty"`
IgnoreGrep string `json:"ignoreGrep,omitempty"`
Modules []string `json:"modules,omitempty"`
Tags []string `json:"tags,omitempty"`
ExportArgs *model.Args `json:"exportArgs,omitempty"`
Config util.ValueMap `json:"config,omitempty"`
Info *Info `json:"info,omitempty"`
Build *Build `json:"build,omitempty"`
Theme *theme.Theme `json:"theme,omitempty"`
}
func (p *Project) ToTemplateContext(configVars util.KeyTypeDescs, portOffsets map[string]int) *TemplateContext {
i := p.Info
if i == nil {
i = &Info{}
}
b := p.Build
if b == nil {
b = &Build{}
}
t := p.Theme
if t == nil {
t = theme.ThemeDefault
}
var ignoreGrep string
for _, ig := range p.Ignore {
if strings.HasPrefix(ig, "^") {
ig = "\\\\./" + strings.TrimPrefix(ig, "^")
}
ignoreGrep += fmt.Sprintf(" | grep -v %s", ig)
}
cv := append(util.KeyTypeDescs{}, configVars...)
if p.Info != nil && len(p.Info.ConfigVars) > 0 {
cv = append(cv, p.Info.ConfigVars...)
}
ret := &TemplateContext{
Key: p.Key, Name: p.Name, Exec: p.Executable(), Version: p.Version,
Package: p.Package, Args: p.Args, Port: p.Port, ConfigVars: cv, PortOffsets: portOffsets,
Ignore: p.Ignore, IgnoreGrep: ignoreGrep, Modules: p.Modules, Tags: p.Tags,
ExportArgs: p.ExportArgs, Config: p.Config, Info: i, Build: b, Theme: t,
}
if ret.Name == "" {
ret.Name = ret.Key
}
if ret.Exec == "" {
ret.Exec = ret.Key
}
if ret.Args == "" {
if p.HasModule("marketing") {
ret.Args = " -v --addr=0.0.0.0 all"
} else {
ret.Args = " -v --addr=0.0.0.0 server"
}
}
return ret
}