Generalize the icon generation

This commit is contained in:
nemunaire 2020-05-11 00:12:08 +02:00
parent 34ce25eb76
commit 1e8d6ad63f
3 changed files with 23 additions and 8 deletions

View File

@ -32,4 +32,5 @@
package main
//go:generate go run generators/gen_database_migration.go
//go:generate go run generators/gen_sources_icon.go
//go:generate go run generators/gen_icon.go sources sources
//go:generate go run generators/gen_icon.go services svcs

View File

@ -45,7 +45,7 @@ const tpl = `// Code generated by go generate. DO NOT EDIT.
// sources:
{{ range $idx, $path := .Sources }}// {{ $path }}
{{ end }}
package sources // import "happydns.org/sources"
package {{ .Package }} // import "happydns.org/{{ .Directory }}"
var Icons = map[string][]byte{
{{ range $file, $content := .Map }} {{printf "%q" $file}}: []byte({{printf "%q" $content}}),
@ -55,19 +55,26 @@ var Icons = map[string][]byte{
var bundleTpl = template.Must(template.New("").Parse(tpl))
type valTpl struct {
Sources []string
Map map[string][]byte
Directory string
Package string
Sources []string
Map map[string][]byte
}
func main() {
srcFiles, err := filepath.Glob("sources/*/*.png")
dir := os.Args[1]
pkg := os.Args[2]
srcFiles, err := filepath.Glob(dir + "/*/*.png")
if err != nil {
panic(err)
}
d := valTpl{
Sources: []string{},
Map: map[string][]byte{},
Directory: dir,
Package: pkg,
Sources: []string{},
Map: map[string][]byte{},
}
for _, srcFile := range srcFiles {
@ -80,7 +87,7 @@ func main() {
d.Map["git.happydns.org/happydns/"+strings.TrimSuffix(srcFile, ".png")] = data
}
f, err := os.Create("sources/icons.go")
f, err := os.Create(dir + "/icons.go")
if err != nil {
panic(err)
}

7
services/icons.go Normal file
View File

@ -0,0 +1,7 @@
// Code generated by go generate. DO NOT EDIT.
// sources:
package svcs // import "happydns.org/services"
var Icons = map[string][]byte{
}