mirror of
https://github.com/grafana/grafana.git
synced 2024-11-23 01:16:31 -06:00
e2ff875976
* Split all named types out into defs, etc. * Use latest cuetsy, refactor generators accordingly * Return AST type from plugin TS generator * Near-complete checkin of TS veneer code generator * First full completed pass * Improve the attribute name * Defer use of the dashboard veneer type to follow-up * Remove dummy index, prettier on veneer * Fix merge errors in gen.go * Add match field to SpecialValueMap * Fix backend lint errors
73 lines
1.6 KiB
Go
73 lines
1.6 KiB
Go
package codegen
|
|
|
|
import (
|
|
"bytes"
|
|
"embed"
|
|
"text/template"
|
|
"time"
|
|
)
|
|
|
|
// All the parsed templates in the tmpl subdirectory
|
|
var tmpls *template.Template
|
|
|
|
func init() {
|
|
base := template.New("codegen").Funcs(template.FuncMap{
|
|
"now": time.Now,
|
|
})
|
|
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 (
|
|
tvars_autogen_header struct {
|
|
GeneratorPath string
|
|
LineagePath string
|
|
LineageCUEPath string
|
|
GenLicense bool
|
|
}
|
|
tvars_coremodel_registry struct {
|
|
Header tvars_autogen_header
|
|
Coremodels []tplVars
|
|
}
|
|
tvars_coremodel_imports struct {
|
|
PackageName string
|
|
}
|
|
tvars_plugin_lineage_binding struct {
|
|
SlotName string
|
|
LatestMajv, LatestMinv uint
|
|
}
|
|
tvars_plugin_lineage_file struct {
|
|
PackageName string
|
|
PluginID string
|
|
PluginType string
|
|
HasModels bool
|
|
RootCUE bool
|
|
SlotImpls []tvars_plugin_lineage_binding
|
|
Header tvars_autogen_header
|
|
}
|
|
tvars_plugin_registry struct {
|
|
Header tvars_autogen_header
|
|
Plugins []struct {
|
|
PkgName string
|
|
Path string
|
|
ImportPath string
|
|
NoAlias bool
|
|
}
|
|
}
|
|
)
|
|
|
|
type HeaderVars = tvars_autogen_header
|
|
|
|
// GenGrafanaHeader creates standard header elements for generated Grafana files.
|
|
func GenGrafanaHeader(vars HeaderVars) string {
|
|
buf := new(bytes.Buffer)
|
|
if err := tmpls.Lookup("autogen_header.tmpl").Execute(buf, vars); err != nil {
|
|
panic(err)
|
|
}
|
|
return buf.String()
|
|
}
|