-
Notifications
You must be signed in to change notification settings - Fork 547
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a `--skip-proto` flag to `s chain` to speed up scaffolding. Advanced user can enjoy faster scaffolding time but still need to run `ignite chain serve` or `ignite chain build` afterwards. (cherry picked from commit c05237b) # Conflicts: # ignite/cmd/scaffold_chain.go # ignite/services/scaffolder/configs.go # ignite/services/scaffolder/init.go # ignite/services/scaffolder/params.go
- Loading branch information
1 parent
5a8b939
commit 5d65278
Showing
12 changed files
with
216 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package scaffolder | ||
|
||
import ( | ||
"context" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/gobuffalo/genny/v2" | ||
|
||
"github.com/ignite/cli/v28/ignite/pkg/cache" | ||
"github.com/ignite/cli/v28/ignite/pkg/errors" | ||
"github.com/ignite/cli/v28/ignite/pkg/goanalysis" | ||
"github.com/ignite/cli/v28/ignite/pkg/multiformatname" | ||
"github.com/ignite/cli/v28/ignite/pkg/placeholder" | ||
"github.com/ignite/cli/v28/ignite/pkg/xgenny" | ||
"github.com/ignite/cli/v28/ignite/templates/field" | ||
modulecreate "github.com/ignite/cli/v28/ignite/templates/module/create" | ||
) | ||
|
||
// CreateConfigs creates a new configs in the scaffolded module. | ||
func (s Scaffolder) CreateConfigs( | ||
ctx context.Context, | ||
cacheStorage cache.Storage, | ||
tracer *placeholder.Tracer, | ||
moduleName string, | ||
configs ...string, | ||
) (sm xgenny.SourceModification, err error) { | ||
appName := s.modpath.Package | ||
// If no module is provided, we add the type to the app's module | ||
if moduleName == "" { | ||
moduleName = s.modpath.Package | ||
} | ||
mfName, err := multiformatname.NewName(moduleName, multiformatname.NoNumber) | ||
if err != nil { | ||
return sm, err | ||
} | ||
moduleName = mfName.LowerCase | ||
|
||
// Check if the module already exist | ||
ok, err := moduleExists(s.path, moduleName) | ||
if err != nil { | ||
return sm, err | ||
} | ||
if !ok { | ||
return sm, errors.Errorf("the module %v not exist", moduleName) | ||
} | ||
|
||
if err := checkConfigCreated(s.path, appName, moduleName, configs); err != nil { | ||
return sm, err | ||
} | ||
|
||
// Parse config with the associated type | ||
configsFields, err := field.ParseFields(configs, checkForbiddenTypeIndex) | ||
if err != nil { | ||
return sm, err | ||
} | ||
|
||
opts := modulecreate.ConfigsOptions{ | ||
ModuleName: moduleName, | ||
Configs: configsFields, | ||
AppName: s.modpath.Package, | ||
AppPath: s.path, | ||
} | ||
|
||
g, err := modulecreate.NewModuleConfigs(opts) | ||
if err != nil { | ||
return sm, err | ||
} | ||
gens := []*genny.Generator{g} | ||
|
||
sm, err = xgenny.RunWithValidation(tracer, gens...) | ||
if err != nil { | ||
return sm, err | ||
} | ||
|
||
return sm, finish(ctx, cacheStorage, opts.AppPath, s.modpath.RawPath, false) | ||
} | ||
|
||
// checkConfigCreated checks if the config has been already created. | ||
func checkConfigCreated(appPath, appName, moduleName string, configs []string) (err error) { | ||
path := filepath.Join(appPath, "api", appName, moduleName, "module") | ||
ok, err := goanalysis.HasAnyStructFieldsInPkg(path, "Module", configs) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if ok { | ||
return errors.Errorf( | ||
"duplicated configs (%s) module %s", | ||
strings.Join(configs, " "), | ||
moduleName, | ||
) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package scaffolder | ||
|
||
import ( | ||
"context" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/gobuffalo/genny/v2" | ||
|
||
"github.com/ignite/cli/v28/ignite/pkg/cache" | ||
"github.com/ignite/cli/v28/ignite/pkg/errors" | ||
"github.com/ignite/cli/v28/ignite/pkg/goanalysis" | ||
"github.com/ignite/cli/v28/ignite/pkg/multiformatname" | ||
"github.com/ignite/cli/v28/ignite/pkg/placeholder" | ||
"github.com/ignite/cli/v28/ignite/pkg/xgenny" | ||
"github.com/ignite/cli/v28/ignite/templates/field" | ||
modulecreate "github.com/ignite/cli/v28/ignite/templates/module/create" | ||
) | ||
|
||
// CreateParams creates a new params in the scaffolded module. | ||
func (s Scaffolder) CreateParams( | ||
ctx context.Context, | ||
cacheStorage cache.Storage, | ||
tracer *placeholder.Tracer, | ||
moduleName string, | ||
params ...string, | ||
) (sm xgenny.SourceModification, err error) { | ||
// If no module is provided, we add the type to the app's module | ||
if moduleName == "" { | ||
moduleName = s.modpath.Package | ||
} | ||
mfName, err := multiformatname.NewName(moduleName, multiformatname.NoNumber) | ||
if err != nil { | ||
return sm, err | ||
} | ||
moduleName = mfName.LowerCase | ||
|
||
// Check if the module already exist | ||
ok, err := moduleExists(s.path, moduleName) | ||
if err != nil { | ||
return sm, err | ||
} | ||
if !ok { | ||
return sm, errors.Errorf("the module %v not exist", moduleName) | ||
} | ||
|
||
if err := checkParamCreated(s.path, moduleName, params); err != nil { | ||
return sm, err | ||
} | ||
|
||
// Parse params with the associated type | ||
paramsFields, err := field.ParseFields(params, checkForbiddenTypeIndex) | ||
if err != nil { | ||
return sm, err | ||
} | ||
|
||
opts := modulecreate.ParamsOptions{ | ||
ModuleName: moduleName, | ||
Params: paramsFields, | ||
AppName: s.modpath.Package, | ||
AppPath: s.path, | ||
} | ||
|
||
g, err := modulecreate.NewModuleParam(opts) | ||
if err != nil { | ||
return sm, err | ||
} | ||
gens := []*genny.Generator{g} | ||
|
||
sm, err = xgenny.RunWithValidation(tracer, gens...) | ||
if err != nil { | ||
return sm, err | ||
} | ||
|
||
return sm, finish(ctx, cacheStorage, opts.AppPath, s.modpath.RawPath, false) | ||
} | ||
|
||
// checkParamCreated checks if the parameter has been already created. | ||
func checkParamCreated(appPath, moduleName string, params []string) error { | ||
path := filepath.Join(appPath, "x", moduleName, "types") | ||
ok, err := goanalysis.HasAnyStructFieldsInPkg(path, "Params", params) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if ok { | ||
return errors.Errorf( | ||
"duplicated params (%s) module %s", | ||
strings.Join(params, " "), | ||
moduleName, | ||
) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters