-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcontext.go
75 lines (60 loc) · 1.27 KB
/
context.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
package main
import (
"bytes"
"html/template"
"time"
)
// reference
// https://github.com/Chaser324/unity-build/wiki/Parameter-Details#basic-settings
type OutputContext struct {
ConfigName string
Revision string
now time.Time
// android/ios
PackageName string
VersionName string
VersionCode int
Platform string
}
func NewOutputContext(c *Config, t time.Time) OutputContext {
return OutputContext{
ConfigName: c.FileName,
Revision: c.Revision,
now: t,
PackageName: c.Identification.PackageName,
VersionName: c.Identification.VersionName,
VersionCode: c.Identification.VersionCode,
Platform: c.Build.Target,
}
}
func (c *OutputContext) ShortRevision() string {
return c.Revision[:7]
}
// yyyy
func (c *OutputContext) Year() string {
return c.now.Format("2006")
}
// MM
func (c *OutputContext) Month() string {
return c.now.Format("01")
}
// dd
func (c *OutputContext) Day() string {
return c.now.Format("02")
}
// hhmmss
func (c *OutputContext) Time() string {
return c.now.Format("150405")
}
func (c *OutputContext) MakeStr(name, text string) string {
tmpl, err := template.New(name).Parse(text)
if err != nil {
panic(err)
}
w := new(bytes.Buffer)
err = tmpl.Execute(w, c)
if err != nil {
panic(err)
}
return w.String()
}