Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(templates): introduce alternative folders #3897

Merged
merged 3 commits into from
Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE/pull_request_template.md
julienrbrt marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ Please make sure to check the following for your PR:
Ignite CLI team only:

- [ ] I have updated the _Unreleased_ section in the changelog.md for my changes.
- [ ] If the templates in `ignite/templates/files` have been changed, make
sure that the change doesn't need to be reflected in the
`ignite/templates/files-*` folders.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

- [#3885](https://github.com/ignite/cli/pull/3885) Scaffold chain with Cosmos SDK `v0.50.3`
- [#3877](https://github.com/ignite/cli/pull/3877) Change Ignite App extension to "ign"
- [#3897](https://github.com/ignite/cli/pull/3897) Introduce alternative folder in templates

## [`v28.1.0`](https://github.com/ignite/cli/releases/tag/v28.1.0)

Expand Down
35 changes: 19 additions & 16 deletions ignite/templates/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package app

import (
"embed"
"fmt"
"io/fs"

"github.com/gobuffalo/genny/v2"
Expand All @@ -14,13 +13,16 @@ import (
"github.com/ignite/cli/v28/ignite/templates/field/plushhelpers"
)

//go:embed files/* files/**/*
var files embed.FS

var (
ibcConfig = "app/ibc.go"
minimalAppConfig = "app/app_config_minimal.go"
appConfig = "app/app_config.go"
//go:embed files/* files/**/*
files embed.FS

//go:embed files-minimal/* files-minimal/**/*
filesMinimal embed.FS
)

const (
ibcConfig = "app/ibc.go"
)

// NewGenerator returns the generator to scaffold a new Cosmos SDK app.
Expand All @@ -32,25 +34,26 @@ func NewGenerator(opts *Options) (*genny.Generator, error) {
}
g := genny.New()

// always exclude minimal app config it will be created later
// app_config_minimal is only used for the minimal app template
excludePrefix := []string{minimalAppConfig}
var excludePrefix []string
if opts.IsChainMinimal {
// minimal chain does not have ibc or classic app config
excludePrefix = append(excludePrefix, ibcConfig, appConfig)
// minimal chain does not have ibc
excludePrefix = append(excludePrefix, ibcConfig)
}

if err := g.SelectiveFS(subfs, opts.IncludePrefixes, nil, excludePrefix, nil); err != nil {
return g, errors.Errorf("generator fs: %w", err)
}

if opts.IsChainMinimal {
file, err := subfs.Open(fmt.Sprintf("%s.plush", minimalAppConfig))
// Remove "files-minimal/" prefix
subfs, err := fs.Sub(filesMinimal, "files-minimal")
if err != nil {
return g, errors.Errorf("open minimal app config: %w", err)
return nil, errors.Errorf("generator sub minimal: %w", err)
}
// Override files from "files" with the ones from "files-minimal"
if err := g.FS(subfs); err != nil {
return g, errors.Errorf("generator fs minimal: %w", err)
}

g.File(genny.NewFile(appConfig, file))
}

ctx := plush.NewContext()
Expand Down
Loading
Loading