Skip to content

Commit

Permalink
fix ignite
Browse files Browse the repository at this point in the history
  • Loading branch information
oren-lava committed Jun 20, 2024
1 parent f3ab0d7 commit 4508873
Show file tree
Hide file tree
Showing 17 changed files with 60 additions and 53 deletions.
6 changes: 3 additions & 3 deletions ignite/cmd/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,9 @@ func configMigrationPreRunHandler(cmd *cobra.Command, session *cliui.Session) (e
}

// Confirm before migrating the config if there are uncommitted changes
if err := confirmWhenUncommittedChanges(session, appPath); err != nil {
return err
}
// if err := confirmWhenUncommittedChanges(session, appPath); err != nil {
// return err
// }
} else {
session.Printf("%s %s\n", icons.Info, colors.Infof(msgMigration, version, chainconfig.LatestVersion))
}
Expand Down
45 changes: 20 additions & 25 deletions ignite/cmd/scaffold.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
package ignitecmd

import (
"errors"

"github.com/manifoldco/promptui"
"github.com/spf13/cobra"
flag "github.com/spf13/pflag"

"github.com/ignite/cli/ignite/pkg/cliui"
"github.com/ignite/cli/ignite/pkg/placeholder"
"github.com/ignite/cli/ignite/pkg/xgit"
"github.com/ignite/cli/ignite/services/scaffolder"
)

Expand Down Expand Up @@ -176,34 +172,33 @@ func gitChangesConfirmPreRunHandler(cmd *cobra.Command, _ []string) error {
return nil
}

appPath := flagGetPath(cmd)
session := cliui.New()

defer session.End()

return confirmWhenUncommittedChanges(session, appPath)
}

func confirmWhenUncommittedChanges(session *cliui.Session, appPath string) error {
cleanState, err := xgit.AreChangesCommitted(appPath)
if err != nil {
return err
}

if !cleanState {
session.Println(msgCommitPrefix)
if err := session.AskConfirm(msgCommitPrompt); err != nil {
if errors.Is(err, promptui.ErrAbort) {
return errors.New("No")
}

return err
}
}

return nil
}

// func confirmWhenUncommittedChanges(session *cliui.Session, appPath string) error {
// cleanState, err := xgit.AreChangesCommitted(appPath)
// if err != nil {
// return err
// }

// if !cleanState {
// session.Println(msgCommitPrefix)
// if err := session.AskConfirm(msgCommitPrompt); err != nil {
// if errors.Is(err, promptui.ErrAbort) {
// return errors.New("No")
// }

// return err
// }
// }

// return nil
// }

func flagSetScaffoldType() *flag.FlagSet {
f := flag.NewFlagSet("", flag.ContinueOnError)
f.String(flagModule, "", "specify which module to generate code in")
Expand Down
2 changes: 1 addition & 1 deletion ignite/config/chain/base/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func DefaultConfig() Config {
return Config{
Build: Build{
Proto: Proto{
Path: "proto",
Path: "proto/lavanet",
ThirdPartyPaths: []string{"third_party/proto", "proto_vendor"},
},
},
Expand Down
11 changes: 11 additions & 0 deletions ignite/pkg/xgenny/xgenny.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@ func Transformer(ctx *plush.Context) genny.Transformer {
if err != nil {
return f, errors.Wrap(err, f.Name())
}
var fileName string
var content string
if !strings.Contains(f.Name(), "proto/lavanet") && strings.Contains(f.Name(), ".proto") {
orig := f.Name()
_ = orig
fileName = strings.Replace(f.Name(), "proto/", "proto/lavanet/", -1)
content = strings.Replace(s, "lava.", "lavanet.lava.", -1)
}
if fileName != "" {
return genny.NewFileS(fileName, content), nil
}
return genny.NewFileS(f.Name(), s), nil
})
t.StripExt = true
Expand Down
2 changes: 1 addition & 1 deletion ignite/services/chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var appBackendSourceWatchPaths = []string{
"app",
"cmd",
"x",
"proto",
"proto/lavanet",
"third_party",
}

Expand Down
2 changes: 1 addition & 1 deletion ignite/services/scaffolder/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const (
componentQuery = "query"
componentPacket = "packet"

protoFolder = "proto"
protoFolder = "proto/lavanet"
)

// checkComponentValidity performs various checks common to all components to verify if it can be scaffolded.
Expand Down
2 changes: 1 addition & 1 deletion ignite/services/scaffolder/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func supportMsgServer(
// isMsgServerDefined checks if the module uses the MsgServer convention for transactions
// this is checked by verifying the existence of the tx.proto file.
func isMsgServerDefined(appPath, appName, moduleName string) (bool, error) {
txProto, err := filepath.Abs(filepath.Join(appPath, "proto", appName, moduleName, "tx.proto"))
txProto, err := filepath.Abs(filepath.Join(appPath, "proto/lavanet", appName, moduleName, "tx.proto"))
if err != nil {
return false, err
}
Expand Down
7 changes: 4 additions & 3 deletions ignite/services/scaffolder/scaffolder.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ func finish(ctx context.Context, cacheStorage cache.Storage, path, gomodPath str
}

func protoc(ctx context.Context, cacheStorage cache.Storage, projectPath, gomodPath string) error {
if err := cosmosgen.InstallDepTools(ctx, projectPath); err != nil {
return err
}
// if err := cosmosgen.InstallDepTools(ctx, projectPath); err != nil {
// return err
// }

confpath, err := chainconfig.LocateDefault(projectPath)
if err != nil {
Expand All @@ -87,6 +87,7 @@ func protoc(ctx context.Context, cacheStorage cache.Storage, projectPath, gomodP
return err
}

conf.Build.Proto.Path = "proto/lavanet"
options := []cosmosgen.Option{
cosmosgen.WithGoGeneration(gomodPath),
cosmosgen.IncludeDirs(conf.Build.Proto.ThirdPartyPaths),
Expand Down
4 changes: 2 additions & 2 deletions ignite/templates/ibc/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func moduleOracleModify(replacer placeholder.Replacer, opts *OracleOptions) genn
// Deprecated: This function is no longer maintained.
func protoQueryOracleModify(replacer placeholder.Replacer, opts *OracleOptions) genny.RunFn {
return func(r *genny.Runner) error {
path := filepath.Join(opts.AppPath, "proto", opts.AppName, opts.ModuleName, "query.proto")
path := filepath.Join(opts.AppPath, "proto/lavanet", opts.AppName, opts.ModuleName, "query.proto")
f, err := r.Disk.Find(path)
if err != nil {
return err
Expand Down Expand Up @@ -172,7 +172,7 @@ message QueryLast%[2]vIdResponse {int64 request_id = 1;}
// Deprecated: This function is no longer maintained.
func protoTxOracleModify(replacer placeholder.Replacer, opts *OracleOptions) genny.RunFn {
return func(r *genny.Runner) error {
path := filepath.Join(opts.AppPath, "proto", opts.AppName, opts.ModuleName, "tx.proto")
path := filepath.Join(opts.AppPath, "proto/lavanet", opts.AppName, opts.ModuleName, "tx.proto")
f, err := r.Disk.Find(path)
if err != nil {
return err
Expand Down
8 changes: 4 additions & 4 deletions ignite/templates/ibc/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func moduleModify(replacer placeholder.Replacer, opts *PacketOptions) genny.RunF
// - Existence of a Oneof field named 'packet'.
func protoModify(opts *PacketOptions) genny.RunFn {
return func(r *genny.Runner) error {
path := filepath.Join(opts.AppPath, "proto", opts.AppName, opts.ModuleName, "packet.proto")
path := filepath.Join(opts.AppPath, "proto/lavanet", opts.AppName, opts.ModuleName, "packet.proto")
f, err := r.Disk.Find(path)
if err != nil {
return err
Expand Down Expand Up @@ -245,7 +245,7 @@ func protoModify(opts *PacketOptions) genny.RunFn {
protoImports = append(protoImports, protoutil.NewImport(imp))
}
for _, f := range append(opts.Fields.Custom(), opts.AckFields.Custom()...) {
protopath := fmt.Sprintf("%[1]v/%[2]v/%[3]v.proto", opts.AppName, opts.ModuleName, f)
protopath := fmt.Sprintf("lavanet/%[1]v/%[2]v/%[3]v.proto", opts.AppName, opts.ModuleName, f)
protoImports = append(protoImports, protoutil.NewImport(protopath))
}
if err := protoutil.AddImports(protoFile, true, protoImports...); err != nil {
Expand Down Expand Up @@ -287,7 +287,7 @@ func eventModify(replacer placeholder.Replacer, opts *PacketOptions) genny.RunFn
// elements in the file.
func protoTxModify(opts *PacketOptions) genny.RunFn {
return func(r *genny.Runner) error {
path := filepath.Join(opts.AppPath, "proto", opts.AppName, opts.ModuleName, "tx.proto")
path := filepath.Join(opts.AppPath, "proto/lavanet", opts.AppName, opts.ModuleName, "tx.proto")
f, err := r.Disk.Find(path)
if err != nil {
return err
Expand Down Expand Up @@ -329,7 +329,7 @@ func protoTxModify(opts *PacketOptions) genny.RunFn {
protoImports = append(protoImports, protoutil.NewImport(imp))
}
for _, f := range opts.Fields.Custom() {
protopath := fmt.Sprintf("%[1]v/%[2]v/%[3]v.proto", opts.AppName, opts.ModuleName, f)
protopath := fmt.Sprintf("lavanet/%[1]v/%[2]v/%[3]v.proto", opts.AppName, opts.ModuleName, f)
protoImports = append(protoImports, protoutil.NewImport(protopath))
}
if err := protoutil.AddImports(protoFile, true, protoImports...); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions ignite/templates/message/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func NewGenerator(replacer placeholder.Replacer, opts *Options) (*genny.Generato
// - A service named "Msg" to exist in the proto file, it appends the RPCs inside it.
func protoTxRPCModify(opts *Options) genny.RunFn {
return func(r *genny.Runner) error {
path := filepath.Join(opts.AppPath, "proto", opts.AppName, opts.ModuleName, "tx.proto")
path := filepath.Join(opts.AppPath, "proto/lavanet", opts.AppName, opts.ModuleName, "tx.proto")
f, err := r.Disk.Find(path)
if err != nil {
return err
Expand All @@ -111,7 +111,7 @@ func protoTxRPCModify(opts *Options) genny.RunFn {

func protoTxMessageModify(opts *Options) genny.RunFn {
return func(r *genny.Runner) error {
path := filepath.Join(opts.AppPath, "proto", opts.AppName, opts.ModuleName, "tx.proto")
path := filepath.Join(opts.AppPath, "proto/lavanet", opts.AppName, opts.ModuleName, "tx.proto")
f, err := r.Disk.Find(path)
if err != nil {
return err
Expand Down Expand Up @@ -141,7 +141,7 @@ func protoTxMessageModify(opts *Options) genny.RunFn {
protoImports = append(protoImports, protoutil.NewImport(imp))
}
for _, f := range append(opts.ResFields.Custom(), opts.Fields.Custom()...) {
protoPath := fmt.Sprintf("%[1]v/%[2]v/%[3]v.proto", opts.AppName, opts.ModuleName, f)
protoPath := fmt.Sprintf("lavanet/%[1]v/%[2]v/%[3]v.proto", opts.AppName, opts.ModuleName, f)
protoImports = append(protoImports, protoutil.NewImport(protoPath))
}
if err = protoutil.AddImports(protoFile, true, protoImports...); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion ignite/templates/module/create/ibc.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func genesisTypesModify(replacer placeholder.Replacer, opts *CreateOptions) genn
// - Existence of a message named 'GenesisState' in genesis.proto.
func genesisProtoModify(opts *CreateOptions) genny.RunFn {
return func(r *genny.Runner) error {
path := filepath.Join(opts.AppPath, "proto", opts.AppName, opts.ModuleName, "genesis.proto")
path := filepath.Join(opts.AppPath, "proto/lavanet", opts.AppName, opts.ModuleName, "genesis.proto")
f, err := r.Disk.Find(path)
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions ignite/templates/query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func NewGenerator(replacer placeholder.Replacer, opts *Options) (*genny.Generato
// - Existence of a service with name "Query" since that is where the RPCs will be added.
func protoQueryModify(opts *Options) genny.RunFn {
return func(r *genny.Runner) error {
path := filepath.Join(opts.AppPath, "proto", opts.AppName, opts.ModuleName, "query.proto")
path := filepath.Join(opts.AppPath, "proto/lavanet", opts.AppName, opts.ModuleName, "query.proto")
f, err := r.Disk.Find(path)
if err != nil {
return err
Expand Down Expand Up @@ -132,7 +132,7 @@ func protoQueryModify(opts *Options) genny.RunFn {
protoImports = append(protoImports, protoutil.NewImport(imp))
}
for _, f := range append(opts.ResFields.Custom(), opts.ReqFields.Custom()...) {
protopath := fmt.Sprintf("%[1]v/%[2]v/%[3]v.proto", opts.AppName, opts.ModuleName, f)
protopath := fmt.Sprintf("lavanet/%[1]v/%[2]v/%[3]v.proto", opts.AppName, opts.ModuleName, f)
protoImports = append(protoImports, protoutil.NewImport(protopath))
}
if err = protoutil.AddImports(protoFile, true, protoImports...); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion ignite/templates/typed/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func protoTxModify(opts *typed.Options) genny.RunFn {
protoImports = append(protoImports, protoutil.NewImport(imp))
}
for _, f := range opts.Fields.Custom() {
protoPath := fmt.Sprintf("%[1]v/%[2]v/%[3]v.proto", opts.AppName, opts.ModuleName, f)
protoPath := fmt.Sprintf("lavanet/%[1]v/%[2]v/%[3]v.proto", opts.AppName, opts.ModuleName, f)
protoImports = append(protoImports, protoutil.NewImport(protoPath))
}
// we already know an import exists, pass false for fallback.
Expand Down
4 changes: 2 additions & 2 deletions ignite/templates/typed/map/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func protoRPCModify(opts *typed.Options) genny.RunFn {
protoImports = append(protoImports, protoutil.NewImport(imp))
}
for _, f := range opts.Fields.Custom() {
protoPath := fmt.Sprintf("%[1]v/%[2]v/%[3]v.proto", opts.AppName, opts.ModuleName, f)
protoPath := fmt.Sprintf("lavanet/%[1]v/%[2]v/%[3]v.proto", opts.AppName, opts.ModuleName, f)
protoImports = append(protoImports, protoutil.NewImport(protoPath))
}
// we already know an import exists, pass false for fallback.
Expand Down Expand Up @@ -539,7 +539,7 @@ func protoTxModify(opts *typed.Options) genny.RunFn {
protoImports = append(protoImports, protoutil.NewImport(imp))
}
for _, f := range opts.Fields.Custom() {
protoPath := fmt.Sprintf("%[1]v/%[2]v/%[3]v.proto", opts.AppName, opts.ModuleName, f)
protoPath := fmt.Sprintf("lavanet/%[1]v/%[2]v/%[3]v.proto", opts.AppName, opts.ModuleName, f)
protoImports = append(protoImports, protoutil.NewImport(protoPath))
}
// we already know an import exists, pass false for fallback.
Expand Down
4 changes: 2 additions & 2 deletions ignite/templates/typed/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ func (opts *Options) Validate() error {

// ProtoPath returns the path to the proto folder within the generated app.
func (opts *Options) ProtoPath(fname string) string {
return filepath.Join(opts.AppPath, "proto", opts.AppName, opts.ModuleName, fname)
return filepath.Join(opts.AppPath, "proto/lavanet", opts.AppName, opts.ModuleName, fname)
}

// ProtoTypeImport Return the protobuf import statement for this type.
func (opts *Options) ProtoTypeImport() *proto.Import {
return protoutil.NewImport(fmt.Sprintf("%s/%s/%s.proto", opts.AppName, opts.ModuleName, opts.TypeName.Snake))
return protoutil.NewImport(fmt.Sprintf("lavanet/%s/%s/%s.proto", opts.AppName, opts.ModuleName, opts.TypeName.Snake))
}
2 changes: 1 addition & 1 deletion ignite/templates/typed/singleton/singleton.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ func protoTxModify(opts *typed.Options) genny.RunFn {
protoImports = append(protoImports, protoutil.NewImport(imp))
}
for _, f := range opts.Fields.Custom() {
protoPath := fmt.Sprintf("%[1]v/%[2]v/%[3]v.proto", opts.AppName, opts.ModuleName, f)
protoPath := fmt.Sprintf("lavanet/%[1]v/%[2]v/%[3]v.proto", opts.AppName, opts.ModuleName, f)
protoImports = append(protoImports, protoutil.NewImport(protoPath))
}
// we already know an import exists, pass false for fallback.
Expand Down

0 comments on commit 4508873

Please sign in to comment.