diff --git a/config.go b/config.go index ce6f298..3db4bad 100644 --- a/config.go +++ b/config.go @@ -36,6 +36,7 @@ type SdkDestination struct { Golang *string `yaml:"go,omitempty"` Java *string `yaml:"java,omitempty"` Python *string `yaml:"python,omitempty"` + TS *string `yaml:"ts,omitempty"` } type CPMConfig struct { @@ -121,8 +122,16 @@ func (c *CPMConfig) getHosts(networkLabel string) []string { } func (c *CPMConfig) getSdkDestination(forLanguage string) string { - if c.Defaults.OnChain == nil { - return generators.OutputRoot + forLanguage + "/" + // TODO: this is a bit of a hack + // Resolve this properly once we have a second language that can do off-chain generation or a language that supports both + if forLanguage == LANG_TYPESCRIPT { + if c.Defaults.OffChain == nil { + return generators.OutputRoot + forLanguage + "/" + } + } else { + if c.Defaults.OnChain == nil { + return generators.OutputRoot + forLanguage + "/" + } } defaultLocation := generators.OutputRoot + forLanguage + "/" @@ -147,6 +156,11 @@ func (c *CPMConfig) getSdkDestination(forLanguage string) string { return EnsureSuffix(*path) } return defaultLocation + case LANG_TYPESCRIPT: + if path := c.Defaults.OffChain.SdkDestinations.TS; path != nil { + return EnsureSuffix(*path) + } + return defaultLocation default: return defaultLocation } diff --git a/docs/config.md b/docs/config.md index 7e1e645..8257c28 100644 --- a/docs/config.md +++ b/docs/config.md @@ -35,7 +35,7 @@ It has 4 major sections which will be described in detail later on # tools Currently `neo-express` is the only tool that supports downloading contracts. An [issue](https://github.com/nspcc-dev/neo-go/issues/2406) exists for `neo-go` to add download support. -For SDK generation `C#`, `Java`, `Golang` and `Python` are supported. +For on-chain SDK generation `C#`, `Java`, `Golang` and `Python` are supported. For off-chain SDK generation `ts` is supported. Each tool must specify the following 2 keys * `canGenerateSDK` - indicates if the tool can be used for generating SDKs. Must be a bool value. diff --git a/main.go b/main.go index c27952c..f35476f 100644 --- a/main.go +++ b/main.go @@ -422,6 +422,13 @@ func fetchManifestAndGenerateSDK(c *ContractConfig, host string) error { if c.OnChain != nil { languages = c.OnChain.Languages } + + if c.OffChain != nil { + languages = append(languages, c.OffChain.Languages...) + } else { + languages = append(languages, cfg.Defaults.OffChain.Languages...) + } + for _, l := range languages { err = generateSDK(m, c.ScriptHash, l, cfg.getSdkDestination(l)) if err != nil {