* Add codegen/go/gen_crd2pulumi * Properly generate Go CRD resources * generate nodejs resources * Remove nodejs/gen_crd2pulumi.go * Remove generating funtions
52 lines
1.2 KiB
Go
52 lines
1.2 KiB
Go
package gen
|
|
|
|
import (
|
|
"bytes"
|
|
|
|
"github.com/pkg/errors"
|
|
"github.com/pulumi/pulumi/pkg/v2/codegen/schema"
|
|
)
|
|
|
|
// CRDTypes returns a map from each module name to a buffer containing the
|
|
// code for its generated types.
|
|
func CRDTypes(tool string, pkg *schema.Package) (map[string]*bytes.Buffer, error) {
|
|
if err := pkg.ImportLanguages(map[string]schema.Language{"go": Importer}); err != nil {
|
|
return map[string]*bytes.Buffer{}, err
|
|
}
|
|
|
|
goInfo, _ := pkg.Language["go"].(GoPackageInfo)
|
|
packages := generatePackageContextMap(tool, pkg, goInfo)
|
|
|
|
var pkgMods []string
|
|
for mod := range packages {
|
|
pkgMods = append(pkgMods, mod)
|
|
}
|
|
|
|
buffers := map[string]*bytes.Buffer{}
|
|
|
|
for _, mod := range pkgMods {
|
|
pkg := packages[mod]
|
|
buffer := &bytes.Buffer{}
|
|
|
|
for _, r := range pkg.resources {
|
|
imports := stringSet{}
|
|
pkg.getImports(r, imports)
|
|
pkg.genHeader(buffer, []string{"context", "reflect"}, imports)
|
|
|
|
if err := pkg.genResource(buffer, r); err != nil {
|
|
return nil, errors.Wrapf(err, "generating resource %s", mod)
|
|
}
|
|
}
|
|
|
|
if len(pkg.types) > 0 {
|
|
for _, t := range pkg.types {
|
|
pkg.genType(buffer, t)
|
|
}
|
|
pkg.genTypeRegistrations(buffer, pkg.types)
|
|
}
|
|
|
|
buffers[mod] = buffer
|
|
}
|
|
|
|
return buffers, nil
|
|
}
|