Chore: Hacky first pass on generating composable kinds within grafana/schema (#64723)
* Super hacky first pass on gen types * First sketchy pass at generated compo kinds in TS, grok-style * Merge fix * Create jenny for MajorsOrX for plugins * Re-generate files with imports * Delete invalid generated file * Fix cue * Update go.mod * Update schemas * Fix go-imports * Regenerate cue files --------- Co-authored-by: spinillos <selenepinillos@gmail.com>
This commit is contained in:
@@ -34,6 +34,11 @@ func (j *lmox) JennyName() string {
|
||||
}
|
||||
|
||||
func (j *lmox) Generate(kind kindsys.Kind) (codejen.Files, error) {
|
||||
// TODO remove this once codejen catches nils https://github.com/grafana/codejen/issues/5
|
||||
if kind == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
comm := kind.Props().Common()
|
||||
sfg := SchemaForGen{
|
||||
Name: comm.Name,
|
||||
|
||||
@@ -2,8 +2,10 @@ package codegen
|
||||
|
||||
import (
|
||||
"github.com/grafana/codejen"
|
||||
"github.com/grafana/cuetsy"
|
||||
"github.com/grafana/cuetsy/ts"
|
||||
"github.com/grafana/cuetsy/ts/ast"
|
||||
"github.com/grafana/grafana/pkg/cuectx"
|
||||
"github.com/grafana/thema/encoding/typescript"
|
||||
)
|
||||
|
||||
@@ -25,6 +27,10 @@ func (j TSResourceJenny) Generate(sfg SchemaForGen) (*codejen.File, error) {
|
||||
f, err := typescript.GenerateTypes(sfg.Schema, &typescript.TypeConfig{
|
||||
RootName: sfg.Name,
|
||||
Group: sfg.IsGroup,
|
||||
CuetsyConfig: &cuetsy.Config{
|
||||
Export: true,
|
||||
ImportMapper: cuectx.MapCUEImportToTS,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -2,6 +2,8 @@ package codegen
|
||||
|
||||
import (
|
||||
"github.com/grafana/codejen"
|
||||
"github.com/grafana/cuetsy"
|
||||
"github.com/grafana/grafana/pkg/cuectx"
|
||||
"github.com/grafana/thema/encoding/typescript"
|
||||
)
|
||||
|
||||
@@ -21,6 +23,10 @@ func (j TSTypesJenny) JennyName() string {
|
||||
func (j TSTypesJenny) Generate(sfg SchemaForGen) (*codejen.File, error) {
|
||||
// TODO allow using name instead of machine name in thema generator
|
||||
f, err := typescript.GenerateTypes(sfg.Schema, &typescript.TypeConfig{
|
||||
CuetsyConfig: &cuetsy.Config{
|
||||
Export: true,
|
||||
ImportMapper: cuectx.MapCUEImportToTS,
|
||||
},
|
||||
RootName: sfg.Name,
|
||||
Group: sfg.IsGroup,
|
||||
})
|
||||
|
||||
@@ -9,8 +9,10 @@ import (
|
||||
"cuelang.org/go/cue"
|
||||
"cuelang.org/go/cue/errors"
|
||||
"github.com/grafana/codejen"
|
||||
"github.com/grafana/cuetsy"
|
||||
"github.com/grafana/cuetsy/ts"
|
||||
"github.com/grafana/cuetsy/ts/ast"
|
||||
"github.com/grafana/grafana/pkg/cuectx"
|
||||
"github.com/grafana/kindsys"
|
||||
"github.com/grafana/thema"
|
||||
"github.com/grafana/thema/encoding/typescript"
|
||||
@@ -44,6 +46,9 @@ func (gen *genTSVeneerIndex) Generate(kinds ...kindsys.Kind) (*codejen.File, err
|
||||
for _, def := range kinds {
|
||||
sch := def.Lineage().Latest()
|
||||
f, err := typescript.GenerateTypes(sch, &typescript.TypeConfig{
|
||||
CuetsyConfig: &cuetsy.Config{
|
||||
ImportMapper: cuectx.MapCUEImportToTS,
|
||||
},
|
||||
RootName: def.Props().Common().Name,
|
||||
Group: def.Props().Common().LineageIsGroup,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user