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
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Fixes

- Change vuex generation to use a default TS client path.
- Fix cli action org in templates.
- Seal the capability keeper in the `app.go` template

Expand Down
19 changes: 18 additions & 1 deletion ignite/chainconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,20 @@ import (
"io"
"os"
"path/filepath"
"strings"

"github.com/goccy/go-yaml"
"github.com/imdario/mergo"

"github.com/ignite/cli/ignite/pkg/xfilepath"
)

const (
// DefaultTSClientPath defines the default relative path to use when generating the TS client.
// The path is relative to the app's directory.
DefaultTSClientPath = "ts-client"
)

var (
// ConfigDirPath returns the path of configuration directory of Ignite.
ConfigDirPath = xfilepath.JoinFromHome(xfilepath.Path(".ignite"))
Expand Down Expand Up @@ -253,7 +260,7 @@ func LocateDefault(root string) (path string, err error) {
return "", ErrCouldntLocateConfig
}

// FaucetHost returns the faucet host to use
// FaucetHost returns the faucet host to use.
func FaucetHost(conf Config) string {
// We keep supporting Port option for backward compatibility
// TODO: drop this option in the future
Expand All @@ -265,6 +272,16 @@ func FaucetHost(conf Config) string {
return host
}

// TSClientPath returns the relative path to the Typescript client directory.
// Path is relative to the app's directory.
func TSClientPath(conf Config) string {
if path := strings.TrimSpace(conf.Client.Typescript.Path); path != "" {
return filepath.Clean(path)
}

return DefaultTSClientPath
}

// CreateConfigDir creates config directory if it is not created yet.
func CreateConfigDir() error {
confPath, err := ConfigDirPath()
Expand Down
12 changes: 11 additions & 1 deletion ignite/cmd/generate_typescript_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ignitecmd
import (
"github.com/spf13/cobra"

"github.com/ignite/cli/ignite/chainconfig"
"github.com/ignite/cli/ignite/pkg/cliui"
"github.com/ignite/cli/ignite/services/chain"
)
Expand All @@ -13,7 +14,10 @@ func NewGenerateTSClient() *cobra.Command {
Short: "Generate Typescript client for your chain's frontend",
RunE: generateTSClientHandler,
}

c.Flags().AddFlagSet(flagSetProto3rdParty(""))
c.Flags().StringP(flagOutput, "o", chainconfig.DefaultTSClientPath, "typescript client output path")

return c
}

Expand All @@ -33,7 +37,13 @@ func generateTSClientHandler(cmd *cobra.Command, args []string) error {
return err
}

if err := c.Generate(cmd.Context(), cacheStorage, chain.GenerateTSClient()); err != nil {
output, err := cmd.Flags().GetString(flagOutput)
if err != nil {
return err
}

err = c.Generate(cmd.Context(), cacheStorage, chain.GenerateTSClient(output))
if err != nil {
return err
}

Expand Down
16 changes: 13 additions & 3 deletions ignite/pkg/cosmosgen/generate_vuex.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cosmosgen

import (
"encoding/json"
"errors"
"fmt"
"os"
"path/filepath"
Expand All @@ -27,6 +28,9 @@ func (g *generator) updateVueDependencies() error {
// Init the path to the "vue" folder inside the app
vuePath := filepath.Join(g.appPath, "vue")
packagesPath := filepath.Join(vuePath, "package.json")
if _, err := os.Stat(packagesPath); errors.Is(err, os.ErrNotExist) {
return nil
}

// Read the Vue app package file
b, err := os.ReadFile(packagesPath)
Expand All @@ -40,23 +44,29 @@ func (g *generator) updateVueDependencies() error {
return fmt.Errorf("error parsing %s: %w", packagesPath, err)
}

// Add the link to the ts-client to the VUE app dependencies
chainPath, _, err := gomodulepath.Find(g.appPath)
if err != nil {
return err
}

// Make sure the TS client path is absolute
tsClientPath, err := filepath.Abs(g.o.tsClientRootPath)
if err != nil {
return fmt.Errorf("failed to read the absolute typescript client path: %w", err)
}

// Add the link to the ts-client to the VUE app dependencies
appModulePath := gomodulepath.ExtractAppPath(chainPath.RawPath)
tsClientNS := strings.ReplaceAll(appModulePath, "/", "-")
tsClientName := fmt.Sprintf("%s-client-ts", tsClientNS)
tsClientPath, err := filepath.Rel(vuePath, g.o.tsClientRootPath)
tsClientRelPath, err := filepath.Rel(vuePath, tsClientPath)
if err != nil {
return err
}

err = mergo.Merge(&pkg, map[string]interface{}{
"dependencies": map[string]interface{}{
tsClientName: fmt.Sprintf("file:%s", tsClientPath),
tsClientName: fmt.Sprintf("file:%s", tsClientRelPath),
},
})
if err != nil {
Expand Down
30 changes: 17 additions & 13 deletions ignite/services/chain/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ import (
"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/cosmosgen"
)

const (
defaultTSClientPath = "ts-client"
defaultVuexPath = "vue/src/store"
defaultDartPath = "flutter/lib"
defaultOpenAPIPath = "docs/static/openapi.yml"
defaultVuexPath = "vue/src/store"
defaultDartPath = "flutter/lib"
defaultOpenAPIPath = "docs/static/openapi.yml"
)

type generateOptions struct {
Expand All @@ -24,6 +24,7 @@ type generateOptions struct {
isVuexEnabled bool
isDartEnabled bool
isOpenAPIEnabled bool
tsClientPath string
}

// GenerateTarget is a target to generate code for from proto files.
Expand All @@ -37,9 +38,12 @@ func GenerateGo() GenerateTarget {
}

// GenerateTSClient enables generating proto based Typescript Client.
func GenerateTSClient() GenerateTarget {
// The path assigns the output path to use for the generated Typescript client
// overriding the configured or default path. Path can be an empty string.
func GenerateTSClient(path string) GenerateTarget {
return func(o *generateOptions) {
o.isTSClientEnabled = true
o.tsClientPath = path
}
}

Expand Down Expand Up @@ -75,8 +79,8 @@ func (c *Chain) generateFromConfig(ctx context.Context, cacheStorage cache.Stora
var additionalTargets []GenerateTarget

// parse config for additional target
if conf.Client.Typescript.Path != "" {
additionalTargets = append(additionalTargets, GenerateTSClient())
if p := conf.Client.Typescript.Path; p != "" {
additionalTargets = append(additionalTargets, GenerateTSClient(p))
}

if conf.Client.Vuex.Path != "" {
Expand Down Expand Up @@ -130,20 +134,20 @@ func (c *Chain) Generate(

// generate Typescript Client code as well if it is enabled.
if targetOptions.isTSClientEnabled {
tsClientPath := conf.Client.Typescript.Path
tsClientPath := targetOptions.tsClientPath
if tsClientPath == "" {
tsClientPath = defaultTSClientPath
// 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))
}

tsClientRootPath := filepath.Join(c.app.Path, tsClientPath)
if err := os.MkdirAll(tsClientRootPath, 0o766); err != nil {
if err := os.MkdirAll(tsClientPath, 0o766); err != nil {
return err
}

options = append(options,
cosmosgen.WithTSClientGeneration(
cosmosgen.TypescriptModulePath(tsClientRootPath),
tsClientRootPath,
cosmosgen.TypescriptModulePath(tsClientPath),
tsClientPath,
),
)
}
Expand Down
6 changes: 3 additions & 3 deletions ignite/services/scaffolder/scaffolder.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ func protoc(cacheStorage cache.Storage, projectPath, gomodPath string) error {
cosmosgen.IncludeDirs(conf.Build.Proto.ThirdPartyPaths),
}

// generate Typescript Client code as well if it is enabled.
if conf.Client.Typescript.Path != "" {
tsClientRootPath := filepath.Join(projectPath, conf.Client.Typescript.Path)
// generate Typescript Client code as well if it is enabled or when the vuex store is being generated
if conf.Client.Typescript.Path != "" || conf.Client.Vuex.Path != "" {
tsClientRootPath := filepath.Join(projectPath, chainconfig.TSClientPath(conf))
if err := os.MkdirAll(tsClientRootPath, 0o766); err != nil {
return err
}
Expand Down