Skip to content

Commit

Permalink
feat: generate ftl-project.toml in the Git root if it DNE
Browse files Browse the repository at this point in the history
  • Loading branch information
deniseli committed Jun 4, 2024
1 parent 7cb8e83 commit 0971d26
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
5 changes: 4 additions & 1 deletion cmd/ftl/cmd_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/TBD54566975/ftl/backend/schema"
"github.com/TBD54566975/ftl/backend/schema/strcase"
"github.com/TBD54566975/ftl/buildengine"
"github.com/TBD54566975/ftl/common/projectconfig"
goruntime "github.com/TBD54566975/ftl/go-runtime"
"github.com/TBD54566975/ftl/internal"
"github.com/TBD54566975/ftl/internal/exec"
Expand Down Expand Up @@ -50,8 +51,10 @@ func (i initGoCmd) Run(ctx context.Context, parent *initCmd) error {
if err := updateGitIgnore(i.Dir); err != nil {
return err
}
if err := projectconfig.CreateDefaultFileIfNonexistent(ctx); err != nil {
return err
}
logger.Debugf("Running go mod tidy")

return exec.Command(ctx, log.Debug, filepath.Join(i.Dir, i.Name), "go", "mod", "tidy").RunBuffered(ctx)
}

Expand Down
16 changes: 16 additions & 0 deletions common/projectconfig/projectconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,22 @@ func GetDefaultConfigPath() string {
return filepath.Join(internal.GitRoot(""), "ftl-project.toml")
}

// CreateDefaultFileIfNonexistent creates the ftl-project.toml file in the Git root if it
// does not already exist.
func CreateDefaultFileIfNonexistent(ctx context.Context) error {
path := GetDefaultConfigPath()
_, err := os.Stat(path)
if err == nil {
return nil
}
if !errors.Is(err, os.ErrNotExist) {
return err
}
logger := log.FromContext(ctx)
logger.Warnf("Creating a new project config file at %q because the file does not already exist", path)
return Save(path, Config{})
}

func LoadConfig(ctx context.Context, input []string) (Config, error) {
logger := log.FromContext(ctx)
configPaths := ConfigPaths(input)
Expand Down

0 comments on commit 0971d26

Please sign in to comment.