2022-09-14 09:15:09 -05:00
|
|
|
package codegen
|
|
|
|
|
|
|
|
import (
|
|
|
|
"embed"
|
2023-04-27 15:32:38 -05:00
|
|
|
"strings"
|
2022-09-14 09:15:09 -05:00
|
|
|
"text/template"
|
|
|
|
"time"
|
2022-11-22 08:00:29 -06:00
|
|
|
|
|
|
|
"github.com/grafana/codejen"
|
2022-09-14 09:15:09 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// All the parsed templates in the tmpl subdirectory
|
|
|
|
var tmpls *template.Template
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
base := template.New("codegen").Funcs(template.FuncMap{
|
2023-04-27 15:32:38 -05:00
|
|
|
"now": time.Now,
|
|
|
|
"ToLower": strings.ToLower,
|
2022-09-14 09:15:09 -05:00
|
|
|
})
|
|
|
|
tmpls = template.Must(base.ParseFS(tmplFS, "tmpl/*.tmpl"))
|
|
|
|
}
|
|
|
|
|
|
|
|
//go:embed tmpl/*.tmpl
|
|
|
|
var tmplFS embed.FS
|
|
|
|
|
|
|
|
// The following group of types, beginning with tvars_*, all contain the set
|
|
|
|
// of variables expected by the corresponding named template file under tmpl/
|
|
|
|
type (
|
2022-11-22 08:00:29 -06:00
|
|
|
tvars_gen_header struct {
|
|
|
|
MainGenerator string
|
|
|
|
Using []codejen.NamedJenny
|
|
|
|
From string
|
2023-02-01 11:08:26 -06:00
|
|
|
Leader string
|
2022-11-22 08:00:29 -06:00
|
|
|
}
|
2024-03-13 11:05:21 -05:00
|
|
|
|
2023-04-27 15:32:38 -05:00
|
|
|
tvars_resource struct {
|
2024-02-26 03:18:19 -06:00
|
|
|
PackageName string
|
|
|
|
KindName string
|
|
|
|
Version string
|
|
|
|
}
|
|
|
|
|
|
|
|
tvars_metadata struct {
|
|
|
|
PackageName string
|
|
|
|
}
|
|
|
|
|
|
|
|
tvars_status struct {
|
|
|
|
PackageName string
|
2023-04-27 15:32:38 -05:00
|
|
|
}
|
2024-03-13 11:05:21 -05:00
|
|
|
|
|
|
|
tvars_registry struct {
|
|
|
|
Schemas []Schema
|
|
|
|
}
|
|
|
|
|
|
|
|
Schema struct {
|
|
|
|
Name string
|
|
|
|
FilePath string
|
|
|
|
}
|
2022-09-14 09:15:09 -05:00
|
|
|
)
|