From 754fe81e01422148d049e41ce92f07325c063fc5 Mon Sep 17 00:00:00 2001 From: 3wc <3wc@doesthisthing.work> Date: Thu, 16 Sep 2021 15:04:04 +0200 Subject: [PATCH] feat: add templating during `.. app new` Closes coop-cloud/organising#168 --- cli/app/new.go | 2 +- pkg/config/app.go | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/cli/app/new.go b/cli/app/new.go index 07dd7fc2..b0dbe26e 100644 --- a/cli/app/new.go +++ b/cli/app/new.go @@ -200,7 +200,7 @@ func action(c *cli.Context) error { } logrus.Debugf("'%s' sanitised as '%s' for new app", newAppName, sanitisedAppName) - if err := config.CopyAppEnvSample(recipe.Name, newAppName, newAppServer); err != nil { + if err := config.TemplateAppEnvSample(recipe.Name, newAppName, newAppServer, domain, recipe.Name); err != nil { logrus.Fatal(err) } diff --git a/pkg/config/app.go b/pkg/config/app.go index 92655d7e..9b6c5ad8 100644 --- a/pkg/config/app.go +++ b/pkg/config/app.go @@ -243,8 +243,8 @@ func GetAppNames() ([]string, error) { return appNames, nil } -// CopyAppEnvSample copies the example env file for the app into the users env files -func CopyAppEnvSample(appType, appName, server string) error { +// TemplateAppEnvSample copies the example env file for the app into the users env files +func TemplateAppEnvSample(appType, appName, server, domain, recipe string) error { envSamplePath := path.Join(ABRA_DIR, "apps", appType, ".env.sample") envSample, err := ioutil.ReadFile(envSamplePath) if err != nil { @@ -256,6 +256,9 @@ func CopyAppEnvSample(appType, appName, server string) error { return fmt.Errorf("%s already exists?", appEnvPath) } + envSample = []byte(strings.Replace(string(envSample), fmt.Sprintf("%s.example.com", recipe), domain, -1)); + envSample = []byte(strings.Replace(string(envSample), "example.com", domain, -1)); + err = ioutil.WriteFile(appEnvPath, envSample, 0755) if err != nil { return err