Kindsys: Target k8s style resource definitions (#67008)

Co-authored-by: sam boyer <sdboyer@grafana.com>
This commit is contained in:
Ryan McKinley
2023-04-27 13:32:38 -07:00
committed by GitHub
parent b71b778d0d
commit ca1f79b9ba
80 changed files with 1991 additions and 640 deletions
+8 -3
View File
@@ -50,6 +50,7 @@ func (gen *genTSVeneerIndex) Generate(kinds ...kindsys.Kind) (*codejen.File, err
if err != nil {
return nil, fmt.Errorf("%s: %w", def.Props().Common().Name, err)
}
renameSpecNode(def.Props().Common().Name, f)
elems, err := gen.extractTSIndexVeneerElements(def, f)
if err != nil {
return nil, fmt.Errorf("%s: %w", def.Props().Common().Name, err)
@@ -75,13 +76,13 @@ func (gen *genTSVeneerIndex) extractTSIndexVeneerElements(def kindsys.Kind, tf *
sels := p.Selectors()
switch len(sels) {
case 0:
name = comm.Name
fallthrough
return true
case 1:
// Only deal with subpaths that are definitions, for now
// TODO incorporate smarts about grouped lineages here
if name == "" {
if !sels[0].IsDefinition() {
if !(sels[0].IsDefinition() || sels[0].String() == "spec") {
return false
}
// It might seem to make sense that we'd strip replaceout the leading # here for
@@ -90,6 +91,10 @@ func (gen *genTSVeneerIndex) extractTSIndexVeneerElements(def kindsys.Kind, tf *
name = sels[0].String()
}
if name == "spec" {
name = comm.Name
}
// Search the generated TS AST for the type and default def nodes
pair := findDeclNode(name, tf)
if pair.T == nil {