moving new config into place

This commit is contained in:
Jan Halfar 2016-07-21 21:39:38 +02:00
parent c277c42b21
commit eff3d56c95
4 changed files with 44 additions and 13 deletions

View File

@ -1,6 +1,8 @@
---
targets:
demo:
services:
- Service
package: github.com/foomo/gotsrpc/demo
out: /tmp/test.ts
mappings:

View File

@ -4,7 +4,11 @@ import (
"encoding/json"
"flag"
"fmt"
"go/format"
"io/ioutil"
"os"
"path"
"strings"
"github.com/foomo/gotsrpc"
"github.com/foomo/gotsrpc/config"
@ -60,8 +64,9 @@ func main() {
}
fmt.Println(os.Stderr, buildTargets)
/*
longPackageName := args[0]
for name, target := range buildTargets {
fmt.Println(os.Stderr, "building target", name)
longPackageName := target.Package
longPackageNameParts := strings.Split(longPackageName, "/")
goFilename := path.Join(goPath, "src", longPackageName, "gotsrpc.go")
@ -72,20 +77,19 @@ func main() {
}
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 {
fmt.Fprintln(os.Stderr, "an error occured while trying to understand your code", err)
os.Exit(2)
}
jsonDump(structs)
ts, err := gotsrpc.RenderTypeScript(services, structs, conf)
ts, err := gotsrpc.RenderTypeScript(services, structs, target.TypeScriptModule)
if err != nil {
fmt.Fprintln(os.Stderr, "could not generate ts code", err)
os.Exit(3)
}
fmt.Println(ts)
fmt.Println(os.Stdout, ts)
gocode, goerr := gotsrpc.RenderGo(services, packageName)
if goerr != nil {
@ -105,7 +109,6 @@ func main() {
fmt.Fprintln(os.Stderr, "could not write go source to file", writeErr)
os.Exit(5)
}
//fmt.Println(goFilename, gocode)
//gotsrpc.ReadFile("/Users/jan/go/src/github.com/foomo/gotsrpc/demo/demo.go", []string{"Service"})
*/
}
}

View File

@ -7,9 +7,10 @@ import (
)
type Target struct {
Name string
Package string
Services []string
TypeScriptModule string `yaml:"module"`
Out string
}
type Mapping struct {

View File

@ -5,8 +5,11 @@ import "testing"
const sampleConf = `---
targets:
demo:
services:
- Service
package: github.com/foomo/gotsrpc/demo
out: /tmp/test.ts
module: My.Service
out: /tmp/my-service.ts
mappings:
foo/bar:
module: Sample.Module
@ -34,4 +37,26 @@ func TestLoadConfig(t *testing.T) {
if foo.Out != "path/to/ts" || foo.TypeScriptModule != "Sample.Module" {
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")
}
}