Skip to content

Commit

Permalink
centralise scaffold funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
matt2e committed Oct 1, 2024
1 parent 60a4b2d commit 5f5cbfe
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 38 deletions.
19 changes: 1 addition & 18 deletions frontend/cli/cmd_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"))
Expand All @@ -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,
}
1 change: 0 additions & 1 deletion frontend/cli/cmd_schema_generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 0 additions & 17 deletions internal/buildengine/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"fmt"
"os"
"path/filepath"
"strings"
"text/template"
"time"

"github.com/alecthomas/types/either"
Expand All @@ -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"
Expand Down Expand Up @@ -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()
Expand Down
1 change: 0 additions & 1 deletion internal/buildengine/plugin_go.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion internal/buildengine/plugin_java.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down

0 comments on commit 5f5cbfe

Please sign in to comment.