Schemas: Delete unused code from the previous refactors (#84254)

* Delete unused code from the previous refactors

* Sort imports
This commit is contained in:
Selene
2024-03-13 12:30:05 +01:00
committed by GitHub
parent 2a1a5145d0
commit 75ea33e0cd
13 changed files with 50 additions and 368 deletions
+49 -8
View File
@@ -5,20 +5,16 @@ import (
"path/filepath"
"github.com/grafana/codejen"
"github.com/grafana/cuetsy/ts"
"github.com/grafana/cuetsy/ts/ast"
"github.com/grafana/kindsys"
)
// LatestMajorsOrXJenny returns a jenny that repeats the input for the latest in each major version.
//
// TODO remove forceGroup option, it's a temporary hack to accommodate core kinds
func LatestMajorsOrXJenny(parentdir string, inner codejen.OneToOne[SchemaForGen]) OneToMany {
if inner == nil {
panic("inner jenny must not be nil")
}
func LatestMajorsOrXJenny(parentdir string) OneToMany {
return &lmox{
parentdir: parentdir,
inner: inner,
inner: TSTypesJenny{ApplyFuncs: []ApplyFunc{renameSpecNode}},
}
}
@@ -56,3 +52,48 @@ func (j *lmox) Generate(kind kindsys.Kind) (codejen.Files, error) {
f.From = append(f.From, j)
return codejen.Files{*f}, nil
}
// renameSpecNode rename spec node from the TS file result
func renameSpecNode(sfg SchemaForGen, tf *ast.File) {
specidx, specdefidx := -1, -1
for idx, def := range tf.Nodes {
// Peer through export keywords
if ex, is := def.(ast.ExportKeyword); is {
def = ex.Decl
}
switch x := def.(type) {
case ast.TypeDecl:
if x.Name.Name == "spec" {
specidx = idx
x.Name.Name = sfg.Name
tf.Nodes[idx] = x
}
case ast.VarDecl:
// Before:
// export const defaultspec: Partial<spec> = {
// After:
// / export const defaultPlaylist: Partial<Playlist> = {
if x.Names.Idents[0].Name == "defaultspec" {
specdefidx = idx
x.Names.Idents[0].Name = "default" + sfg.Name
tt := x.Type.(ast.TypeTransformExpr)
tt.Expr = ts.Ident(sfg.Name)
x.Type = tt
tf.Nodes[idx] = x
}
}
}
if specidx != -1 {
decl := tf.Nodes[specidx]
tf.Nodes = append(append(tf.Nodes[:specidx], tf.Nodes[specidx+1:]...), decl)
}
if specdefidx != -1 {
if specdefidx > specidx {
specdefidx--
}
decl := tf.Nodes[specdefidx]
tf.Nodes = append(append(tf.Nodes[:specdefidx], tf.Nodes[specdefidx+1:]...), decl)
}
}