Skip to content

Commit 62ae705

Browse files
authored
feat: add possibility to scaffold underscore package (#4880)
1 parent cd9e46a commit 62ae705

5 files changed

Lines changed: 28 additions & 5 deletions

File tree

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Changes
66

7+
- [#4880](https://github.com/ignite/cli/pull/4880) Add possibility to scaffold underscore package.
78
- [#4878](https://github.com/ignite/cli/pull/4878) Improve the `xast` package readability.
89

910
## [`v29.8.0`](https://github.com/ignite/cli/releases/tag/v29.8.0)

ignite/pkg/gomodulepath/gomodulepath.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,6 @@ func root(path string) string {
154154
}
155155

156156
func stripNonAlphaNumeric(name string) string {
157-
reg := regexp.MustCompile(`[^a-zA-Z0-9]+`)
157+
reg := regexp.MustCompile(`[^a-zA-Z0-9_]+`)
158158
return strings.ToLower(reg.ReplaceAllString(name, ""))
159159
}

ignite/pkg/gomodulepath/gomodulepath_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func TestParse(t *testing.T) {
6363
{
6464
name: "with underscore",
6565
rawpath: "github.com/a/b_c",
66-
path: Path{RawPath: "github.com/a/b_c", Root: "b_c", Package: "bc"},
66+
path: Path{RawPath: "github.com/a/b_c", Root: "b_c", Package: "b_c"},
6767
},
6868
{
6969
name: "with mixed case",
@@ -78,7 +78,7 @@ func TestParse(t *testing.T) {
7878
{
7979
name: "with a name containing underscore",
8080
rawpath: "a_b",
81-
path: Path{RawPath: "a_b", Root: "a_b", Package: "ab"},
81+
path: Path{RawPath: "a_b", Root: "a_b", Package: "a_b"},
8282
},
8383
{
8484
name: "with a name containing dash",
@@ -93,7 +93,7 @@ func TestParse(t *testing.T) {
9393
{
9494
name: "with a path containing underscore",
9595
rawpath: "a/b_c",
96-
path: Path{RawPath: "a/b_c", Root: "b_c", Package: "bc"},
96+
path: Path{RawPath: "a/b_c", Root: "b_c", Package: "b_c"},
9797
},
9898
{
9999
name: "with a path containing dash",

ignite/services/scaffolder/init.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/ignite/cli/v29/ignite/pkg/cliui"
1010
"github.com/ignite/cli/v29/ignite/pkg/errors"
1111
"github.com/ignite/cli/v29/ignite/pkg/gomodulepath"
12+
"github.com/ignite/cli/v29/ignite/pkg/multiformatname"
1213
"github.com/ignite/cli/v29/ignite/pkg/xgenny"
1314
"github.com/ignite/cli/v29/ignite/templates/app"
1415
"github.com/ignite/cli/v29/ignite/templates/field"
@@ -119,8 +120,13 @@ func generate(
119120
}
120121

121122
if !noDefaultModule {
123+
moduleName, err := multiformatname.NewName(pathInfo.Package, multiformatname.NoNumber)
124+
if err != nil {
125+
return smc, err
126+
}
127+
122128
opts := &modulecreate.CreateOptions{
123-
ModuleName: pathInfo.Package, // App name
129+
ModuleName: moduleName.LowerCase, // App module
124130
ModulePath: pathInfo.RawPath,
125131
AppName: pathInfo.Package,
126132
ProtoDir: protoDir,

integration/app/cmd_app_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,19 @@ func TestGenerateAnAppWithDefaultDenom(t *testing.T) {
216216

217217
app.EnsureSteady()
218218
}
219+
220+
func TestScaffoldModuleWithUnderscoreAppName(t *testing.T) {
221+
var (
222+
env = envtest.New(t)
223+
app = env.ScaffoldApp("github.com/test/space_chain")
224+
)
225+
226+
app.Scaffold(
227+
"create a module in app with underscore name",
228+
false,
229+
"module",
230+
"f_o_o",
231+
)
232+
233+
app.EnsureSteady()
234+
}

0 commit comments

Comments
 (0)