github.com/wawandco/ox@v0.13.6-0.20230809142027-913b3d837f2a/plugins/tools/ox/embedded/initializer.go (about) 1 package embedded 2 3 import ( 4 "context" 5 "embed" 6 "path/filepath" 7 8 "github.com/wawandco/ox/internal/source" 9 "github.com/wawandco/ox/plugins/base/new" 10 ) 11 12 var ( 13 14 //go:embed templates 15 templates embed.FS 16 ) 17 18 // Initializer 19 type Initializer struct{} 20 21 func (i Initializer) Name() string { 22 return "embedded/initializer" 23 } 24 25 func (i *Initializer) Initialize(ctx context.Context, options new.Options) error { 26 files := map[string]string{ 27 "templates/rootname.go.tmpl": filepath.Join(options.Folder, options.Name+".go"), 28 "templates/templates.go.tmpl": filepath.Join(options.Folder, "app", "templates", "templates.go"), 29 "templates/public.go.tmpl": filepath.Join(options.Folder, "public", "public.go"), 30 "templates/config.go.tmpl": filepath.Join(options.Folder, "config", "config.go"), 31 "templates/migrations.go.tmpl": filepath.Join(options.Folder, "migrations", "migrations.go"), 32 } 33 34 for k, path := range files { 35 content, err := templates.ReadFile(k) 36 if err != nil { 37 return err 38 } 39 40 err = source.Build(path, string(content), options.Name) 41 if err != nil { 42 return err 43 } 44 } 45 46 return nil 47 }