@@ -11,6 +11,7 @@ import (
1111
1212 "golang.org/x/sync/errgroup"
1313
14+ "github.com/ignite/cli/v29/ignite/internal/buf"
1415 "github.com/ignite/cli/v29/ignite/pkg/cache"
1516 "github.com/ignite/cli/v29/ignite/pkg/cosmosanalysis/module"
1617 "github.com/ignite/cli/v29/ignite/pkg/cosmosbuf"
@@ -19,6 +20,8 @@ import (
1920)
2021
2122var (
23+ bufTokenEnvName = "BUF_TOKEN"
24+
2225 dirchangeCacheNamespace = "generate.typescript.dirchange"
2326
2427 protocGenTSProtoBin = "protoc-gen-ts_proto"
@@ -31,15 +34,21 @@ plugins:
3134 - plugin: ts_proto
3235 out: .
3336 opt:
34- - "esModuleInterop=true"
35- - "forceLong=long"
36- - "useOptionals=true"
37+ - logtostderr=true
38+ - allow_merge=true
39+ - json_names_for_fields=false
40+ - ts_proto_opt=snakeToCamel=true
41+ - ts_proto_opt=esModuleInterop=true
42+ - ts_proto_out=.
3743`
3844
3945type tsGenerator struct {
4046 g * generator
4147 tsTemplateFile string
4248 isLocalProto bool
49+
50+ // hasLocalBufToken indicates whether the user had already a local Buf token.
51+ hasLocalBufToken bool
4352}
4453
4554type generatePayload struct {
@@ -54,7 +63,16 @@ func newTSGenerator(g *generator) *tsGenerator {
5463 }
5564
5665 if ! tsg .isLocalProto {
57- log .Printf ("No '%s' binary found in PATH, using remote buf plugin for Typescript generation. %s\n " , protocGenTSProtoBin , msgBufAuth )
66+ if os .Getenv (bufTokenEnvName ) == "" {
67+ token , err := buf .FetchToken ()
68+ if err != nil {
69+ log .Printf ("No '%s' binary found in PATH, using remote buf plugin for Typescript generation. %s\n " , protocGenTSProtoBin , msgBufAuth )
70+ } else {
71+ os .Setenv (bufTokenEnvName , token )
72+ }
73+ } else {
74+ tsg .hasLocalBufToken = true
75+ }
5876 }
5977
6078 return tsg
@@ -83,6 +101,11 @@ func (g *tsGenerator) cleanup() {
83101 if g .tsTemplateFile != "" {
84102 os .Remove (g .tsTemplateFile )
85103 }
104+
105+ // unset ignite buf token from env
106+ if ! g .hasLocalBufToken {
107+ os .Unsetenv (bufTokenEnvName )
108+ }
86109}
87110
88111func (g * generator ) tsTemplate () string {
0 commit comments