mirror of
https://github.com/foomo/gotsrpc.git
synced 2025-10-16 12:35:35 +00:00
moving new config into place
This commit is contained in:
parent
c277c42b21
commit
eff3d56c95
@ -1,6 +1,8 @@
|
|||||||
---
|
---
|
||||||
targets:
|
targets:
|
||||||
demo:
|
demo:
|
||||||
|
services:
|
||||||
|
- Service
|
||||||
package: github.com/foomo/gotsrpc/demo
|
package: github.com/foomo/gotsrpc/demo
|
||||||
out: /tmp/test.ts
|
out: /tmp/test.ts
|
||||||
mappings:
|
mappings:
|
||||||
|
|||||||
@ -4,7 +4,11 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"go/format"
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/foomo/gotsrpc"
|
"github.com/foomo/gotsrpc"
|
||||||
"github.com/foomo/gotsrpc/config"
|
"github.com/foomo/gotsrpc/config"
|
||||||
@ -60,8 +64,9 @@ func main() {
|
|||||||
}
|
}
|
||||||
fmt.Println(os.Stderr, buildTargets)
|
fmt.Println(os.Stderr, buildTargets)
|
||||||
|
|
||||||
/*
|
for name, target := range buildTargets {
|
||||||
longPackageName := args[0]
|
fmt.Println(os.Stderr, "building target", name)
|
||||||
|
longPackageName := target.Package
|
||||||
longPackageNameParts := strings.Split(longPackageName, "/")
|
longPackageNameParts := strings.Split(longPackageName, "/")
|
||||||
goFilename := path.Join(goPath, "src", longPackageName, "gotsrpc.go")
|
goFilename := path.Join(goPath, "src", longPackageName, "gotsrpc.go")
|
||||||
|
|
||||||
@ -72,20 +77,19 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
packageName := longPackageNameParts[len(longPackageNameParts)-1]
|
packageName := longPackageNameParts[len(longPackageNameParts)-1]
|
||||||
services, structs, err := gotsrpc.Read(goPath, longPackageName, args[1:])
|
services, structs, err := gotsrpc.Read(goPath, longPackageName, target.Services)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, "an error occured while trying to understand your code", err)
|
fmt.Fprintln(os.Stderr, "an error occured while trying to understand your code", err)
|
||||||
os.Exit(2)
|
os.Exit(2)
|
||||||
}
|
}
|
||||||
jsonDump(structs)
|
ts, err := gotsrpc.RenderTypeScript(services, structs, target.TypeScriptModule)
|
||||||
ts, err := gotsrpc.RenderTypeScript(services, structs, conf)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, "could not generate ts code", err)
|
fmt.Fprintln(os.Stderr, "could not generate ts code", err)
|
||||||
os.Exit(3)
|
os.Exit(3)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(ts)
|
fmt.Println(os.Stdout, ts)
|
||||||
|
|
||||||
gocode, goerr := gotsrpc.RenderGo(services, packageName)
|
gocode, goerr := gotsrpc.RenderGo(services, packageName)
|
||||||
if goerr != nil {
|
if goerr != nil {
|
||||||
@ -105,7 +109,6 @@ func main() {
|
|||||||
fmt.Fprintln(os.Stderr, "could not write go source to file", writeErr)
|
fmt.Fprintln(os.Stderr, "could not write go source to file", writeErr)
|
||||||
os.Exit(5)
|
os.Exit(5)
|
||||||
}
|
}
|
||||||
//fmt.Println(goFilename, gocode)
|
}
|
||||||
//gotsrpc.ReadFile("/Users/jan/go/src/github.com/foomo/gotsrpc/demo/demo.go", []string{"Service"})
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,9 +7,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Target struct {
|
type Target struct {
|
||||||
Name string
|
Package string
|
||||||
Package string
|
Services []string
|
||||||
Services []string
|
TypeScriptModule string `yaml:"module"`
|
||||||
|
Out string
|
||||||
}
|
}
|
||||||
|
|
||||||
type Mapping struct {
|
type Mapping struct {
|
||||||
|
|||||||
@ -5,8 +5,11 @@ import "testing"
|
|||||||
const sampleConf = `---
|
const sampleConf = `---
|
||||||
targets:
|
targets:
|
||||||
demo:
|
demo:
|
||||||
|
services:
|
||||||
|
- Service
|
||||||
package: github.com/foomo/gotsrpc/demo
|
package: github.com/foomo/gotsrpc/demo
|
||||||
out: /tmp/test.ts
|
module: My.Service
|
||||||
|
out: /tmp/my-service.ts
|
||||||
mappings:
|
mappings:
|
||||||
foo/bar:
|
foo/bar:
|
||||||
module: Sample.Module
|
module: Sample.Module
|
||||||
@ -34,4 +37,26 @@ func TestLoadConfig(t *testing.T) {
|
|||||||
if foo.Out != "path/to/ts" || foo.TypeScriptModule != "Sample.Module" {
|
if foo.Out != "path/to/ts" || foo.TypeScriptModule != "Sample.Module" {
|
||||||
t.Fatal("unexpected data", foo)
|
t.Fatal("unexpected data", foo)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// looking at the targets
|
||||||
|
|
||||||
|
demoTarget, ok := c.Targets["demo"]
|
||||||
|
if !ok {
|
||||||
|
t.Fatal("demo target not found")
|
||||||
|
}
|
||||||
|
if demoTarget.Out != "/tmp/my-service.ts" {
|
||||||
|
t.Fatal("demo target out is wrong")
|
||||||
|
}
|
||||||
|
if demoTarget.Package != "github.com/foomo/gotsrpc/demo" {
|
||||||
|
t.Fatal("wrong target package")
|
||||||
|
}
|
||||||
|
if demoTarget.TypeScriptModule != "My.Service" {
|
||||||
|
t.Fatal("wromg ts module")
|
||||||
|
}
|
||||||
|
if len(demoTarget.Services) != 1 {
|
||||||
|
t.Fatal("wrong number of services")
|
||||||
|
}
|
||||||
|
if demoTarget.Services[0] != "Service" {
|
||||||
|
t.Fatal("first serive is wrong")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user