Skip to content
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
12 changes: 1 addition & 11 deletions starport/cmd/generate_vuex.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,14 @@ func NewGenerateVuex() *cobra.Command {
RunE: generateVuexHandler,
}

c.Flags().Bool(flagRebuildProtoOnce, false, "Enables proto code generation for 3rd party modules.")

return c
}

func generateVuexHandler(cmd *cobra.Command, args []string) error {
s := clispinner.New().SetText("Generating...")
defer s.Stop()

isRebuildProtoOnce, _ := cmd.Flags().GetBool(flagRebuildProtoOnce)

chainOption := []chain.Option{}

if isRebuildProtoOnce {
chainOption = append(chainOption, chain.EnableThirdPartyModuleCodegen())
}

c, err := newChainWithHomeFlags(cmd, appPath, chainOption...)
c, err := newChainWithHomeFlags(cmd, appPath, chain.EnableThirdPartyModuleCodegen())
if err != nil {
return err
}
Expand Down
46 changes: 41 additions & 5 deletions starport/services/chain/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@ package chain
import (
"context"
"fmt"
"os"
"path/filepath"

"github.com/tendermint/starport/starport/pkg/cosmosanalysis/module"
"github.com/tendermint/starport/starport/pkg/cosmosgen"
"github.com/tendermint/starport/starport/pkg/giturl"
)

const (
defaultVuexPath = "vue/src/store"
defaultOpenAPIPath = "docs/static/openapi.yml"
)

type generateOptions struct {
isGoEnabled bool
isVuexEnabled bool
Expand Down Expand Up @@ -41,7 +47,22 @@ func GenerateOpenAPI() GenerateTarget {
}

func (c *Chain) generateAll(ctx context.Context) error {
return c.Generate(ctx, GenerateGo(), GenerateVuex(), GenerateOpenAPI())
conf, err := c.Config()
if err != nil {
return err
}

var additionalTargets []GenerateTarget

if conf.Client.Vuex.Path != "" {
additionalTargets = append(additionalTargets, GenerateVuex())
}

if conf.Client.OpenAPI.Path != "" {
additionalTargets = append(additionalTargets, GenerateOpenAPI())
}

return c.Generate(ctx, GenerateGo(), additionalTargets...)
}

// Generate makes code generation from proto files for given target and additionalTargets.
Expand Down Expand Up @@ -78,8 +99,17 @@ func (c *Chain) Generate(
enableThirdPartyModuleCodegen := !c.protoBuiltAtLeastOnce && c.options.isThirdPartyModuleCodegenEnabled

// generate Vuex code as well if it is enabled.
if targetOptions.isVuexEnabled && conf.Client.Vuex.Path != "" {
storeRootPath := filepath.Join(c.app.Path, conf.Client.Vuex.Path, "generated")
if targetOptions.isVuexEnabled {
vuexPath := conf.Client.Vuex.Path
if vuexPath == "" {
vuexPath = defaultVuexPath
}

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

options = append(options,
cosmosgen.WithVuexGeneration(
enableThirdPartyModuleCodegen,
Expand All @@ -91,8 +121,14 @@ func (c *Chain) Generate(
),
)
}
if targetOptions.isOpenAPIEnabled && conf.Client.OpenAPI.Path != "" {
options = append(options, cosmosgen.WithOpenAPIGeneration(conf.Client.OpenAPI.Path))
if targetOptions.isOpenAPIEnabled {
openAPIPath := conf.Client.OpenAPI.Path

if openAPIPath == "" {
openAPIPath = defaultOpenAPIPath
}

options = append(options, cosmosgen.WithOpenAPIGeneration(openAPIPath))
}

if err := cosmosgen.Generate(ctx, c.app.Path, conf.Build.Proto.Path, options...); err != nil {
Expand Down