Skip to content

Commit ade4632

Browse files
committed
Handle packages with hyphens
1 parent 0ce364c commit ade4632

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ test: lint
1212
go run example/example.go
1313
tsc browser_test/example_output.ts
1414
# Make sure dommandline tool works:
15-
go run tscriptify/main.go -package github.com/tkrajina/typescriptify-golang-structs/example/models -target tmp_classes.ts example/models/example_models.go
16-
go run tscriptify/main.go -package github.com/tkrajina/typescriptify-golang-structs/example/models -target tmp_interfaces.ts -interface example/models/example_models.go
15+
go run tscriptify/main.go -package github.com/tkrajina/typescriptify-golang-structs/example/example-models -verbose -target tmp_classes.ts example/example-models/example_models.go
16+
go run tscriptify/main.go -package github.com/tkrajina/typescriptify-golang-structs/example/example-models -verbose -target tmp_interfaces.ts -interface example/example-models/example_models.go
1717

1818
.PHONY: lint
1919
lint:
2020
go vet ./...
21-
golangci-lint run
21+
golangci-lint run

tscriptify/main.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const TEMPLATE = `package main
3030
import (
3131
"fmt"
3232
33-
"{{ .ModelsPackage }}"
33+
m "{{ .ModelsPackage }}"
3434
"github.com/tkrajina/typescriptify-golang-structs/typescriptify"
3535
)
3636
@@ -57,6 +57,7 @@ type Params struct {
5757
InitParams map[string]interface{}
5858
CustomImports arrayImports
5959
Interface bool
60+
Verbose bool
6061
}
6162

6263
func main() {
@@ -67,6 +68,7 @@ func main() {
6768
flag.StringVar(&backupDir, "backup", "", "Directory where backup files are saved")
6869
flag.BoolVar(&p.Interface, "interface", false, "Create interfaces (not classes)")
6970
flag.Var(&p.CustomImports, "import", "Typescript import for your custom type, repeat this option for each import needed")
71+
flag.BoolVar(&p.Verbose, "verbose", false, "Verbose logs")
7072
flag.Parse()
7173

7274
structs := []string{}
@@ -92,9 +94,6 @@ func main() {
9294
os.Exit(1)
9395
}
9496

95-
packageParts := strings.Split(p.ModelsPackage, "/")
96-
pckg := packageParts[len(packageParts)-1]
97-
9897
t := template.Must(template.New("").Parse(TEMPLATE))
9998

10099
filename, err := ioutil.TempDir(os.TempDir(), "")
@@ -110,7 +109,7 @@ func main() {
110109
for _, str := range structs {
111110
str = strings.TrimSpace(str)
112111
if len(str) > 0 {
113-
structsArr = append(structsArr, pckg+"."+str)
112+
structsArr = append(structsArr, "m."+str)
114113
}
115114
}
116115

@@ -121,6 +120,12 @@ func main() {
121120
err = t.Execute(f, p)
122121
handleErr(err)
123122

123+
if p.Verbose {
124+
byts, err := ioutil.ReadFile(filename)
125+
handleErr(err)
126+
fmt.Printf("\nCompiling generated code (%s):\n%s\n----------------------------------------------------------------------------------------------------\n", filename, string(byts))
127+
}
128+
124129
cmd := exec.Command("go", "run", filename)
125130
fmt.Println(strings.Join(cmd.Args, " "))
126131
output, err := cmd.CombinedOutput()

0 commit comments

Comments
 (0)