Skip to content

Commit 1b38e8c

Browse files
committed
marshall and save config file
1 parent 9998eb4 commit 1b38e8c

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

internal/config/projectconfig/init.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"github.com/commitdev/zero/internal/constants"
99
"github.com/commitdev/zero/pkg/util/exit"
10+
"gopkg.in/yaml.v2"
1011
)
1112

1213
const exampleConfig = `name: %s
@@ -47,10 +48,14 @@ func SetRootDir(dir string) {
4748

4849
func Init(dir string, projectName string, projectContext *ZeroProjectConfig) {
4950
// TODO: template the zero-project.yml with projectContext
50-
content := []byte(fmt.Sprintf(exampleConfig, projectName))
51-
52-
err := ioutil.WriteFile(path.Join(dir, projectName, constants.ZeroProjectYml), content, 0644)
51+
// content := []byte(fmt.Sprintf(exampleConfig, projectName))
52+
content, err := yaml.Marshal(projectContext)
5353
if err != nil {
54-
exit.Fatal(fmt.Sprintf("Failed to create example %s", constants.ZeroProjectYml))
54+
exit.Fatal(fmt.Sprintf("Failed to serialize configuration file %s", constants.ZeroProjectYml))
55+
}
56+
57+
writeErr := ioutil.WriteFile(path.Join(dir, projectName, constants.ZeroProjectYml), content, 0644)
58+
if writeErr != nil {
59+
exit.Fatal(fmt.Sprintf("Failed to create config file %s", constants.ZeroProjectYml))
5560
}
5661
}

internal/config/projectconfig/project_config.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ type terraform struct {
3333
type Modules map[string]Module
3434

3535
type Module struct {
36-
Parameters Parameters `yaml:"parameters"`
37-
Files Files `yaml:"files"`
36+
Parameters Parameters `yaml:"parameters,omitempty"`
37+
Files Files `yaml:"files,omitempty"`
3838
}
3939

4040
type Parameters map[string]string
@@ -66,9 +66,9 @@ func (c *ZeroProjectConfig) Print() {
6666
func EKSGoReactSampleModules() Modules {
6767
parameters := Parameters{}
6868
return Modules{
69-
"zero-aws-eks-stack": NewModule(parameters, "zero-aws-eks-stack", "github.com/commitdev/zero-aws-eks-stack"),
70-
"zero-deployable-backend": NewModule(parameters, "zero-deployable-backend", "github.com/commitdev/zero-deployable-backend"),
71-
"zero-deployable-react-frontend": NewModule(parameters, "zero-deployable-react-frontend", "github.com/commitdev/zero-deployable-react-frontend"),
69+
"aws-eks-stack": NewModule(parameters, "zero-aws-eks-stack", "github.com/commitdev/zero-aws-eks-stack"),
70+
"deployable-backend": NewModule(parameters, "zero-deployable-backend", "github.com/commitdev/zero-deployable-backend"),
71+
"deployable-react-frontend": NewModule(parameters, "zero-deployable-react-frontend", "github.com/commitdev/zero-deployable-react-frontend"),
7272
}
7373
}
7474

0 commit comments

Comments
 (0)