Skip to content

Commit

Permalink
marshall and save config file
Browse files Browse the repository at this point in the history
  • Loading branch information
thdaraujo committed Jun 10, 2020
1 parent 9998eb4 commit 1b38e8c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
13 changes: 9 additions & 4 deletions internal/config/projectconfig/init.go
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/commitdev/zero/internal/constants"
"github.com/commitdev/zero/pkg/util/exit"
"gopkg.in/yaml.v2"
)

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

func Init(dir string, projectName string, projectContext *ZeroProjectConfig) {
// TODO: template the zero-project.yml with projectContext
content := []byte(fmt.Sprintf(exampleConfig, projectName))

err := ioutil.WriteFile(path.Join(dir, projectName, constants.ZeroProjectYml), content, 0644)
// content := []byte(fmt.Sprintf(exampleConfig, projectName))
content, err := yaml.Marshal(projectContext)
if err != nil {
exit.Fatal(fmt.Sprintf("Failed to create example %s", constants.ZeroProjectYml))
exit.Fatal(fmt.Sprintf("Failed to serialize configuration file %s", constants.ZeroProjectYml))
}

writeErr := ioutil.WriteFile(path.Join(dir, projectName, constants.ZeroProjectYml), content, 0644)
if writeErr != nil {
exit.Fatal(fmt.Sprintf("Failed to create config file %s", constants.ZeroProjectYml))
}
}
10 changes: 5 additions & 5 deletions internal/config/projectconfig/project_config.go
Expand Up @@ -33,8 +33,8 @@ type terraform struct {
type Modules map[string]Module

type Module struct {
Parameters Parameters `yaml:"parameters"`
Files Files `yaml:"files"`
Parameters Parameters `yaml:"parameters,omitempty"`
Files Files `yaml:"files,omitempty"`
}

type Parameters map[string]string
Expand Down Expand Up @@ -66,9 +66,9 @@ func (c *ZeroProjectConfig) Print() {
func EKSGoReactSampleModules() Modules {
parameters := Parameters{}
return Modules{
"zero-aws-eks-stack": NewModule(parameters, "zero-aws-eks-stack", "github.com/commitdev/zero-aws-eks-stack"),
"zero-deployable-backend": NewModule(parameters, "zero-deployable-backend", "github.com/commitdev/zero-deployable-backend"),
"zero-deployable-react-frontend": NewModule(parameters, "zero-deployable-react-frontend", "github.com/commitdev/zero-deployable-react-frontend"),
"aws-eks-stack": NewModule(parameters, "zero-aws-eks-stack", "github.com/commitdev/zero-aws-eks-stack"),
"deployable-backend": NewModule(parameters, "zero-deployable-backend", "github.com/commitdev/zero-deployable-backend"),
"deployable-react-frontend": NewModule(parameters, "zero-deployable-react-frontend", "github.com/commitdev/zero-deployable-react-frontend"),
}
}

Expand Down

0 comments on commit 1b38e8c

Please sign in to comment.