forked from ignite/cli
/
new.go
42 lines (36 loc) · 1.24 KB
/
new.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
40
41
42
package app
import (
"strings"
"github.com/gobuffalo/genny"
"github.com/gobuffalo/packr/v2"
"github.com/gobuffalo/plush"
"github.com/gobuffalo/plushgen"
"github.com/tendermint/starport/starport/pkg/cosmosver"
)
// these needs to be created in the compiler time, otherwise packr2 won't be
// able to find boxes.
var templates = map[cosmosver.MajorVersion]*packr.Box{
cosmosver.Launchpad: packr.New("app/templates/launchpad", "./launchpad"),
cosmosver.Stargate: packr.New("app/templates/stargate", "./stargate"),
}
// New ...
func New(sdkVersion cosmosver.MajorVersion, opts *Options) (*genny.Generator, error) {
g := genny.New()
if err := g.Box(templates[sdkVersion]); err != nil {
return g, err
}
ctx := plush.NewContext()
ctx.Set("ModulePath", opts.ModulePath)
ctx.Set("AppName", opts.AppName)
ctx.Set("OwnerName", opts.OwnerName)
ctx.Set("BinaryNamePrefix", opts.BinaryNamePrefix)
ctx.Set("AddressPrefix", opts.AddressPrefix)
ctx.Set("title", strings.Title)
ctx.Set("nodash", func(s string) string {
return strings.ReplaceAll(s, "-", "")
})
g.Transformer(plushgen.Transformer(ctx))
g.Transformer(genny.Replace("{{appName}}", opts.AppName))
g.Transformer(genny.Replace("{{binaryNamePrefix}}", opts.BinaryNamePrefix))
return g, nil
}