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 @@ -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)
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
25 changes: 21 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,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
}
Expand All @@ -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
}
Expand All @@ -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))
}

Expand Down Expand Up @@ -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")
}
34 changes: 24 additions & 10 deletions ignite/services/scaffolder/scaffolder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand Down