From 5f5cbfe44e0d7f6125f6421e2f490f6b7aaa5479 Mon Sep 17 00:00:00 2001 From: Matt Toohey Date: Tue, 1 Oct 2024 10:59:35 +1000 Subject: [PATCH] centralise scaffold funcs --- frontend/cli/cmd_init.go | 19 +------------------ frontend/cli/cmd_schema_generate.go | 1 - internal/buildengine/plugin.go | 17 ----------------- internal/buildengine/plugin_go.go | 1 - internal/buildengine/plugin_java.go | 2 +- 5 files changed, 2 insertions(+), 38 deletions(-) diff --git a/frontend/cli/cmd_init.go b/frontend/cli/cmd_init.go index cdbba65bdf..69ca63f1ed 100644 --- a/frontend/cli/cmd_init.go +++ b/frontend/cli/cmd_init.go @@ -8,13 +8,10 @@ import ( "os" "path" "strings" - "text/template" "github.com/TBD54566975/scaffolder" "github.com/TBD54566975/ftl" - "github.com/TBD54566975/ftl/backend/schema" - "github.com/TBD54566975/ftl/backend/schema/strcase" "github.com/TBD54566975/ftl/internal" "github.com/TBD54566975/ftl/internal/configuration" "github.com/TBD54566975/ftl/internal/configuration/providers" @@ -120,7 +117,7 @@ func updateGitIgnore(ctx context.Context, gitRoot string) error { func scaffold(ctx context.Context, includeBinDir bool, source *zip.Reader, destination string, sctx any, options ...scaffolder.Option) error { logger := log.FromContext(ctx) - opts := []scaffolder.Option{scaffolder.Functions(scaffoldFuncs), scaffolder.Exclude("^go.mod$")} + opts := []scaffolder.Option{scaffolder.Exclude("^go.mod$")} if !includeBinDir { logger.Debugf("Excluding bin directory") opts = append(opts, scaffolder.Exclude("^bin")) @@ -131,17 +128,3 @@ func scaffold(ctx context.Context, includeBinDir bool, source *zip.Reader, desti } return nil } - -var scaffoldFuncs = template.FuncMap{ - "snake": strcase.ToLowerSnake, - "screamingSnake": strcase.ToUpperSnake, - "camel": strcase.ToUpperCamel, - "lowerCamel": strcase.ToLowerCamel, - "strippedCamel": strcase.ToUpperStrippedCamel, - "kebab": strcase.ToLowerKebab, - "screamingKebab": strcase.ToUpperKebab, - "upper": strings.ToUpper, - "lower": strings.ToLower, - "title": strings.Title, - "typename": schema.TypeName, -} diff --git a/frontend/cli/cmd_schema_generate.go b/frontend/cli/cmd_schema_generate.go index eb28832592..4c7059aadf 100644 --- a/frontend/cli/cmd_schema_generate.go +++ b/frontend/cli/cmd_schema_generate.go @@ -144,7 +144,6 @@ func (s *schemaGenerateCmd) regenerateModules(logger *log.Logger, modules []*sch for _, module := range modules { if err := scaffolder.Scaffold(s.Template, s.Dest, module, - scaffolder.Functions(scaffoldFuncs), scaffolder.Extend(javascript.Extension("template.js", javascript.WithLogger(makeJSLoggerAdapter(logger)))), ); err != nil { return err diff --git a/internal/buildengine/plugin.go b/internal/buildengine/plugin.go index ef6c990dcb..eece05aa48 100644 --- a/internal/buildengine/plugin.go +++ b/internal/buildengine/plugin.go @@ -5,8 +5,6 @@ import ( "fmt" "os" "path/filepath" - "strings" - "text/template" "time" "github.com/alecthomas/types/either" @@ -15,7 +13,6 @@ import ( schemapb "github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/v1/schema" "github.com/TBD54566975/ftl/backend/schema" - "github.com/TBD54566975/ftl/backend/schema/strcase" "github.com/TBD54566975/ftl/internal/errors" "github.com/TBD54566975/ftl/internal/flock" "github.com/TBD54566975/ftl/internal/moduleconfig" @@ -91,20 +88,6 @@ func PluginFromConfig(ctx context.Context, config moduleconfig.ModuleConfig, pro } } -var scaffoldFuncs = template.FuncMap{ - "snake": strcase.ToLowerSnake, - "screamingSnake": strcase.ToUpperSnake, - "camel": strcase.ToUpperCamel, - "lowerCamel": strcase.ToLowerCamel, - "strippedCamel": strcase.ToUpperStrippedCamel, - "kebab": strcase.ToLowerKebab, - "screamingKebab": strcase.ToUpperKebab, - "upper": strings.ToUpper, - "lower": strings.ToLower, - "title": strings.Title, - "typename": schema.TypeName, -} - //sumtype:decl type pluginCommand interface { pluginCmd() diff --git a/internal/buildengine/plugin_go.go b/internal/buildengine/plugin_go.go index 571f1e6d98..244df234c4 100644 --- a/internal/buildengine/plugin_go.go +++ b/internal/buildengine/plugin_go.go @@ -48,7 +48,6 @@ func (p *goPlugin) CreateModule(ctx context.Context, c moduleconfig.ModuleConfig config := c.Abs() opts := []scaffolder.Option{ scaffolder.Exclude("^go.mod$"), - scaffolder.Functions(scaffoldFuncs), } if !includeBinDir { logger.Debugf("Excluding bin directory") diff --git a/internal/buildengine/plugin_java.go b/internal/buildengine/plugin_java.go index 9277d3078f..9c696eac70 100644 --- a/internal/buildengine/plugin_java.go +++ b/internal/buildengine/plugin_java.go @@ -65,7 +65,7 @@ func (p *javaPlugin) CreateModule(ctx context.Context, config moduleconfig.Modul PackageDir: packageDir, } - opts := []scaffolder.Option{scaffolder.Functions(scaffoldFuncs), scaffolder.Exclude("^go.mod$")} + opts := []scaffolder.Option{scaffolder.Exclude("^go.mod$")} if !includeBinDir { logger.Debugf("Excluding bin directory") opts = append(opts, scaffolder.Exclude("^bin"))