pkg/generator: fold codegen scripts generation into renderTmp()
@@ -30,6 +30,8 @@ const (
register = "register.go"
types = "types.go"
build = "build.sh"
+ boilerplate = "boilerplate.go.txt"
+ updateGenerated = "update-generated.sh"
)
type Generator struct {
@@ -128,11 +130,11 @@ func (g *Generator) renderTmp() error {
return err
}
- if err := os.MkdirAll(filepath.Join(g.projectName, codegenDir), defaultDirFileMode); err != nil {
+ cDir := filepath.Join(g.projectName, codegenDir)
+ if err := os.MkdirAll(cDir, defaultDirFileMode); err != nil {
return err
}
- // TODO render files.
- return nil
+ return renderCodegenFiles(cDir, g.repoPath, apiDirName(g.apiVersion), version(g.apiVersion), g.projectName)
}
func renderBuildFiles(buildDir, repoPath, projectName string) error {
@@ -143,6 +145,22 @@ func renderBuildFiles(buildDir, repoPath, projectName string) error {
return ioutil.WriteFile(filepath.Join(buildDir, build), buf.Bytes(), defaultExecFileMode)
}
+func renderCodegenFiles(codegenDir, repoPath, apiDirName, version, projectName string) error {
+ buf := &bytes.Buffer{}
+ if err := renderBoilerplateFile(buf, projectName); err != nil {
+ return err
+ }
+ if err := ioutil.WriteFile(filepath.Join(codegenDir, boilerplate), buf.Bytes(), defaultFileMode); err != nil {
+ return err
+ }
+
+ buf = &bytes.Buffer{}
+ if err := renderUpdateGeneratedFile(buf, repoPath, apiDirName, version); err != nil {
+ return err
+ }
+ return ioutil.WriteFile(filepath.Join(codegenDir, updateGenerated), buf.Bytes(), defaultExecFileMode)
+}
+
func (g *Generator) renderPkg() error {
v := version(g.apiVersion)
apiDir := filepath.Join(g.projectName, apisDir, apiDirName(g.apiVersion), v)
