-
-
Notifications
You must be signed in to change notification settings - Fork 328
/
main.go
53 lines (41 loc) · 1.05 KB
/
main.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
package main
import (
"strings"
"github.com/go-rod/rod/lib/assets"
"github.com/go-rod/rod/lib/utils"
"github.com/ysmood/kit"
)
func main() {
list := kit.JSON(assets.DeviceList)
code := ``
for _, d := range list.Array() {
name := d.Get("device.title").String()
code += kit.S(`
// {{.name}} type
{{.name}} DeviceType = "{{.title}}"
`, "name", normalizeName(name), "title", name)
}
code = kit.S(`// generated by running "go generate" on project root
package devices
const (
{{.code}}
)
`, "code", code)
path := "./lib/devices/types.go"
utils.E(kit.OutputFile(path, code, nil))
kit.Exec("gofmt", "-s", "-w", path).MustDo()
kit.Exec("goimports", "-w", path).MustDo()
kit.Exec("misspell", "-w", "-q", path).MustDo()
}
func normalizeName(name string) string {
name = strings.ReplaceAll(name, "/", "or")
list := []string{}
for _, s := range strings.Split(name, " ") {
if len(s) > 1 {
list = append(list, strings.ToUpper(s[0:1])+s[1:])
} else {
list = append(list, strings.ToUpper(s))
}
}
return strings.Join(list, "")
}