From 97b8c24ed21053b2b6777160aff418f971229a66 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 8 Mar 2024 17:38:26 +0100 Subject: [PATCH 1/3] build: remove flatpak (#4005) ref: https://github.com/ignite/cli/pull/3945#issuecomment-1985857124 Ignite is available on Homebrew (Linux + macOS): https://formulae.brew.sh/formula/ignite#default And the snap store (Linux): https://snapcraft.io/ignite We have CI configured already to publish releases for both of them. I as well added the Flatpak support, but it is harder to release automatically, and we already have two packages managers for linux. Imho we should just remove it. --- Makefile | 4 -- packaging/.gitignore | 1 - packaging/flatpak/com.ignite.Ignite.yml | 33 ------------- packaging/flatpak/ignite.desktop | 10 ---- packaging/flatpak/ignite.metainfo.xml | 61 ------------------------- packaging/flatpak/logo.svg | 15 ------ packaging/readme.md | 19 -------- 7 files changed, 143 deletions(-) delete mode 100644 packaging/flatpak/com.ignite.Ignite.yml delete mode 100644 packaging/flatpak/ignite.desktop delete mode 100644 packaging/flatpak/ignite.metainfo.xml delete mode 100644 packaging/flatpak/logo.svg diff --git a/Makefile b/Makefile index c48a7c6ab2..79cf248443 100644 --- a/Makefile +++ b/Makefile @@ -24,10 +24,6 @@ build: snapcraft: @sed -i 's/{{version}}/'$(version)'/' packaging/snap/snapcraft.yaml -## prepare flatpak manifest for release -flatpak: - @sed -i 's/{{version}}/'$(version)'/' packaging/flatpak/com.ignite.Ignite.yml - ## mocks: generate mocks mocks: @echo Generating mocks diff --git a/packaging/.gitignore b/packaging/.gitignore index 0ec52ff128..2163481bf2 100644 --- a/packaging/.gitignore +++ b/packaging/.gitignore @@ -1,4 +1,3 @@ -.flatpak-builder build-dir repo *.snap \ No newline at end of file diff --git a/packaging/flatpak/com.ignite.Ignite.yml b/packaging/flatpak/com.ignite.Ignite.yml deleted file mode 100644 index dcc831ad49..0000000000 --- a/packaging/flatpak/com.ignite.Ignite.yml +++ /dev/null @@ -1,33 +0,0 @@ -app-id: com.ignite.Ignite -runtime: org.freedesktop.Platform -runtime-version: "23.08" -sdk: org.freedesktop.Sdk -sdk-extensions: - - org.freedesktop.Sdk.Extension.golang -command: ignite - -finish-args: - - --share=network - - --device=all - - --filesystem=host -build-options: - append-path: /usr/lib/sdk/golang/bin - build-args: - - --share=network - env: - - GOBIN=/app/bin - - GOROOT=/usr/lib/sdk/golang - -modules: - - name: ignite - buildsystem: simple - build-commands: - - $GOROOT/bin/go build -mod=readonly -o ignt ./ignite/cmd/ignite - - install -Dm00755 ignt $FLATPAK_DEST/bin/ignite - - install -Dm00644 packaging/flatpak/logo.svg $FLATPAK_DEST/share/icons/hicolor/scalable/apps/ignite.svg - - install -Dm00644 packaging/flatpak/ignite.desktop $FLATPAK_DEST/share/applications/ignite.desktop - - install -Dm00644 packaging/flatpak/ignite.metainfo.xml $FLATPAK_DEST/share/metainfo/ignite.metainfo.xml - sources: - - type: git - url: "https://github.com/ignite/cli.git" - tag: "v{{version}}" diff --git a/packaging/flatpak/ignite.desktop b/packaging/flatpak/ignite.desktop deleted file mode 100644 index 3ecb57280a..0000000000 --- a/packaging/flatpak/ignite.desktop +++ /dev/null @@ -1,10 +0,0 @@ -[Desktop Entry] -Type=Application - -Name=ignite -Comment=Ignite CLI is the all-in-one platform to build, launch, and maintain any crypto application on a sovereign and secured blockchain -Categories=Utility;Development;Network - -Icon=ignite -Exec=ignite -Terminal=true \ No newline at end of file diff --git a/packaging/flatpak/ignite.metainfo.xml b/packaging/flatpak/ignite.metainfo.xml deleted file mode 100644 index 9f2ec83586..0000000000 --- a/packaging/flatpak/ignite.metainfo.xml +++ /dev/null @@ -1,61 +0,0 @@ - - - com.ignite.Ignite - - Ignite CLI - Ignite - - Ignite CLI is the all-in-one platform to build, launch, and maintain any crypto - application on a sovereign and secured blockchain. - - - Development - - - Apache - Apache - - - ignite - cosmos - cosmos-sdk - blockchain - development - tendermint - - - - keyboard - - - -

Ignite CLI offers everything you need to build, test, and launch your blockchain with a - decentralized worldwide community.

-

Ignite CLI is built on top of Cosmos SDK, the world's most popular blockchain framework.

-

Ignite CLI accelerates chain development by scaffolding everything you need so you can focus - on business logic.

-
- - ignite.desktop - - - https://raw.githubusercontent.com/ignite/cli/v0.27.1/assets/ignite-cli.png - How it works - - - - https://github.com/ignite/cli/issues - https://github.com/ignite/cli - - - - - - -

Ignite CLI v28.0.0 adds support for Cosmos SDK Eden (v0.50)

-
- https://github.com/ignite/cli/releases/tag/v28.0.0 -
-
- -
\ No newline at end of file diff --git a/packaging/flatpak/logo.svg b/packaging/flatpak/logo.svg deleted file mode 100644 index 46a0ffa303..0000000000 --- a/packaging/flatpak/logo.svg +++ /dev/null @@ -1,15 +0,0 @@ - - - - - diff --git a/packaging/readme.md b/packaging/readme.md index 77b25a7b9b..371ae8608e 100644 --- a/packaging/readme.md +++ b/packaging/readme.md @@ -2,25 +2,6 @@ Ignite CLI is distributed on multiple platforms and package managers. This document describes how to package and distribute Ignite CLI. -## Flatpak - -Read the folowing resources to understand Flatpak. - -* -* - -```bash -cd packaging/flatpak -sudo apt install flatpak-builder -flatpak install org.freedesktop.Platform//23.08 org.freedesktop.Sdk//23.08 org.freedesktop.Sdk.Extension.golang//23.08 -flatpak-builder build-dir com.ignite.Ignite.yml --force-clean -flatpak-builder --user --install--force-clean --repo=repo build-dir com.ignite.Ignite.yml -flatpak run com.ignite.Ignite -``` - -The Flatpak is published at . -The update process is done manually at at the moment. At each release, edit `com.ignite.Ignite.yml` and the metainfo file to update the version. - ## Snap Read the folowing resources to understand Snap. From 59400a520fb3fc4a67799a54df39705c91e4374a Mon Sep 17 00:00:00 2001 From: Danilo Pantani Date: Fri, 8 Mar 2024 16:55:03 -0300 Subject: [PATCH 2/3] feat: remove all import placeholders using the `xast` pkg (#4004) * remove all import placeholders * add changelog * remove unused placeholders * fix wrong import path * improve readbility * remove keeper definition placeholder --------- Co-authored-by: Pantani --- changelog.md | 1 + .../testdata/modules/app_config/app_config.go | 1 - .../app/testdata/modules/spn/app.go | 1 - .../module/testdata/earth/app/app_config.go | 1 - ignite/pkg/xast/import.go | 35 +++++++++- ignite/pkg/xast/import_test.go | 38 +++++------ .../app/files-minimal/app/app.go.plush | 4 +- .../app/files-minimal/app/app_config.go.plush | 2 - ignite/templates/app/files/app/app.go.plush | 4 +- .../app/files/app/app_config.go.plush | 2 - ignite/templates/app/files/app/ibc.go.plush | 2 - ignite/templates/ibc/placeholders.go | 12 +--- ignite/templates/message/placeholders.go | 1 - ignite/templates/module/create/base.go | 65 +++++++++++++------ .../x/{{moduleName}}/types/genesis.go.plush | 4 -- ignite/templates/module/create/ibc.go | 31 ++++++--- ignite/templates/module/placeholders.go | 4 -- ignite/templates/typed/genesis.go | 22 ------- ignite/templates/typed/list/genesis.go | 9 +-- ignite/templates/typed/map/map.go | 9 +-- ignite/templates/typed/placeholders.go | 2 - ignite/templates/typed/singleton/singleton.go | 4 +- 22 files changed, 134 insertions(+), 120 deletions(-) diff --git a/changelog.md b/changelog.md index 6a5c65c6c5..617ab6854e 100644 --- a/changelog.md +++ b/changelog.md @@ -8,6 +8,7 @@ - [#3770](https://github.com/ignite/cli/pull/3770) Add `scaffold configs` and `scaffold params` commands - [#3985](https://github.com/ignite/cli/pull/3985) Make some `cmd` pkg functions public - [#3967](https://github.com/ignite/cli/issues/3967) Add HD wallet parameters `address index` and `account number` to the chain account config +- [#4004](https://github.com/ignite/cli/pull/4004) Remove all import placeholders using the `xast` pkg ### Changes diff --git a/ignite/pkg/cosmosanalysis/app/testdata/modules/app_config/app_config.go b/ignite/pkg/cosmosanalysis/app/testdata/modules/app_config/app_config.go index 42e35eaa42..1e9aca5a9e 100644 --- a/ignite/pkg/cosmosanalysis/app/testdata/modules/app_config/app_config.go +++ b/ignite/pkg/cosmosanalysis/app/testdata/modules/app_config/app_config.go @@ -74,7 +74,6 @@ import ( marsmodulev1 "github.com/ignite/mars/api/mars/mars/module" _ "github.com/ignite/mars/x/mars" // import for side-effects marsmoduletypes "github.com/ignite/mars/x/mars/types" - // this line is used by starport scaffolding # stargate/app/moduleImport ) var ( diff --git a/ignite/pkg/cosmosanalysis/app/testdata/modules/spn/app.go b/ignite/pkg/cosmosanalysis/app/testdata/modules/spn/app.go index 40070dd24f..0da49006f5 100644 --- a/ignite/pkg/cosmosanalysis/app/testdata/modules/spn/app.go +++ b/ignite/pkg/cosmosanalysis/app/testdata/modules/spn/app.go @@ -125,7 +125,6 @@ import ( "github.com/tendermint/spn/x/reward" rewardkeeper "github.com/tendermint/spn/x/reward/keeper" rewardtypes "github.com/tendermint/spn/x/reward/types" - // this line is used by starport scaffolding # stargate/app/moduleImport ) const ( diff --git a/ignite/pkg/cosmosanalysis/module/testdata/earth/app/app_config.go b/ignite/pkg/cosmosanalysis/module/testdata/earth/app/app_config.go index 8ff441e81b..7f50257e85 100644 --- a/ignite/pkg/cosmosanalysis/module/testdata/earth/app/app_config.go +++ b/ignite/pkg/cosmosanalysis/module/testdata/earth/app/app_config.go @@ -77,7 +77,6 @@ import ( marsmodulev1 "github.com/tendermint/mars/api/mars/mars/module" _ "github.com/tendermint/mars/x/mars" // import for side-effects marsmoduletypes "github.com/tendermint/mars/x/mars/types" - // this line is used by starport scaffolding # stargate/app/moduleImport ) var ( diff --git a/ignite/pkg/xast/import.go b/ignite/pkg/xast/import.go index 08942c5bb5..0fb57271b3 100644 --- a/ignite/pkg/xast/import.go +++ b/ignite/pkg/xast/import.go @@ -27,17 +27,50 @@ type ( } ) +// WithLastImport add a new import int the end. +func WithLastImport(repo string) ImportOptions { + return func(c *importOpts) { + c.imports = append(c.imports, imp{ + repo: repo, + name: "", + index: -1, + }) + } +} + // WithImport add a new import. If the index is -1 will append in the end of the imports. -func WithImport(repo, name string, index int) ImportOptions { +func WithImport(repo string, index int) ImportOptions { return func(c *importOpts) { c.imports = append(c.imports, imp{ repo: repo, + name: "", + index: index, + }) + } +} + +// WithNamedImport add a new import with name. If the index is -1 will append in the end of the imports. +func WithNamedImport(name, repo string, index int) ImportOptions { + return func(c *importOpts) { + c.imports = append(c.imports, imp{ name: name, + repo: repo, index: index, }) } } +// WithLastNamedImport add a new import with name in the end of the imports. +func WithLastNamedImport(name, repo string) ImportOptions { + return func(c *importOpts) { + c.imports = append(c.imports, imp{ + name: name, + repo: repo, + index: -1, + }) + } +} + func newImportOptions() importOpts { return importOpts{ imports: make([]imp, 0), diff --git a/ignite/pkg/xast/import_test.go b/ignite/pkg/xast/import_test.go index e9f564fbab..afa0c28794 100644 --- a/ignite/pkg/xast/import_test.go +++ b/ignite/pkg/xast/import_test.go @@ -34,7 +34,7 @@ func main() { args: args{ fileContent: existingContent, imports: []ImportOptions{ - WithImport("strings", "", -1), + WithImport("strings", -1), }, }, want: `package main @@ -54,9 +54,9 @@ func main() { args: args{ fileContent: existingContent, imports: []ImportOptions{ - WithImport("strings", "st", -1), - WithImport("strconv", "", -1), - WithImport("os", "", -1), + WithNamedImport("st", "strings", -1), + WithImport("strconv", -1), + WithLastImport("os"), }, }, want: `package main @@ -78,10 +78,10 @@ func main() { args: args{ fileContent: existingContent, imports: []ImportOptions{ - WithImport("strings", "st", -1), - WithImport("strconv", "", -1), - WithImport("os", "", -1), - WithImport("fmt", "", -1), + WithNamedImport("st", "strings", -1), + WithImport("strconv", -1), + WithImport("os", -1), + WithLastImport("fmt"), }, }, want: `package main @@ -109,7 +109,7 @@ import ( st "strings" )`, imports: []ImportOptions{ - WithImport("strconv", "", 1), + WithImport("strconv", 1), }, }, want: `package main @@ -133,9 +133,9 @@ import ( st "strings" )`, imports: []ImportOptions{ - WithImport("strconv", "", 0), - WithImport("testing", "", 3), - WithImport("bytes", "", -1), + WithImport("strconv", 0), + WithNamedImport("", "testing", 3), + WithLastImport("bytes"), }, }, want: `package main @@ -155,7 +155,7 @@ import ( args: args{ fileContent: existingContent, imports: []ImportOptions{ - WithImport("fmt", "", -1), + WithLastImport("fmt"), }, }, want: existingContent + "\n", @@ -169,7 +169,7 @@ func main() { fmt.Println("Hello, world!") }`, imports: []ImportOptions{ - WithImport("fmt", "", -1), + WithImport("fmt", -1), }, }, want: `package main @@ -190,8 +190,8 @@ func main() { fmt.Println("Hello, world!") }`, imports: []ImportOptions{ - WithImport("fmt", "", -1), - WithImport("os", "", -1), + WithImport("fmt", -1), + WithLastImport("os"), }, }, want: `package main @@ -211,7 +211,7 @@ func main() { args: args{ fileContent: existingContent, imports: []ImportOptions{ - WithImport("strings", "", 10), + WithImport("strings", 10), }, }, err: errors.New("index out of range"), @@ -221,7 +221,7 @@ func main() { args: args{ fileContent: existingContent, imports: []ImportOptions{ - WithImport("fmt\"", "fmt\"", -1), + WithNamedImport("fmt\"", "fmt\"", -1), }, }, err: errors.New("format.Node internal error (5:8: expected ';', found fmt (and 2 more errors))"), @@ -231,7 +231,7 @@ func main() { args: args{ fileContent: "", imports: []ImportOptions{ - WithImport("fmt", "", -1), + WithImport("fmt", -1), }, }, err: errors.New("1:1: expected 'package', found 'EOF'"), diff --git a/ignite/templates/app/files-minimal/app/app.go.plush b/ignite/templates/app/files-minimal/app/app.go.plush index e5ea32dc46..82ed491840 100644 --- a/ignite/templates/app/files-minimal/app/app.go.plush +++ b/ignite/templates/app/files-minimal/app/app.go.plush @@ -38,8 +38,6 @@ import ( mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" - // this line is used by starport scaffolding # stargate/app/moduleImport - "<%= ModulePath %>/docs" ) @@ -181,7 +179,7 @@ func New( &app.StakingKeeper, &app.DistrKeeper, &app.ConsensusParamsKeeper, - // this line is used by starport scaffolding # stargate/app/keeperDefinition + ); err != nil { panic(err) } diff --git a/ignite/templates/app/files-minimal/app/app_config.go.plush b/ignite/templates/app/files-minimal/app/app_config.go.plush index e133dd41a7..02db10bacf 100644 --- a/ignite/templates/app/files-minimal/app/app_config.go.plush +++ b/ignite/templates/app/files-minimal/app/app_config.go.plush @@ -20,8 +20,6 @@ import ( genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - - // this line is used by starport scaffolding # stargate/app/moduleImport ) var ( diff --git a/ignite/templates/app/files/app/app.go.plush b/ignite/templates/app/files/app/app.go.plush index 00d39212b3..2673a020f2 100644 --- a/ignite/templates/app/files/app/app.go.plush +++ b/ignite/templates/app/files/app/app.go.plush @@ -76,8 +76,6 @@ import ( ibctransferkeeper "github.com/cosmos/ibc-go/v8/modules/apps/transfer/keeper" ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper" - // this line is used by starport scaffolding # stargate/app/moduleImport - "<%= ModulePath %>/docs" ) @@ -278,7 +276,7 @@ func New( &app.NFTKeeper, &app.GroupKeeper, &app.CircuitBreakerKeeper, - // this line is used by starport scaffolding # stargate/app/keeperDefinition + ); err != nil { panic(err) } diff --git a/ignite/templates/app/files/app/app_config.go.plush b/ignite/templates/app/files/app/app_config.go.plush index 02f6f7531e..dc0c19a24b 100644 --- a/ignite/templates/app/files/app/app_config.go.plush +++ b/ignite/templates/app/files/app/app_config.go.plush @@ -52,8 +52,6 @@ import ( ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported" "google.golang.org/protobuf/types/known/durationpb" - - // this line is used by starport scaffolding # stargate/app/moduleImport ) var ( diff --git a/ignite/templates/app/files/app/ibc.go.plush b/ignite/templates/app/files/app/ibc.go.plush index cd3e156664..9e255b0cab 100644 --- a/ignite/templates/app/files/app/ibc.go.plush +++ b/ignite/templates/app/files/app/ibc.go.plush @@ -34,8 +34,6 @@ import ( ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper" solomachine "github.com/cosmos/ibc-go/v8/modules/light-clients/06-solomachine" ibctm "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint" - - // this line is used by starport scaffolding # ibc/app/import ) // registerIBCModules register IBC keepers and non dependency inject modules. diff --git a/ignite/templates/ibc/placeholders.go b/ignite/templates/ibc/placeholders.go index ea2fc9077c..d1dfd154b9 100644 --- a/ignite/templates/ibc/placeholders.go +++ b/ignite/templates/ibc/placeholders.go @@ -2,21 +2,11 @@ package ibc //nolint:godot const ( - Placeholder = "// this line is used by starport scaffolding # 1" - Placeholder2 = "// this line is used by starport scaffolding # 2" - Placeholder3 = "// this line is used by starport scaffolding # 3" + Placeholder = "// this line is used by starport scaffolding # 1" // Placeholders IBC packets PlaceholderIBCPacketEvent = "// this line is used by starport scaffolding # ibc/packet/event" PlaceholderIBCPacketModuleRecv = "// this line is used by starport scaffolding # ibc/packet/module/recv" PlaceholderIBCPacketModuleAck = "// this line is used by starport scaffolding # ibc/packet/module/ack" PlaceholderIBCPacketModuleTimeout = "// this line is used by starport scaffolding # ibc/packet/module/timeout" - - // Placeholders for messages - PlaceholderProtoTxRPC = "// this line is used by starport scaffolding # proto/tx/rpc" - PlaceholderProtoTxMessage = "// this line is used by starport scaffolding # proto/tx/message" - - // Placeholders AutoCLI - PlaceholderAutoCLIQuery = "// this line is used by ignite scaffolding # autocli/query" - PlaceholderAutoCLITx = "// this line is used by ignite scaffolding # autocli/tx" ) diff --git a/ignite/templates/message/placeholders.go b/ignite/templates/message/placeholders.go index b6b121fb53..c6cf265b8a 100644 --- a/ignite/templates/message/placeholders.go +++ b/ignite/templates/message/placeholders.go @@ -2,6 +2,5 @@ package message const ( Placeholder = "// this line is used by starport scaffolding # 1" - Placeholder2 = "// this line is used by starport scaffolding # 2" Placeholder3 = "// this line is used by starport scaffolding # 3" ) diff --git a/ignite/templates/module/create/base.go b/ignite/templates/module/create/base.go index 0af3c1de82..99dc5d6464 100644 --- a/ignite/templates/module/create/base.go +++ b/ignite/templates/module/create/base.go @@ -10,6 +10,7 @@ import ( "github.com/ignite/cli/v28/ignite/pkg/gomodulepath" "github.com/ignite/cli/v28/ignite/pkg/placeholder" + "github.com/ignite/cli/v28/ignite/pkg/xast" "github.com/ignite/cli/v28/ignite/pkg/xgenny" "github.com/ignite/cli/v28/ignite/pkg/xstrings" "github.com/ignite/cli/v28/ignite/templates/field/plushhelpers" @@ -82,17 +83,29 @@ func appConfigModify(replacer placeholder.Replacer, opts *CreateOptions) genny.R } // Import - template := `%[2]vmodulev1 "%[3]v/api/%[4]v/%[2]v/module" -_ "%[3]v/x/%[2]v/module" // import for side-effects -%[2]vmoduletypes "%[3]v/x/%[2]v/types" -%[1]v` - replacement := fmt.Sprintf(template, module.PlaceholderSgAppModuleImport, opts.ModuleName, opts.ModulePath, opts.AppName) - content := replacer.Replace(fConfig.String(), module.PlaceholderSgAppModuleImport, replacement) + content, err := xast.AppendImports( + fConfig.String(), + xast.WithLastNamedImport( + fmt.Sprintf("%[1]vmodulev1", opts.ModuleName), + fmt.Sprintf("%[1]v/api/%[2]v/%[3]v/module", opts.ModulePath, opts.AppName, opts.ModuleName), + ), + xast.WithLastNamedImport( + "_", + fmt.Sprintf("%[1]v/x/%[2]v/module", opts.ModulePath, opts.ModuleName), + ), + xast.WithLastNamedImport( + fmt.Sprintf("%[1]vmoduletypes", opts.ModuleName), + fmt.Sprintf("%[1]v/x/%[2]v/types", opts.ModulePath, opts.ModuleName), + ), + ) + if err != nil { + return err + } // Init genesis - template = `%[2]vmoduletypes.ModuleName, + template := `%[2]vmoduletypes.ModuleName, %[1]v` - replacement = fmt.Sprintf(template, module.PlaceholderSgAppInitGenesis, opts.ModuleName) + replacement := fmt.Sprintf(template, module.PlaceholderSgAppInitGenesis, opts.ModuleName) content = replacer.Replace(content, module.PlaceholderSgAppInitGenesis, replacement) replacement = fmt.Sprintf(template, module.PlaceholderSgAppBeginBlockers, opts.ModuleName) content = replacer.Replace(content, module.PlaceholderSgAppBeginBlockers, replacement) @@ -139,15 +152,21 @@ func appModify(replacer placeholder.Replacer, opts *CreateOptions) genny.RunFn { } // Import - template := `%[2]vmodulekeeper "%[3]v/x/%[2]v/keeper" -%[1]v` - replacement := fmt.Sprintf(template, module.PlaceholderSgAppModuleImport, opts.ModuleName, opts.ModulePath) - content := replacer.Replace(f.String(), module.PlaceholderSgAppModuleImport, replacement) + content, err := xast.AppendImports( + f.String(), + xast.WithLastNamedImport( + fmt.Sprintf("%[1]vmodulekeeper", opts.ModuleName), + fmt.Sprintf("%[1]v/x/%[2]v/keeper", opts.ModulePath, opts.ModuleName), + ), + ) + if err != nil { + return err + } // Keeper declaration - template = `%[2]vKeeper %[3]vmodulekeeper.Keeper + template := `%[2]vKeeper %[3]vmodulekeeper.Keeper %[1]v` - replacement = fmt.Sprintf( + replacement := fmt.Sprintf( template, module.PlaceholderSgAppKeeperDeclaration, xstrings.Title(opts.ModuleName), @@ -156,14 +175,18 @@ func appModify(replacer placeholder.Replacer, opts *CreateOptions) genny.RunFn { content = replacer.Replace(content, module.PlaceholderSgAppKeeperDeclaration, replacement) // Keeper definition - template = `&app.%[2]vKeeper, - %[1]v` - replacement = fmt.Sprintf( - template, - module.PlaceholderSgAppKeeperDefinition, - xstrings.Title(opts.ModuleName), + content, err = xast.ModifyFunction( + content, + "New", + xast.AppendInsideFuncCall( + "Inject", + fmt.Sprintf("\n&app.%[1]vKeeper", xstrings.Title(opts.ModuleName)), + -1, + ), ) - content = replacer.Replace(content, module.PlaceholderSgAppKeeperDefinition, replacement) + if err != nil { + return err + } newFile := genny.NewFileS(appPath, content) return r.File(newFile) diff --git a/ignite/templates/module/create/files/base/x/{{moduleName}}/types/genesis.go.plush b/ignite/templates/module/create/files/base/x/{{moduleName}}/types/genesis.go.plush index c41be07425..bb4de5a6f5 100644 --- a/ignite/templates/module/create/files/base/x/{{moduleName}}/types/genesis.go.plush +++ b/ignite/templates/module/create/files/base/x/{{moduleName}}/types/genesis.go.plush @@ -1,9 +1,5 @@ package types -import ( -// this line is used by starport scaffolding # genesis/types/import -) - // DefaultIndex is the default global index const DefaultIndex uint64 = 1 diff --git a/ignite/templates/module/create/ibc.go b/ignite/templates/module/create/ibc.go index 557b984c64..9cdad45009 100644 --- a/ignite/templates/module/create/ibc.go +++ b/ignite/templates/module/create/ibc.go @@ -11,6 +11,7 @@ import ( "github.com/ignite/cli/v28/ignite/pkg/gomodulepath" "github.com/ignite/cli/v28/ignite/pkg/placeholder" "github.com/ignite/cli/v28/ignite/pkg/protoanalysis/protoutil" + "github.com/ignite/cli/v28/ignite/pkg/xast" "github.com/ignite/cli/v28/ignite/pkg/xgenny" "github.com/ignite/cli/v28/ignite/pkg/xstrings" "github.com/ignite/cli/v28/ignite/templates/field/plushhelpers" @@ -95,10 +96,13 @@ func genesisTypesModify(replacer placeholder.Replacer, opts *CreateOptions) genn } // Import - templateImport := `host "github.com/cosmos/ibc-go/v8/modules/core/24-host" -%s` - replacementImport := fmt.Sprintf(templateImport, typed.PlaceholderGenesisTypesImport) - content := replacer.Replace(f.String(), typed.PlaceholderGenesisTypesImport, replacementImport) + content, err := xast.AppendImports( + f.String(), + xast.WithLastNamedImport("host", "github.com/cosmos/ibc-go/v8/modules/core/24-host"), + ) + if err != nil { + return err + } // Default genesis templateDefault := `PortId: PortID, @@ -189,11 +193,20 @@ func appIBCModify(replacer placeholder.Replacer, opts *CreateOptions) genny.RunF } // Import - templateImport := `%[1]v -%[2]vmodule "%[3]v/x/%[2]v/module" -%[2]vmoduletypes "%[3]v/x/%[2]v/types"` - replacementImport := fmt.Sprintf(templateImport, module.PlaceholderIBCImport, opts.ModuleName, opts.ModulePath) - content := replacer.Replace(f.String(), module.PlaceholderIBCImport, replacementImport) + content, err := xast.AppendImports( + f.String(), + xast.WithLastNamedImport( + fmt.Sprintf("%[1]vmodule", opts.ModuleName), + fmt.Sprintf("%[1]v/x/%[2]v/module", opts.ModulePath, opts.ModuleName), + ), + xast.WithLastNamedImport( + fmt.Sprintf("%[1]vmoduletypes", opts.ModuleName), + fmt.Sprintf("%[1]v/x/%[2]v/types", opts.ModulePath, opts.ModuleName), + ), + ) + if err != nil { + return err + } // create IBC module templateIBCModule := `%[2]vIBCModule := ibcfee.NewIBCMiddleware(%[2]vmodule.NewIBCModule(app.%[3]vKeeper), app.IBCFeeKeeper) diff --git a/ignite/templates/module/placeholders.go b/ignite/templates/module/placeholders.go index d8cf25041a..84c4040443 100644 --- a/ignite/templates/module/placeholders.go +++ b/ignite/templates/module/placeholders.go @@ -3,13 +3,10 @@ package module //nolint:godot const ( Placeholder = "// this line is used by starport scaffolding # 1" - Placeholder2 = "// this line is used by starport scaffolding # 2" Placeholder3 = "// this line is used by starport scaffolding # 3" // Placeholders in app.go - PlaceholderSgAppModuleImport = "// this line is used by starport scaffolding # stargate/app/moduleImport" PlaceholderSgAppKeeperDeclaration = "// this line is used by starport scaffolding # stargate/app/keeperDeclaration" - PlaceholderSgAppKeeperDefinition = "// this line is used by starport scaffolding # stargate/app/keeperDefinition" PlaceholderSgAppInitGenesis = "// this line is used by starport scaffolding # stargate/app/initGenesis" PlaceholderSgAppBeginBlockers = "// this line is used by starport scaffolding # stargate/app/beginBlockers" PlaceholderSgAppEndBlockers = "// this line is used by starport scaffolding # stargate/app/endBlockers" @@ -17,7 +14,6 @@ const ( PlaceholderSgAppModuleConfig = "// this line is used by starport scaffolding # stargate/app/moduleConfig" // Placeholders IBC - PlaceholderIBCImport = "// this line is used by starport scaffolding # ibc/app/import" PlaceholderIBCKeysName = "// this line is used by starport scaffolding # ibc/keys/name" PlaceholderIBCKeysPort = "// this line is used by starport scaffolding # ibc/keys/port" PlaceholderIBCNewModule = "// this line is used by starport scaffolding # ibc/app/module" diff --git a/ignite/templates/typed/genesis.go b/ignite/templates/typed/genesis.go index f58fa6cc39..a0a2bb6398 100644 --- a/ignite/templates/typed/genesis.go +++ b/ignite/templates/typed/genesis.go @@ -1,26 +1,4 @@ package typed -import ( - "fmt" - "strings" - - "github.com/ignite/cli/v28/ignite/pkg/placeholder" -) - // ProtoGenesisStateMessage is the name of the proto message that represents the genesis state. const ProtoGenesisStateMessage = "GenesisState" - -// PatchGenesisTypeImport patches types/genesis.go content from the issue: -// https://github.com/ignite/cli/issues/992 -func PatchGenesisTypeImport(replacer placeholder.Replacer, content string) string { - patternToCheck := "import (" - replacement := fmt.Sprintf(`import ( -%[1]v -)`, PlaceholderGenesisTypesImport) - - if !strings.Contains(content, patternToCheck) { - content = replacer.Replace(content, PlaceholderGenesisTypesImport, replacement) - } - - return content -} diff --git a/ignite/templates/typed/list/genesis.go b/ignite/templates/typed/list/genesis.go index c6f06ff79d..afe17718d3 100644 --- a/ignite/templates/typed/list/genesis.go +++ b/ignite/templates/typed/list/genesis.go @@ -9,6 +9,7 @@ import ( "github.com/ignite/cli/v28/ignite/pkg/errors" "github.com/ignite/cli/v28/ignite/pkg/placeholder" "github.com/ignite/cli/v28/ignite/pkg/protoanalysis/protoutil" + "github.com/ignite/cli/v28/ignite/pkg/xast" "github.com/ignite/cli/v28/ignite/templates/module" "github.com/ignite/cli/v28/ignite/templates/typed" ) @@ -74,10 +75,10 @@ func genesisTypesModify(replacer placeholder.Replacer, opts *typed.Options) genn return err } - content := typed.PatchGenesisTypeImport(replacer, f.String()) - - templateTypesImport := `"fmt"` - content = replacer.ReplaceOnce(content, typed.PlaceholderGenesisTypesImport, templateTypesImport) + content, err := xast.AppendImports(f.String(), xast.WithLastImport("fmt")) + if err != nil { + return err + } templateTypesDefault := `%[2]vList: []%[2]v{}, %[1]v` diff --git a/ignite/templates/typed/map/map.go b/ignite/templates/typed/map/map.go index b8fda5cd9a..a578299ba0 100644 --- a/ignite/templates/typed/map/map.go +++ b/ignite/templates/typed/map/map.go @@ -13,6 +13,7 @@ import ( "github.com/ignite/cli/v28/ignite/pkg/gomodulepath" "github.com/ignite/cli/v28/ignite/pkg/placeholder" "github.com/ignite/cli/v28/ignite/pkg/protoanalysis/protoutil" + "github.com/ignite/cli/v28/ignite/pkg/xast" "github.com/ignite/cli/v28/ignite/pkg/xgenny" "github.com/ignite/cli/v28/ignite/templates/field/datatype" "github.com/ignite/cli/v28/ignite/templates/module" @@ -328,10 +329,10 @@ func genesisTypesModify(replacer placeholder.Replacer, opts *typed.Options) genn return err } - content := typed.PatchGenesisTypeImport(replacer, f.String()) - - templateTypesImport := `"fmt"` - content = replacer.ReplaceOnce(content, typed.PlaceholderGenesisTypesImport, templateTypesImport) + content, err := xast.AppendImports(f.String(), xast.WithLastImport("fmt")) + if err != nil { + return err + } templateTypesDefault := `%[2]vList: []%[2]v{}, %[1]v` diff --git a/ignite/templates/typed/placeholders.go b/ignite/templates/typed/placeholders.go index 1ca61b23fb..78cfa927fd 100644 --- a/ignite/templates/typed/placeholders.go +++ b/ignite/templates/typed/placeholders.go @@ -3,12 +3,10 @@ package typed //nolint:godot const ( Placeholder = "// this line is used by starport scaffolding # 1" - Placeholder2 = "// this line is used by starport scaffolding # 2" Placeholder3 = "// this line is used by starport scaffolding # 3" Placeholder4 = "" // Genesis - PlaceholderGenesisTypesImport = "// this line is used by starport scaffolding # genesis/types/import" PlaceholderGenesisTypesDefault = "// this line is used by starport scaffolding # genesis/types/default" PlaceholderGenesisTypesValidate = "// this line is used by starport scaffolding # genesis/types/validate" PlaceholderGenesisModuleInit = "// this line is used by starport scaffolding # genesis/module/init" diff --git a/ignite/templates/typed/singleton/singleton.go b/ignite/templates/typed/singleton/singleton.go index c2cf350ec5..131a0930a9 100644 --- a/ignite/templates/typed/singleton/singleton.go +++ b/ignite/templates/typed/singleton/singleton.go @@ -234,8 +234,6 @@ func genesisTypesModify(replacer placeholder.Replacer, opts *typed.Options) genn return err } - content := typed.PatchGenesisTypeImport(replacer, f.String()) - templateTypesDefault := `%[2]v: nil, %[1]v` replacementTypesDefault := fmt.Sprintf( @@ -243,7 +241,7 @@ func genesisTypesModify(replacer placeholder.Replacer, opts *typed.Options) genn typed.PlaceholderGenesisTypesDefault, opts.TypeName.UpperCamel, ) - content = replacer.Replace(content, typed.PlaceholderGenesisTypesDefault, replacementTypesDefault) + content := replacer.Replace(f.String(), typed.PlaceholderGenesisTypesDefault, replacementTypesDefault) newFile := genny.NewFileS(path, content) return r.File(newFile) From d1b89436c36d49d009e39bde40a149b76fc996e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jer=C3=B3nimo=20Albi?= Date: Mon, 11 Mar 2024 21:49:56 +0100 Subject: [PATCH 3/3] chore: rename `pkg/yaml` to `pkg/xyaml` (#4008) * chore: rename `pkg/yaml` to `pkg/xyaml` * chore: update changelog --- changelog.md | 1 + ignite/config/chain/base/config.go | 2 +- ignite/config/chain/v1/validator.go | 2 +- .../config/chain/v1/validator_servers_test.go | 2 +- ignite/pkg/{yaml => xyaml}/map.go | 2 +- ignite/pkg/{yaml => xyaml}/map_test.go | 4 +- ignite/pkg/{yaml => xyaml}/yaml.go | 2 +- ignite/pkg/{yaml => xyaml}/yaml_test.go | 2 +- integration/ibc/cmd_relayer_test.go | 48 +++++++++---------- integration/node/cmd_query_bank_test.go | 2 +- integration/node/cmd_tx_bank_send_test.go | 2 +- 11 files changed, 35 insertions(+), 34 deletions(-) rename ignite/pkg/{yaml => xyaml}/map.go (98%) rename ignite/pkg/{yaml => xyaml}/map_test.go (91%) rename ignite/pkg/{yaml => xyaml}/yaml.go (98%) rename ignite/pkg/{yaml => xyaml}/yaml_test.go (99%) diff --git a/changelog.md b/changelog.md index 617ab6854e..d46ab575da 100644 --- a/changelog.md +++ b/changelog.md @@ -19,6 +19,7 @@ - [#3976](https://github.com/ignite/cli/pull/3976) Remove error checks for Cobra command value get calls - [#3983](https://github.com/ignite/cli/pull/3983) Bump `cosmos-sdk` to `v0.50.4` and `ibc-go` to `v8.1.0` - [#4002](https://github.com/ignite/cli/pull/4002) Bump buf build +- [#4008](https://github.com/ignite/cli/pull/4008) Rename `pkg/yaml` to `pkg/xyaml` ### Fixes diff --git a/ignite/config/chain/base/config.go b/ignite/config/chain/base/config.go index 3475e802f1..60699bca12 100644 --- a/ignite/config/chain/base/config.go +++ b/ignite/config/chain/base/config.go @@ -4,7 +4,7 @@ import ( "github.com/imdario/mergo" "github.com/ignite/cli/v28/ignite/config/chain/version" - xyaml "github.com/ignite/cli/v28/ignite/pkg/yaml" + "github.com/ignite/cli/v28/ignite/pkg/xyaml" ) var ( diff --git a/ignite/config/chain/v1/validator.go b/ignite/config/chain/v1/validator.go index 7af0b615c5..8bd1b0754f 100644 --- a/ignite/config/chain/v1/validator.go +++ b/ignite/config/chain/v1/validator.go @@ -1,7 +1,7 @@ package v1 import ( - xyaml "github.com/ignite/cli/v28/ignite/pkg/yaml" + "github.com/ignite/cli/v28/ignite/pkg/xyaml" ) // Validator holds info related to validator settings. diff --git a/ignite/config/chain/v1/validator_servers_test.go b/ignite/config/chain/v1/validator_servers_test.go index c711f43603..e28f4a7b74 100644 --- a/ignite/config/chain/v1/validator_servers_test.go +++ b/ignite/config/chain/v1/validator_servers_test.go @@ -6,7 +6,7 @@ import ( "github.com/stretchr/testify/require" v1 "github.com/ignite/cli/v28/ignite/config/chain/v1" - xyaml "github.com/ignite/cli/v28/ignite/pkg/yaml" + "github.com/ignite/cli/v28/ignite/pkg/xyaml" ) func TestValidatorGetServers(t *testing.T) { diff --git a/ignite/pkg/yaml/map.go b/ignite/pkg/xyaml/map.go similarity index 98% rename from ignite/pkg/yaml/map.go rename to ignite/pkg/xyaml/map.go index 5385f0e64a..fa4be088f1 100644 --- a/ignite/pkg/yaml/map.go +++ b/ignite/pkg/xyaml/map.go @@ -1,4 +1,4 @@ -package yaml +package xyaml // Map defines a map type that uses strings as key value. // The map implements the Unmarshaller interface to convert diff --git a/ignite/pkg/yaml/map_test.go b/ignite/pkg/xyaml/map_test.go similarity index 91% rename from ignite/pkg/yaml/map_test.go rename to ignite/pkg/xyaml/map_test.go index afc87e6e4b..7b9e95c1ec 100644 --- a/ignite/pkg/yaml/map_test.go +++ b/ignite/pkg/xyaml/map_test.go @@ -1,4 +1,4 @@ -package yaml_test +package xyaml_test import ( "testing" @@ -6,7 +6,7 @@ import ( "github.com/stretchr/testify/require" "gopkg.in/yaml.v2" - xyaml "github.com/ignite/cli/v28/ignite/pkg/yaml" + "github.com/ignite/cli/v28/ignite/pkg/xyaml" ) func TestUnmarshalWithCustomMapType(t *testing.T) { diff --git a/ignite/pkg/yaml/yaml.go b/ignite/pkg/xyaml/yaml.go similarity index 98% rename from ignite/pkg/yaml/yaml.go rename to ignite/pkg/xyaml/yaml.go index edeb602257..5f1ad0c6c9 100644 --- a/ignite/pkg/yaml/yaml.go +++ b/ignite/pkg/xyaml/yaml.go @@ -1,4 +1,4 @@ -package yaml +package xyaml import ( "context" diff --git a/ignite/pkg/yaml/yaml_test.go b/ignite/pkg/xyaml/yaml_test.go similarity index 99% rename from ignite/pkg/yaml/yaml_test.go rename to ignite/pkg/xyaml/yaml_test.go index 21c7848b8d..b5810901dc 100644 --- a/ignite/pkg/yaml/yaml_test.go +++ b/ignite/pkg/xyaml/yaml_test.go @@ -1,4 +1,4 @@ -package yaml +package xyaml import ( "context" diff --git a/integration/ibc/cmd_relayer_test.go b/integration/ibc/cmd_relayer_test.go index 30fb207fd9..74d0fdd7fa 100644 --- a/integration/ibc/cmd_relayer_test.go +++ b/integration/ibc/cmd_relayer_test.go @@ -25,7 +25,7 @@ import ( "github.com/ignite/cli/v28/ignite/pkg/cmdrunner" "github.com/ignite/cli/v28/ignite/pkg/cmdrunner/step" "github.com/ignite/cli/v28/ignite/pkg/goanalysis" - yamlmap "github.com/ignite/cli/v28/ignite/pkg/yaml" + "github.com/ignite/cli/v28/ignite/pkg/xyaml" envtest "github.com/ignite/cli/v28/integration" ) @@ -66,21 +66,21 @@ var ( Coins: []string{"500token", "100000000stake"}, Host: ":4501", }, - Genesis: yamlmap.Map{"chain_id": "mars-1"}, + Genesis: xyaml.Map{"chain_id": "mars-1"}, }, Validators: []v1.Validator{ { Name: "alice", Bonded: "100000000stake", - Client: yamlmap.Map{"keyring-backend": keyring.BackendTest}, - App: yamlmap.Map{ - "api": yamlmap.Map{"address": ":1318"}, - "grpc": yamlmap.Map{"address": ":9092"}, - "grpc-web": yamlmap.Map{"address": ":9093"}, + Client: xyaml.Map{"keyring-backend": keyring.BackendTest}, + App: xyaml.Map{ + "api": xyaml.Map{"address": ":1318"}, + "grpc": xyaml.Map{"address": ":9092"}, + "grpc-web": xyaml.Map{"address": ":9093"}, }, - Config: yamlmap.Map{ - "p2p": yamlmap.Map{"laddr": ":26658"}, - "rpc": yamlmap.Map{"laddr": ":26658", "pprof_laddr": ":6061"}, + Config: xyaml.Map{ + "p2p": xyaml.Map{"laddr": ":26658"}, + "rpc": xyaml.Map{"laddr": ":26658", "pprof_laddr": ":6061"}, }, Home: "$HOME/.mars", }, @@ -117,21 +117,21 @@ var ( Coins: []string{"500token", "100000000stake"}, Host: ":4500", }, - Genesis: yamlmap.Map{"chain_id": "earth-1"}, + Genesis: xyaml.Map{"chain_id": "earth-1"}, }, Validators: []v1.Validator{ { Name: "alice", Bonded: "100000000stake", - Client: yamlmap.Map{"keyring-backend": keyring.BackendTest}, - App: yamlmap.Map{ - "api": yamlmap.Map{"address": ":1317"}, - "grpc": yamlmap.Map{"address": ":9090"}, - "grpc-web": yamlmap.Map{"address": ":9091"}, + Client: xyaml.Map{"keyring-backend": keyring.BackendTest}, + App: xyaml.Map{ + "api": xyaml.Map{"address": ":1317"}, + "grpc": xyaml.Map{"address": ":9090"}, + "grpc-web": xyaml.Map{"address": ":9091"}, }, - Config: yamlmap.Map{ - "p2p": yamlmap.Map{"laddr": ":26656"}, - "rpc": yamlmap.Map{"laddr": ":26656", "pprof_laddr": ":6060"}, + Config: xyaml.Map{ + "p2p": xyaml.Map{"laddr": ":26656"}, + "rpc": xyaml.Map{"laddr": ":26656", "pprof_laddr": ":6060"}, }, Home: "$HOME/.earth", }, @@ -260,11 +260,11 @@ func runChain( cfg.Validators[0].Home = homePath cfg.Faucet.Host = genAddr(ports[0]) - cfg.Validators[0].App["api"] = yamlmap.Map{"address": genAddr(ports[1])} - cfg.Validators[0].App["grpc"] = yamlmap.Map{"address": genAddr(ports[2])} - cfg.Validators[0].App["grpc-web"] = yamlmap.Map{"address": genAddr(ports[3])} - cfg.Validators[0].Config["p2p"] = yamlmap.Map{"laddr": genAddr(ports[4])} - cfg.Validators[0].Config["rpc"] = yamlmap.Map{ + cfg.Validators[0].App["api"] = xyaml.Map{"address": genAddr(ports[1])} + cfg.Validators[0].App["grpc"] = xyaml.Map{"address": genAddr(ports[2])} + cfg.Validators[0].App["grpc-web"] = xyaml.Map{"address": genAddr(ports[3])} + cfg.Validators[0].Config["p2p"] = xyaml.Map{"laddr": genAddr(ports[4])} + cfg.Validators[0].Config["rpc"] = xyaml.Map{ "laddr": genAddr(ports[5]), "pprof_laddr": genAddr(ports[6]), } diff --git a/integration/node/cmd_query_bank_test.go b/integration/node/cmd_query_bank_test.go index af4ddfbeb7..b1ef6e245c 100644 --- a/integration/node/cmd_query_bank_test.go +++ b/integration/node/cmd_query_bank_test.go @@ -20,7 +20,7 @@ import ( "github.com/ignite/cli/v28/ignite/pkg/cosmosclient" "github.com/ignite/cli/v28/ignite/pkg/randstr" "github.com/ignite/cli/v28/ignite/pkg/xurl" - xyaml "github.com/ignite/cli/v28/ignite/pkg/yaml" + "github.com/ignite/cli/v28/ignite/pkg/xyaml" envtest "github.com/ignite/cli/v28/integration" ) diff --git a/integration/node/cmd_tx_bank_send_test.go b/integration/node/cmd_tx_bank_send_test.go index 442c8e9ec7..a99c74fe00 100644 --- a/integration/node/cmd_tx_bank_send_test.go +++ b/integration/node/cmd_tx_bank_send_test.go @@ -18,7 +18,7 @@ import ( "github.com/ignite/cli/v28/ignite/pkg/cosmosclient" "github.com/ignite/cli/v28/ignite/pkg/randstr" "github.com/ignite/cli/v28/ignite/pkg/xurl" - xyaml "github.com/ignite/cli/v28/ignite/pkg/yaml" + "github.com/ignite/cli/v28/ignite/pkg/xyaml" envtest "github.com/ignite/cli/v28/integration" )