mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Kindsys: Generate plugin Go types under a kinds/ dir (#61899)
Kindsys: Generate plugin Go types under kinds/
This commit is contained in:
parent
40feee0d17
commit
f62f3cb0e9
@ -5,20 +5,24 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
copenapi "cuelang.org/go/encoding/openapi"
|
||||||
|
"github.com/dave/dst/dstutil"
|
||||||
"github.com/grafana/codejen"
|
"github.com/grafana/codejen"
|
||||||
|
corecodegen "github.com/grafana/grafana/pkg/codegen"
|
||||||
"github.com/grafana/grafana/pkg/plugins/pfs"
|
"github.com/grafana/grafana/pkg/plugins/pfs"
|
||||||
|
"github.com/grafana/thema/encoding/gocode"
|
||||||
|
"github.com/grafana/thema/encoding/openapi"
|
||||||
)
|
)
|
||||||
|
|
||||||
func PluginGoTypesJenny(root string, inner codejen.OneToOne[*pfs.PluginDecl]) codejen.OneToOne[*pfs.PluginDecl] {
|
// TODO this is duplicative of other Go type jennies. Remove it in favor of a better-abstracted version in thema itself
|
||||||
|
func PluginGoTypesJenny(root string) codejen.OneToOne[*pfs.PluginDecl] {
|
||||||
return &pgoJenny{
|
return &pgoJenny{
|
||||||
inner: inner,
|
root: root,
|
||||||
root: root,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type pgoJenny struct {
|
type pgoJenny struct {
|
||||||
inner codejen.OneToOne[*pfs.PluginDecl]
|
root string
|
||||||
root string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *pgoJenny) JennyName() string {
|
func (j *pgoJenny) JennyName() string {
|
||||||
@ -31,16 +35,22 @@ func (j *pgoJenny) Generate(decl *pfs.PluginDecl) (*codejen.File, error) {
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
f, err := j.inner.Generate(decl)
|
slotname := strings.ToLower(decl.SchemaInterface.Name())
|
||||||
|
byt, err := gocode.GenerateTypesOpenAPI(decl.Lineage.Latest(), &gocode.TypeConfigOpenAPI{
|
||||||
|
Config: &openapi.Config{
|
||||||
|
Group: decl.SchemaInterface.IsGroup(),
|
||||||
|
Config: &copenapi.Config{
|
||||||
|
ExpandReferences: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
PackageName: slotname,
|
||||||
|
ApplyFuncs: []dstutil.ApplyFunc{corecodegen.PrefixDropper(decl.Lineage.Name()), corecodegen.DecoderCompactor()},
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
pluginfolder := filepath.Base(decl.PluginPath)
|
pluginfolder := filepath.Base(decl.PluginPath)
|
||||||
slotname := strings.ToLower(decl.SchemaInterface.Name())
|
|
||||||
filename := fmt.Sprintf("types_%s_gen.go", slotname)
|
filename := fmt.Sprintf("types_%s_gen.go", slotname)
|
||||||
f.RelativePath = filepath.Join(j.root, pluginfolder, filename)
|
return codejen.NewFile(filepath.Join(j.root, pluginfolder, "kinds", slotname, filename), byt, j), nil
|
||||||
f.From = append(f.From, j)
|
|
||||||
|
|
||||||
return f, nil
|
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ func main() {
|
|||||||
|
|
||||||
pluginKindGen.Append(
|
pluginKindGen.Append(
|
||||||
codegen.PluginTreeListJenny(),
|
codegen.PluginTreeListJenny(),
|
||||||
codegen.PluginGoTypesJenny("pkg/tsdb", adaptToPipeline(corecodegen.GoTypesJenny{ExpandReferences: true})),
|
codegen.PluginGoTypesJenny("pkg/tsdb"),
|
||||||
codegen.PluginTSTypesJenny("public/app/plugins", adaptToPipeline(corecodegen.TSTypesJenny{})),
|
codegen.PluginTSTypesJenny("public/app/plugins", adaptToPipeline(corecodegen.TSTypesJenny{})),
|
||||||
codegen.PluginDocsJenny(toDeclForGen(corecodegen.DocsJenny(
|
codegen.PluginDocsJenny(toDeclForGen(corecodegen.DocsJenny(
|
||||||
filepath.Join("docs", "sources", "developers", "kinds", "composable"),
|
filepath.Join("docs", "sources", "developers", "kinds", "composable"),
|
||||||
|
Loading…
Reference in New Issue
Block a user