mirror of
https://github.com/grafana/grafana.git
synced 2024-11-26 02:40:26 -06:00
473898e47c
* Move some thema code inside grafana * Use new codegen instead of thema for core kinds * Replace TS generator * Use new generator for go types * Remove thema from oapi generator * Remove thema from generators * Don't use kindsys/thema for core kinds * Remove kindsys/thema from plugins * Remove last thema related * Remove most of cuectx and move utils_ts into codegen. It also deletes wire dependency * Merge plugins generators * Delete thema dependency 🎉 * Fix CODEOWNERS * Fix package name * Fix TS output names * More path fixes * Fix mod codeowners * Use original plugin's name * Remove kindsys dependency 🎉 * Modify oapi schema and create an apply function to fix elasticsearch errors * cue.mod was deleted by mistake * Fix TS panels * sort imports * Fixing elasticsearch output * Downgrade oapi-codegen library * Update output ts files * More fixes * Restore old elasticsearch generated file and skip its generation. Remove core imports into plugins * More lint fixes * Add codeowners * restore embed.go file * Fix embed.go
46 lines
1004 B
Go
46 lines
1004 B
Go
package codegen
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"cuelang.org/go/cue"
|
|
"github.com/dave/dst/dstutil"
|
|
"github.com/grafana/codejen"
|
|
"github.com/grafana/grafana/pkg/codegen/generators"
|
|
)
|
|
|
|
type GoSpecJenny struct {
|
|
ApplyFuncs []dstutil.ApplyFunc
|
|
}
|
|
|
|
func (jenny *GoSpecJenny) JennyName() string {
|
|
return "GoResourceTypes"
|
|
}
|
|
|
|
func (jenny *GoSpecJenny) Generate(sfg ...SchemaForGen) (codejen.Files, error) {
|
|
files := make(codejen.Files, len(sfg))
|
|
for i, v := range sfg {
|
|
packageName := strings.ToLower(v.Name)
|
|
b, err := generators.GenerateTypesGo(v.CueFile,
|
|
&generators.GoConfig{
|
|
Config: &generators.OpenApiConfig{
|
|
IsGroup: false,
|
|
RootName: "Spec",
|
|
SubPath: cue.MakePath(cue.Str("spec")),
|
|
},
|
|
PackageName: packageName,
|
|
ApplyFuncs: append(jenny.ApplyFuncs, PrefixDropper(v.Name)),
|
|
},
|
|
)
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
files[i] = *codejen.NewFile(fmt.Sprintf("pkg/kinds/%s/%s_spec_gen.go", packageName, packageName), b, jenny)
|
|
}
|
|
|
|
return files, nil
|
|
}
|