diff --git a/README.md b/README.md index 840869c..38d96ff 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,9 @@ synmake --config= --debug An example configuration file might look like this: ```yaml --- +env: + - .env + - .env.local targets: targetA: helpDescription: targetA just prints an output @@ -60,6 +63,9 @@ templates: minVersion: 0.1.0 ``` +### Env files +List all env files that should be used inside the Makefile + ### Targets Each key under targets specifies a new target where you can specify 3 attributes: - `helpDescription` -> This field describes the target and will be added above the target as documentation. If you have set diff --git a/internal/config/apply.go b/internal/config/apply.go index 81046bd..dac2399 100644 --- a/internal/config/apply.go +++ b/internal/config/apply.go @@ -29,6 +29,11 @@ func (cm *ConfigManager) applyConfig(w io.StringWriter) error { ) } + // -- Env files + cm.logger.Info("Inserting env file includes", zap.Strings("func", cm.Config.EnvFiles)) + content = content.addSuggar(assembleEnvFiles(cm.Config.EnvFiles)) + cm.logger.Info("Env files included") + // --- VARIABLES cm.logger.Info("Variables will be added", zap.String("func", "applyConfig")) variables := []string{} diff --git a/internal/config/assembler.go b/internal/config/assembler.go index acd6474..dd9a0dc 100644 --- a/internal/config/assembler.go +++ b/internal/config/assembler.go @@ -44,6 +44,16 @@ func assemblePreflightTarget(commands []string) SuggarString { return content } +func assembleEnvFiles(envFiles []string) SuggarString { + var content SuggarString + + for _, envFile := range envFiles { + content.appendString("-include").appendString(" ").appendString(envFile).lineBreak() + } + + return content +} + func assembleTargets(targetMap map[string]Target, delimiter string) SuggarString { var content SuggarString for targetName, targetConfig := range targetMap { diff --git a/internal/config/config.go b/internal/config/config.go index 1ea9a20..5f361c4 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -28,6 +28,7 @@ type OptionalTemplates struct { } type Config struct { + EnvFiles []string `yaml:"env"` Targets map[string]Target `yaml:"targets"` Templates OptionalTemplates `yaml:"templates"` } diff --git a/internal/config/example.go b/internal/config/example.go index dfaf855..74ed042 100644 --- a/internal/config/example.go +++ b/internal/config/example.go @@ -2,9 +2,10 @@ package config import ( "bytes" - "gopkg.in/yaml.v3" "io" + "gopkg.in/yaml.v3" + "go.uber.org/zap" ) @@ -23,6 +24,7 @@ func GenerateExampleYamlConfig(logger *zap.Logger, w io.StringWriter) error { } config := Config{ + EnvFiles: []string{}, Targets: map[string]Target{ "targetA": tA, "targetB": tB,