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

feat: change generate commands to print paths of the generated code #2957

Merged
merged 11 commits into from
Oct 21, 2022
Merged
18 changes: 11 additions & 7 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
## [`v0.25.1`](https://github.com/ignite/cli/releases/tag/v0.25.1)

### Changes

- [#2968](https://github.com/ignite/cli/pull/2968) Dragonberry security fix upgrading Cosmos SDK to `v0.46.3`

# Changelog

## Unreleased
Expand All @@ -12,6 +6,16 @@

- [#2955](https://github.com/ignite/cli/pull/2955/) Add `ignite network request add-account` command.

### Changes

- [#2957](https://github.com/ignite/cli/pull/2957) Change generate commands to print the path to the generated code.

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

### Changes

- [#2968](https://github.com/ignite/cli/pull/2968) Dragonberry security fix upgrading Cosmos SDK to `v0.46.3`

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

### Features
Expand Down Expand Up @@ -39,7 +43,7 @@
- Add `--peer-address` flag to `network chain join` command.
- Change nightly tag format
- Add cosmos-sdk version in `version` command
- [#29350](https://github.com/ignite/cli/pull/2935) Update `gobuffalo/plush` templating tool to `v4`
- [#2935](https://github.com/ignite/cli/pull/2935) Update `gobuffalo/plush` templating tool to `v4`

### Fixes

Expand Down
4 changes: 3 additions & 1 deletion ignite/cmd/generate_dart.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/spf13/cobra"

"github.com/ignite/cli/ignite/pkg/cliui"
"github.com/ignite/cli/ignite/pkg/cliui/icons"
"github.com/ignite/cli/ignite/services/chain"
)

Expand Down Expand Up @@ -31,6 +32,7 @@ func generateDartHandler(cmd *cobra.Command, args []string) error {
chain.EnableThirdPartyModuleCodegen(),
chain.WithOutputer(session),
chain.CollectEvents(session.EventBus()),
chain.PrintGeneratedPaths(),
)
if err != nil {
return err
Expand All @@ -45,5 +47,5 @@ func generateDartHandler(cmd *cobra.Command, args []string) error {
return err
}

return session.Println("⛏️ Generated Dart client.")
return session.Println(icons.OK, "Generated Dart Client")
}
3 changes: 2 additions & 1 deletion ignite/cmd/generate_go.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/spf13/cobra"

"github.com/ignite/cli/ignite/pkg/cliui"
"github.com/ignite/cli/ignite/pkg/cliui/icons"
"github.com/ignite/cli/ignite/services/chain"
)

Expand Down Expand Up @@ -44,5 +45,5 @@ func generateGoHandler(cmd *cobra.Command, args []string) error {
return err
}

return session.Println("⛏️ Generated go code.")
return session.Println(icons.OK, "Generated Go code")
}
4 changes: 3 additions & 1 deletion ignite/cmd/generate_openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/spf13/cobra"

"github.com/ignite/cli/ignite/pkg/cliui"
"github.com/ignite/cli/ignite/pkg/cliui/icons"
"github.com/ignite/cli/ignite/services/chain"
)

Expand All @@ -30,6 +31,7 @@ func generateOpenAPIHandler(cmd *cobra.Command, args []string) error {
cmd,
chain.WithOutputer(session),
chain.CollectEvents(session.EventBus()),
chain.PrintGeneratedPaths(),
)
if err != nil {
return err
Expand All @@ -44,5 +46,5 @@ func generateOpenAPIHandler(cmd *cobra.Command, args []string) error {
return err
}

return session.Println("⛏️ Generated OpenAPI spec.")
return session.Println(icons.OK, "Generated OpenAPI spec")
}
4 changes: 3 additions & 1 deletion ignite/cmd/generate_typescript_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/spf13/cobra"

"github.com/ignite/cli/ignite/pkg/cliui"
"github.com/ignite/cli/ignite/pkg/cliui/icons"
"github.com/ignite/cli/ignite/services/chain"
)

Expand Down Expand Up @@ -32,6 +33,7 @@ func generateTSClientHandler(cmd *cobra.Command, args []string) error {
chain.EnableThirdPartyModuleCodegen(),
chain.WithOutputer(session),
chain.CollectEvents(session.EventBus()),
chain.PrintGeneratedPaths(),
)
if err != nil {
return err
Expand All @@ -52,5 +54,5 @@ func generateTSClientHandler(cmd *cobra.Command, args []string) error {
return err
}

return session.Println("⛏️ Generated Typescript Client")
return session.Println(icons.OK, "Generated Typescript Client")
}
4 changes: 3 additions & 1 deletion ignite/cmd/generate_vuex.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/spf13/cobra"

"github.com/ignite/cli/ignite/pkg/cliui"
"github.com/ignite/cli/ignite/pkg/cliui/icons"
"github.com/ignite/cli/ignite/services/chain"
)

Expand Down Expand Up @@ -32,6 +33,7 @@ func generateVuexHandler(cmd *cobra.Command, args []string) error {
chain.EnableThirdPartyModuleCodegen(),
chain.WithOutputer(session),
chain.CollectEvents(session.EventBus()),
chain.PrintGeneratedPaths(),
)
if err != nil {
return err
Expand All @@ -46,5 +48,5 @@ func generateVuexHandler(cmd *cobra.Command, args []string) error {
return err
}

return session.Println("⛏️ Generated Typescript Client and Vuex stores")
return session.Println(icons.OK, "Generated Typescript Client and Vuex stores")
}
10 changes: 9 additions & 1 deletion ignite/pkg/cosmosgen/cosmosgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,18 @@ func Generate(ctx context.Context, cacheStorage cache.Storage, appPath, protoDir
return nil
}

// TypescriptModulePath generates module paths for Cosmos SDK modules.
// TypescriptModulePath generates TS module paths for Cosmos SDK modules.
// The root path is used as prefix for the generated paths.
func TypescriptModulePath(rootPath string) ModulePathFunc {
return func(m module.Module) string {
return filepath.Join(rootPath, m.Pkg.Name)
}
}

// DartModulePath generates Dart module paths for Cosmos SDK modules.
// The root path is used as prefix for the generated paths.
func DartModulePath(rootPath string) ModulePathFunc {
return func(m module.Module) string {
return filepath.Join(rootPath, m.Pkg.Name, "module")
}
}
10 changes: 10 additions & 0 deletions ignite/services/chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ type chainOptions struct {
// been modified since they were downloaded.
checkDependencies bool

// printGeneratedPaths prints the output paths of the generated code
printGeneratedPaths bool

// path of a custom config file
ConfigFile string
}
Expand Down Expand Up @@ -141,6 +144,13 @@ func CheckDependencies() Option {
}
}

// PrintGeneratedPaths prints the output paths of the generated code.
func PrintGeneratedPaths() Option {
return func(c *Chain) {
c.options.printGeneratedPaths = true
}
}

// New initializes a new Chain with options that its source lives at path.
func New(path string, options ...Option) (*Chain, error) {
app, err := NewAppAt(path)
Expand Down
70 changes: 52 additions & 18 deletions ignite/services/chain/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package chain

import (
"context"
"fmt"
"os"
"path/filepath"

"github.com/ignite/cli/ignite/chainconfig"
"github.com/ignite/cli/ignite/pkg/cache"
"github.com/ignite/cli/ignite/pkg/cosmosanalysis/module"
"github.com/ignite/cli/ignite/pkg/cliui/icons"
"github.com/ignite/cli/ignite/pkg/cosmosgen"
"github.com/ignite/cli/ignite/pkg/events"
)

const (
Expand Down Expand Up @@ -119,7 +121,7 @@ func (c *Chain) Generate(
return err
}

c.ev.Send("🛠 Building proto...")
c.ev.Send("Building proto...", events.ProgressStarted())
tbruyelle marked this conversation as resolved.
Show resolved Hide resolved

options := []cosmosgen.Option{
cosmosgen.IncludeDirs(conf.Build.Proto.ThirdPartyPaths),
Expand All @@ -131,9 +133,10 @@ func (c *Chain) Generate(

enableThirdPartyModuleCodegen := !c.protoBuiltAtLeastOnce && c.options.isThirdPartyModuleCodegenEnabled

// generate Typescript Client code as well if it is enabled.
var dartPath, openAPIPath, tsClientPath, vuexPath string

if targetOptions.isTSClientEnabled {
tsClientPath := targetOptions.tsClientPath
tsClientPath = targetOptions.tsClientPath
if tsClientPath == "" {
// TODO: Change to allow full paths in case TS client dir is not inside the app's dir?
tsClientPath = filepath.Join(c.app.Path, chainconfig.TSClientPath(conf))
Expand All @@ -152,50 +155,47 @@ func (c *Chain) Generate(
}

if targetOptions.isVuexEnabled {
vuexPath := conf.Client.Vuex.Path
vuexPath = conf.Client.Vuex.Path
if vuexPath == "" {
vuexPath = defaultVuexPath
}

storeRootPath := filepath.Join(c.app.Path, vuexPath, "generated")
if err := os.MkdirAll(storeRootPath, 0o766); err != nil {
vuexPath = filepath.Join(c.app.Path, vuexPath, "generated")
if err := os.MkdirAll(vuexPath, 0o766); err != nil {
return err
}

options = append(options,
cosmosgen.WithVuexGeneration(
enableThirdPartyModuleCodegen,
cosmosgen.TypescriptModulePath(storeRootPath),
storeRootPath,
cosmosgen.TypescriptModulePath(vuexPath),
vuexPath,
),
)
}

if targetOptions.isDartEnabled {
dartPath := conf.Client.Dart.Path
dartPath = conf.Client.Dart.Path
if dartPath == "" {
dartPath = defaultDartPath
}

rootPath := filepath.Join(c.app.Path, dartPath, "generated")
if err := os.MkdirAll(rootPath, 0o766); err != nil {
dartPath = filepath.Join(c.app.Path, dartPath, "generated")
if err := os.MkdirAll(dartPath, 0o766); err != nil {
return err
}

options = append(options,
cosmosgen.WithDartGeneration(
enableThirdPartyModuleCodegen,
func(m module.Module) string {
return filepath.Join(rootPath, m.Pkg.Name, "module")
},
rootPath,
cosmosgen.DartModulePath(dartPath),
dartPath,
),
)
}

if targetOptions.isOpenAPIEnabled {
openAPIPath := conf.Client.OpenAPI.Path

openAPIPath = conf.Client.OpenAPI.Path
if openAPIPath == "" {
openAPIPath = defaultOpenAPIPath
}
Expand All @@ -209,5 +209,39 @@ func (c *Chain) Generate(

c.protoBuiltAtLeastOnce = true

if c.options.printGeneratedPaths {
if targetOptions.isTSClientEnabled {
c.ev.Send(
fmt.Sprintf("Typescript client path: %s", tsClientPath),
events.Icon(icons.Bullet),
events.ProgressFinished(),
)
}

if targetOptions.isVuexEnabled {
c.ev.Send(
fmt.Sprintf("Vuex stores path: %s", vuexPath),
events.Icon(icons.Bullet),
events.ProgressFinished(),
)
}

if targetOptions.isDartEnabled {
c.ev.Send(
fmt.Sprintf("Dart path: %s", dartPath),
events.Icon(icons.Bullet),
events.ProgressFinished(),
)
}

if targetOptions.isOpenAPIEnabled {
c.ev.Send(
fmt.Sprintf("OpenAPI path: %s", openAPIPath),
events.Icon(icons.Bullet),
events.ProgressFinished(),
)
}
}

return nil
}