Skip to content

Commit

Permalink
added typescript client sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
ppwfx committed May 14, 2020
1 parent 2d04503 commit 552621e
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions metactl/pkg/v0/business/sdk/typescript/typescript.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package typescript

import (
"github.com/metamatex/metamate/metactl/pkg/v0/types"
"github.com/metamatex/metamate/metactl/pkg/v0/utils"
"github.com/metamatex/metamate/metactl/pkg/v0/utils/ptr"
"github.com/pkg/errors"
"os"
)

const (
TaskSetHttpJsonClient = "httpjsonClient"
)

const (
SdkHttpJsonClient = "typescript_httpjson_client"
)

const (
DataPath = "path"
)

var tasks = map[string]types.RenderTask{}

func initSdk(g *types.SdkGenerator, c types.SdkConfig) (err error) {
_, ok := c.Data[DataPath]
if !ok {
err = errors.New("data.path is missing")

return
}

prepareTasks(c.Data, g.Dependencies)
prepareTasks(c.Data, g.Tasks)

return
}

func prepareTasks(data map[string]interface{}, tasks []types.RenderTask) {
for i, _ := range tasks {
tasks[i].TemplateData = ptr.String("// generated by metactl gen \n" + *tasks[i].TemplateData)
tasks[i].Data = data
tasks[i].Out = ptr.String(data[DataPath].(string) + "/" + *tasks[i].Out)
}
}

func resetSdk(c types.SdkConfig) (err error) {
err = os.RemoveAll(c.Data[DataPath].(string) + "/mql_.ts")
if err != nil {
return
}

return
}

func GetSdks() []types.SdkGenerator {
taskSets := map[string][]types.RenderTask{}

taskSets[TaskSetHttpJsonClient] = []types.RenderTask{
tasks[TaskHttpJsonClient],
}

return []types.SdkGenerator{
{
Name: SdkHttpJsonClient,
Description: "typescript client sdk that transports via httpjson",
Tasks: utils.ConcatTaskSets(taskSets[TaskSetHttpJsonClient]),
Init: initSdk,
Reset: resetSdk,
},
}
}

0 comments on commit 552621e

Please sign in to comment.