Skip to content

Commit 9ad4b4d

Browse files
authored
feat: scaffold a new app without a default module (#1214)
1 parent 044aa82 commit 9ad4b4d

File tree

5 files changed

+87
-29
lines changed

5 files changed

+87
-29
lines changed

changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Features:
6+
7+
- Added the flag `--no-default-module` to the command `starport app` to prevent scaffolding a default module when creating a new app
8+
39
## `v0.16.1`
410

511
### Features:

integration/cmd_app_test.go

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package integration_test
44

55
import (
6+
"fmt"
67
"os"
78
"path/filepath"
89
"testing"
@@ -11,19 +12,52 @@ import (
1112
"github.com/tendermint/starport/starport/pkg/cmdrunner/step"
1213
)
1314

14-
func TestGenerateAnAppAndVerify(t *testing.T) {
15+
func TestGenerateAnApp(t *testing.T) {
1516
var (
1617
env = newEnv(t)
1718
path = env.Scaffold("blog")
1819
)
1920

20-
_, statErr := os.Stat(filepath.Join(path, "config.yml"))
21-
require.False(t, os.IsNotExist(statErr), "config.yml cannot be found")
21+
_, statErr := os.Stat(filepath.Join(path, "x", "blog"))
22+
require.False(t, os.IsNotExist(statErr), "the default module should be scaffolded")
2223

2324
env.EnsureAppIsSteady(path)
2425
}
2526

26-
func TestGenerateAnAppWithWasmAndVerify(t *testing.T) {
27+
func TestGenerateAnAppWithNoDefaultModule(t *testing.T) {
28+
var (
29+
env = newEnv(t)
30+
appName = "blog"
31+
)
32+
33+
root := env.TmpDir()
34+
env.Exec("scaffold an app",
35+
step.NewSteps(step.New(
36+
step.Exec(
37+
"starport",
38+
"app",
39+
fmt.Sprintf("github.com/test/%s", appName),
40+
"--no-default-module",
41+
),
42+
step.Workdir(root),
43+
)),
44+
)
45+
46+
// Cleanup the home directory of the app
47+
env.t.Cleanup(func() {
48+
os.RemoveAll(filepath.Join(env.Home(), fmt.Sprintf(".%s", appName)))
49+
})
50+
51+
path := filepath.Join(root, appName)
52+
53+
_, statErr := os.Stat(filepath.Join(path, "x", "blog"))
54+
require.True(t, os.IsNotExist(statErr), "the default module should not be scaffolded")
55+
56+
env.EnsureAppIsSteady(path)
57+
}
58+
59+
60+
func TestGenerateAnAppWithWasm(t *testing.T) {
2761
var (
2862
env = newEnv(t)
2963
path = env.Scaffold("blog")
@@ -47,7 +81,7 @@ func TestGenerateAnAppWithWasmAndVerify(t *testing.T) {
4781
env.EnsureAppIsSteady(path)
4882
}
4983

50-
func TestGenerateAStargateAppWithEmptyModuleAndVerify(t *testing.T) {
84+
func TestGenerateAStargateAppWithEmptyModule(t *testing.T) {
5185
var (
5286
env = newEnv(t)
5387
path = env.Scaffold("blog")

integration/env_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ func (e env) Serve(msg, path, home, configPath string, options ...execOption) (o
199199
// EnsureAppIsSteady ensures that app living at the path can compile and its tests
200200
// are passing.
201201
func (e env) EnsureAppIsSteady(appPath string) {
202+
_, statErr := os.Stat(filepath.Join(appPath, "config.yml"))
203+
require.False(e.t, os.IsNotExist(statErr), "config.yml cannot be found")
204+
202205
e.Exec("make sure app is steady",
203206
step.NewSteps(step.New(
204207
step.Exec(gocmd.Name(), "test", "./..."),

starport/cmd/app.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ import (
99
"github.com/tendermint/starport/starport/services/scaffolder"
1010
)
1111

12+
const (
13+
flagAddressPrefix = "address-prefix"
14+
flagNoDefaultModule = "no-default-module"
15+
)
16+
1217
// NewApp creates new command named `app` to create Cosmos scaffolds customized
1318
// by the user given options.
1419
func NewApp() *cobra.Command {
@@ -19,7 +24,8 @@ func NewApp() *cobra.Command {
1924
Args: cobra.ExactArgs(1),
2025
RunE: appHandler,
2126
}
22-
c.Flags().String("address-prefix", "cosmos", "Address prefix")
27+
c.Flags().String(flagAddressPrefix, "cosmos", "Address prefix")
28+
c.Flags().Bool(flagNoDefaultModule, false, "Prevent scaffolding a default module in the app")
2329
return c
2430
}
2531

@@ -28,8 +34,9 @@ func appHandler(cmd *cobra.Command, args []string) error {
2834
defer s.Stop()
2935

3036
var (
31-
name = args[0]
32-
addressPrefix, _ = cmd.Flags().GetString("address-prefix")
37+
name = args[0]
38+
addressPrefix, _ = cmd.Flags().GetString(flagAddressPrefix)
39+
noDefaultModule, _ = cmd.Flags().GetBool(flagNoDefaultModule)
3340
)
3441

3542
sc, err := scaffolder.New("",
@@ -39,7 +46,7 @@ func appHandler(cmd *cobra.Command, args []string) error {
3946
return err
4047
}
4148

42-
appdir, err := sc.Init(placeholder.New(), name)
49+
appdir, err := sc.Init(placeholder.New(), name, noDefaultModule)
4350
if err != nil {
4451
return err
4552
}

starport/services/scaffolder/init.go

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var (
2828

2929
// Init initializes a new app with name and given options.
3030
// path is the relative path to the scaffoled app.
31-
func (s *Scaffolder) Init(tracer *placeholder.Tracer, name string) (path string, err error) {
31+
func (s *Scaffolder) Init(tracer *placeholder.Tracer, name string, noDefaultModule bool) (path string, err error) {
3232
pathInfo, err := gomodulepath.Parse(name)
3333
if err != nil {
3434
return "", err
@@ -40,7 +40,7 @@ func (s *Scaffolder) Init(tracer *placeholder.Tracer, name string) (path string,
4040
absRoot := filepath.Join(pwd, pathInfo.Root)
4141

4242
// create the project
43-
if err := s.generate(tracer, pathInfo, absRoot); err != nil {
43+
if err := s.generate(tracer, pathInfo, absRoot, noDefaultModule); err != nil {
4444
return "", err
4545
}
4646

@@ -56,7 +56,12 @@ func (s *Scaffolder) Init(tracer *placeholder.Tracer, name string) (path string,
5656
}
5757

5858
//nolint:interfacer
59-
func (s *Scaffolder) generate(tracer *placeholder.Tracer, pathInfo gomodulepath.Path, absRoot string) error {
59+
func (s *Scaffolder) generate(
60+
tracer *placeholder.Tracer,
61+
pathInfo gomodulepath.Path,
62+
absRoot string,
63+
noDefaultModule bool,
64+
) error {
6065
g, err := app.New(&app.Options{
6166
// generate application template
6267
ModulePath: pathInfo.RawPath,
@@ -79,23 +84,26 @@ func (s *Scaffolder) generate(tracer *placeholder.Tracer, pathInfo gomodulepath.
7984
}
8085

8186
// generate module template
82-
opts := &modulecreate.CreateOptions{
83-
ModuleName: pathInfo.Package, // App name
84-
ModulePath: pathInfo.RawPath,
85-
AppName: pathInfo.Package,
86-
OwnerName: owner(pathInfo.RawPath),
87-
IsIBC: false,
88-
}
89-
g, err = modulecreate.NewStargate(opts)
90-
if err != nil {
91-
return err
92-
}
93-
if err := run(genny.WetRunner(context.Background()), g); err != nil {
94-
return err
95-
}
96-
g = modulecreate.NewStargateAppModify(tracer, opts)
97-
if err := run(genny.WetRunner(context.Background()), g); err != nil {
98-
return err
87+
if !noDefaultModule {
88+
opts := &modulecreate.CreateOptions{
89+
ModuleName: pathInfo.Package, // App name
90+
ModulePath: pathInfo.RawPath,
91+
AppName: pathInfo.Package,
92+
OwnerName: owner(pathInfo.RawPath),
93+
IsIBC: false,
94+
}
95+
g, err = modulecreate.NewStargate(opts)
96+
if err != nil {
97+
return err
98+
}
99+
if err := run(genny.WetRunner(context.Background()), g); err != nil {
100+
return err
101+
}
102+
g = modulecreate.NewStargateAppModify(tracer, opts)
103+
if err := run(genny.WetRunner(context.Background()), g); err != nil {
104+
return err
105+
}
106+
99107
}
100108

101109
// generate the vue app.

0 commit comments

Comments
 (0)