mirror of https://github.com/pulumi/pulumi.git
61 lines
1.2 KiB
Go
61 lines
1.2 KiB
Go
package sdkgen
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/pulumi/pulumi/pkg/v3/codegen/nodejs/codebase"
|
|
"github.com/pulumi/pulumi/pkg/v3/codegen/schema"
|
|
)
|
|
|
|
func GeneratePackage(
|
|
tool string,
|
|
pkg *schema.Package,
|
|
extraFiles map[string][]byte,
|
|
localDependencies map[string]string,
|
|
) (map[string][]byte, error) {
|
|
g := NewGenerator(pkg)
|
|
return g.GeneratePackage(tool, extraFiles, localDependencies)
|
|
}
|
|
|
|
type generator struct {
|
|
pkg *schema.Package
|
|
info NodePackageInfo
|
|
|
|
codebase *codebase.Codebase
|
|
}
|
|
|
|
func NewGenerator(
|
|
pkg *schema.Package,
|
|
) *generator {
|
|
info, _ := pkg.Language["nodejs"].(NodePackageInfo)
|
|
|
|
codebase := codebase.NewCodebase()
|
|
|
|
return &generator{
|
|
pkg: pkg,
|
|
info: info,
|
|
|
|
codebase: &codebase,
|
|
}
|
|
}
|
|
|
|
func (g *generator) GeneratePackage(
|
|
tool string,
|
|
extraFiles map[string][]byte,
|
|
localDependencies map[string]string,
|
|
) (map[string][]byte, error) {
|
|
for _, r := range g.pkg.Resources {
|
|
g.generateResource(r)
|
|
}
|
|
|
|
for _, m := range g.codebase.Modules {
|
|
m.WithHeader(
|
|
fmt.Sprintf("// *** WARNING: this file was generated by %s. ***", tool),
|
|
"// *** Do not edit by hand unless you're certain you know what you are doing! ***",
|
|
)
|
|
}
|
|
|
|
files := g.codebase.Instantiate()
|
|
return files, nil
|
|
}
|