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: support absolute path for client generation config options #2958

Merged
merged 7 commits into from
Oct 26, 2022
Merged
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
- Change nightly tag format
- Add cosmos-sdk version in `version` command
- [#2935](https://github.com/ignite/cli/pull/2935) Update `gobuffalo/plush` templating tool to `v4`
- [#2958](https://github.com/ignite/cli/pull/2958) Support absolute paths for client code generation config paths.
jeronimoalbi marked this conversation as resolved.
Show resolved Hide resolved

### Fixes

Expand Down
4 changes: 2 additions & 2 deletions ignite/pkg/cosmosgen/generate_openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ var openAPIOut = []string{
const specCacheNamespace = "generate.openapi.spec"

func generateOpenAPISpec(g *generator) error {
out := filepath.Join(g.appPath, g.o.specOut)

var (
specDirs []string
conf = swaggercombine.Config{
Expand Down Expand Up @@ -125,6 +123,8 @@ func generateOpenAPISpec(g *generator) error {
}
}

out := g.o.specOut

if !hasAnySpecChanged {
// In case the generated output has been changed
changed, err := dirchange.HasDirChecksumChanged(specCache, out, g.appPath, out)
Expand Down
29 changes: 25 additions & 4 deletions ignite/services/chain/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,12 @@ func (c *Chain) Generate(
if targetOptions.isTSClientEnabled {
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))
tsClientPath = chainconfig.TSClientPath(conf)
}

// Non absolute TS client output paths must be treated as relative to the app directory
if !filepath.IsAbs(tsClientPath) {
tsClientPath = filepath.Join(c.app.Path, tsClientPath)
}

if err := os.MkdirAll(tsClientPath, 0o766); err != nil {
Expand All @@ -160,7 +164,13 @@ func (c *Chain) Generate(
vuexPath = defaultVuexPath
}

vuexPath = filepath.Join(c.app.Path, vuexPath, "generated")
if filepath.IsAbs(vuexPath) {
// TODO: Should we always generate Vuex code inside a "generated" directory?
vuexPath = filepath.Join(vuexPath, "generated")
} else {
vuexPath = filepath.Join(c.app.Path, vuexPath, "generated")
}
jeronimoalbi marked this conversation as resolved.
Show resolved Hide resolved

if err := os.MkdirAll(vuexPath, 0o766); err != nil {
return err
}
Expand All @@ -180,7 +190,13 @@ func (c *Chain) Generate(
dartPath = defaultDartPath
}

dartPath = filepath.Join(c.app.Path, dartPath, "generated")
if filepath.IsAbs(dartPath) {
// TODO: Should we always generate Dart code inside a "generated" directory?
dartPath = filepath.Join(dartPath, "generated")
} else {
dartPath = filepath.Join(c.app.Path, dartPath, "generated")
}

if err := os.MkdirAll(dartPath, 0o766); err != nil {
return err
}
Expand All @@ -200,6 +216,11 @@ func (c *Chain) Generate(
openAPIPath = defaultOpenAPIPath
}

// Non absolute OpenAPI paths must be treated as relative to the app directory
if !filepath.IsAbs(openAPIPath) {
openAPIPath = filepath.Join(c.app.Path, openAPIPath)
}

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

Expand Down
35 changes: 25 additions & 10 deletions ignite/services/scaffolder/scaffolder.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,35 +96,50 @@ func protoc(ctx context.Context, cacheStorage cache.Storage, projectPath, gomodP
cosmosgen.IncludeDirs(conf.Build.Proto.ThirdPartyPaths),
}

// generate Typescript Client code as well if it is enabled or when the vuex store is being generated
// Generate Typescript client code if it's enabled or when Vuex stores are 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 {
tsClientPath := chainconfig.TSClientPath(conf)
if !filepath.IsAbs(tsClientPath) {
tsClientPath = filepath.Join(projectPath, tsClientPath)
}

if err := os.MkdirAll(tsClientPath, 0o766); err != nil {
return err
}

options = append(options,
cosmosgen.WithTSClientGeneration(
cosmosgen.TypescriptModulePath(tsClientRootPath),
tsClientRootPath,
cosmosgen.TypescriptModulePath(tsClientPath),
tsClientPath,
),
)
}

// generate Vuex code as well if it is enabled.
if conf.Client.Vuex.Path != "" {
storeRootPath := filepath.Join(projectPath, conf.Client.Vuex.Path, "generated")
vuexPath := conf.Client.Vuex.Path
if filepath.IsAbs(vuexPath) {
// TODO: Should we always generate Vuex code inside a "generated" directory?
vuexPath = filepath.Join(vuexPath, "generated")
} else {
vuexPath = filepath.Join(projectPath, vuexPath, "generated")
}

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

if conf.Client.OpenAPI.Path != "" {
options = append(options, cosmosgen.WithOpenAPIGeneration(conf.Client.OpenAPI.Path))
openAPIPath := conf.Client.OpenAPI.Path
if !filepath.IsAbs(openAPIPath) {
openAPIPath = filepath.Join(projectPath, openAPIPath)
}

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

return cosmosgen.Generate(ctx, cacheStorage, projectPath, conf.Build.Proto.Path, options...)
Expand Down