generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 7
/
scaffold.go
39 lines (34 loc) · 1.1 KB
/
scaffold.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package internal
import (
"archive/zip"
"os"
"strings"
"github.com/TBD54566975/scaffolder"
"github.com/TBD54566975/ftl/backend/schema"
"github.com/TBD54566975/ftl/backend/schema/strcase"
)
// ScaffoldZip is a convenience function for scaffolding a zip archive with scaffolder.
func ScaffoldZip(source *zip.Reader, destination string, ctx any, options ...scaffolder.Option) error {
tmpDir, err := os.MkdirTemp("", "scaffold-")
if err != nil {
return err
}
defer os.RemoveAll(tmpDir)
if err := UnzipDir(source, tmpDir); err != nil {
return err
}
options = append(options, scaffolder.Functions(scaffoldFuncs))
return scaffolder.Scaffold(tmpDir, destination, ctx, options...)
}
var scaffoldFuncs = scaffolder.FuncMap{
"snake": strcase.ToLowerSnake,
"screamingSnake": strcase.ToUpperSnake,
"camel": strcase.ToUpperCamel,
"lowerCamel": strcase.ToLowerCamel,
"kebab": strcase.ToLowerKebab,
"screamingKebab": strcase.ToUpperKebab,
"upper": strings.ToUpper,
"lower": strings.ToLower,
"title": strings.Title,
"typename": schema.TypeName,
}