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
4 changes: 3 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

## Unreleased

## [`v29.3.0`](https://github.com/ignite/cli/releases/tag/v29.3.0)

### Features

- [#4786](https://github.com/ignite/cli/pull/4786) Add all types to the documentation and disclaimer for multiple coin types.

### Changes

- [#4780](https://github.com/ignite/cli/pull/4780) Fallback to local generation when possible in `generate ts-client` command.
- [#4779](https://github.com/ignite/cli/pull/4779) Do not re-gen openapi spec each time the `ts-client` or the `composables` are generated.
- [#4784](https://github.com/ignite/cli/pull/4784) Remove unused message initialization.

Expand Down Expand Up @@ -910,7 +913,6 @@ Our new name is **Ignite CLI**!
in [PR 1971](https://github.com/ignite/cli/pull/1971/files)

Updates are required if your chain uses these packages:

- `spm/ibckeeper` is now `pkg/cosmosibckeeper`
- `spm/cosmoscmd` is now `pkg/cosmoscmd`
- `spm/openapiconsole` is now `pkg/openapiconsole`
Expand Down
13 changes: 12 additions & 1 deletion docs/docs/04-clients/02-typescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
description: Information about the generated TypeScript client code.
---

# TypeScript frontend
# TypeScript library

Ignite offers powerful functionality for generating client-side code for your
blockchain. Think of this as a one-click client SDK generation tailored
Expand Down Expand Up @@ -35,6 +35,17 @@ SDK modules:
ignite generate ts-client --clear-cache
```

:::tip
In order to not rely on the remote `buf.build` service, you can install the
`protoc-gen-ts_proto` binary locally and Ignite will use it instead of the remote plugin.

```sh
npm install -g ts-proto
```

Learn more at <https://github.com/stephenh/ts-proto>
:::

Run a command to start your blockchain node:

```
Expand Down
22 changes: 4 additions & 18 deletions ignite/cmd/generate_typescript_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,10 @@ import (

"github.com/ignite/cli/v29/ignite/pkg/cliui"
"github.com/ignite/cli/v29/ignite/pkg/cliui/icons"
"github.com/ignite/cli/v29/ignite/pkg/errors"
"github.com/ignite/cli/v29/ignite/services/chain"
)

const (
flagUseCache = "use-cache"
msgBufAuth = "Generate ts-client uses a 'buf.build' remote plugin. Buf is begin limiting remote plugin requests from unauthenticated users on 'buf.build'. Intensively using this function will get you rate limited. Authenticate with 'buf registry login' to avoid this (https://buf.build/docs/generate/auth-required)."
)
const flagDisableCache = "disable-cache"

func NewGenerateTSClient() *cobra.Command {
c := &cobra.Command{
Expand Down Expand Up @@ -41,7 +37,7 @@ changes when the blockchain is started with a flag:

c.Flags().AddFlagSet(flagSetYes())
c.Flags().StringP(flagOutput, "o", "", "TypeScript client output path")
c.Flags().Bool(flagUseCache, false, "use build cache to speed-up generation")
c.Flags().Bool(flagDisableCache, false, "disable build cache")

return c
}
Expand All @@ -53,16 +49,6 @@ func generateTSClientHandler(cmd *cobra.Command, _ []string) error {
)
defer session.End()

if !getYes(cmd) {
if err := session.AskConfirm(msgBufAuth); err != nil {
if errors.Is(err, cliui.ErrAbort) {
return errors.New("buf not auth")
}

return err
}
}

c, err := chain.NewWithHomeFlags(
cmd,
chain.WithOutputer(session),
Expand All @@ -79,14 +65,14 @@ func generateTSClientHandler(cmd *cobra.Command, _ []string) error {
}

output, _ := cmd.Flags().GetString(flagOutput)
useCache, _ := cmd.Flags().GetBool(flagUseCache)
disableCache, _ := cmd.Flags().GetBool(flagDisableCache)

var opts []chain.GenerateTarget
if flagGetEnableProtoVendor(cmd) {
opts = append(opts, chain.GenerateProtoVendor())
}

err = c.Generate(cmd.Context(), cacheStorage, chain.GenerateTSClient(output, useCache), opts...)
err = c.Generate(cmd.Context(), cacheStorage, chain.GenerateTSClient(output, !disableCache), opts...)
if err != nil {
return err
}
Expand Down
67 changes: 63 additions & 4 deletions ignite/pkg/cosmosgen/generate_typescript.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"log"
"os"
"os/exec"
"path/filepath"
"sort"
"strings"
Expand All @@ -17,10 +18,28 @@ import (
"github.com/ignite/cli/v29/ignite/pkg/gomodulepath"
)

var dirchangeCacheNamespace = "generate.typescript.dirchange"
var (
dirchangeCacheNamespace = "generate.typescript.dirchange"

protocGenTSProtoBin = "protoc-gen-ts_proto"

msgBufAuth = "Note: Buf is limits remote plugin requests from unauthenticated users on 'buf.build'. Intensively using this function will get you rate limited. Authenticate with 'buf registry login' to avoid this (https://buf.build/docs/generate/auth-required)."
)

const localTSProtoTmpl = `version: v1
plugins:
- plugin: ts_proto
out: .
opt:
- "esModuleInterop=true"
- "forceLong=long"
- "useOptionals=true"
`

type tsGenerator struct {
g *generator
g *generator
tsTemplateFile string
isLocalProto bool
}

type generatePayload struct {
Expand All @@ -29,7 +48,41 @@ type generatePayload struct {
}

func newTSGenerator(g *generator) *tsGenerator {
return &tsGenerator{g}
tsg := &tsGenerator{g: g}
if _, err := exec.LookPath(protocGenTSProtoBin); err == nil {
tsg.isLocalProto = true
}

if !tsg.isLocalProto {
log.Printf("No '%s' binary found in PATH, using remote buf plugin for Typescript generation. %s\n", protocGenTSProtoBin, msgBufAuth)
}

return tsg
}

func (g *tsGenerator) tsTemplate() (string, error) {
if !g.isLocalProto {
return g.g.tsTemplate(), nil
}
if g.tsTemplateFile != "" {
return g.tsTemplateFile, nil
}
f, err := os.CreateTemp("", "buf-gen-ts-*.yaml")
if err != nil {
return "", err
}
defer f.Close()
if _, err := f.WriteString(localTSProtoTmpl); err != nil {
return "", err
}
g.tsTemplateFile = f.Name()
return g.tsTemplateFile, nil
}

func (g *tsGenerator) cleanup() {
if g.tsTemplateFile != "" {
os.Remove(g.tsTemplateFile)
}
}

func (g *generator) tsTemplate() string {
Expand All @@ -56,6 +109,7 @@ func (g *generator) generateTS(ctx context.Context) error {
})

tsg := newTSGenerator(g)
defer tsg.cleanup()
if err := tsg.generateModuleTemplates(ctx); err != nil {
return err
}
Expand Down Expand Up @@ -154,12 +208,17 @@ func (g *tsGenerator) generateModuleTemplate(
}
}

tsTemplate, err := g.tsTemplate()
if err != nil {
return err
}

// code generate for each module.
if err := g.g.buf.Generate(
ctx,
protoPath,
typesOut,
g.g.tsTemplate(),
tsTemplate,
cosmosbuf.IncludeWKT(),
cosmosbuf.WithModuleName(m.Pkg.Name),
); err != nil {
Expand Down
Loading