diff --git a/changelog.md b/changelog.md index 415c200665..cd08e59044 100644 --- a/changelog.md +++ b/changelog.md @@ -11,6 +11,7 @@ - [#2957](https://github.com/ignite/cli/pull/2957) Change generate commands to print the path to the generated code. - [#2981](https://github.com/ignite/cli/issues/2981) Change CLI to also search chain binary in Go binary path. +- [#2958](https://github.com/ignite/cli/pull/2958) Support absolute paths for client code generation config paths. - [#2993](https://github.com/ignite/cli/pull/2993) Hide `ignite scaffold band` command and deprecate functionality. ## [`v0.25.1`](https://github.com/ignite/cli/releases/tag/v0.25.1) diff --git a/ignite/pkg/cosmosgen/generate_openapi.go b/ignite/pkg/cosmosgen/generate_openapi.go index d3ee4b3a0a..eb228cae4a 100644 --- a/ignite/pkg/cosmosgen/generate_openapi.go +++ b/ignite/pkg/cosmosgen/generate_openapi.go @@ -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{ @@ -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) diff --git a/ignite/services/chain/generate.go b/ignite/services/chain/generate.go index 3958d1713f..f4edcfbae8 100644 --- a/ignite/services/chain/generate.go +++ b/ignite/services/chain/generate.go @@ -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 { @@ -160,7 +164,7 @@ func (c *Chain) Generate( vuexPath = defaultVuexPath } - vuexPath = filepath.Join(c.app.Path, vuexPath, "generated") + vuexPath = c.joinGeneratedPath(vuexPath) if err := os.MkdirAll(vuexPath, 0o766); err != nil { return err } @@ -180,7 +184,7 @@ func (c *Chain) Generate( dartPath = defaultDartPath } - dartPath = filepath.Join(c.app.Path, dartPath, "generated") + dartPath = c.joinGeneratedPath(dartPath) if err := os.MkdirAll(dartPath, 0o766); err != nil { return err } @@ -200,6 +204,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)) } @@ -245,3 +254,11 @@ func (c *Chain) Generate( return nil } + +func (c Chain) joinGeneratedPath(rootPath string) string { + if filepath.IsAbs(rootPath) { + return filepath.Join(rootPath, "generated") + } + + return filepath.Join(c.app.Path, rootPath, "generated") +} diff --git a/ignite/services/scaffolder/scaffolder.go b/ignite/services/scaffolder/scaffolder.go index 5ef02aa558..3e362dc3a8 100644 --- a/ignite/services/scaffolder/scaffolder.go +++ b/ignite/services/scaffolder/scaffolder.go @@ -96,35 +96,49 @@ 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) { + 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...)