feat: added support typescript

This commit is contained in:
2026-03-23 16:04:31 +03:00
parent 40b81de08d
commit d41cef5576
7 changed files with 1469 additions and 35 deletions
+24 -4
View File
@@ -1,28 +1,31 @@
package main
import (
"github.com/edmand46/arpack/generator"
"github.com/edmand46/arpack/parser"
"flag"
"fmt"
"log"
"os"
"path/filepath"
"strings"
"github.com/edmand46/arpack/generator"
"github.com/edmand46/arpack/parser"
)
func main() {
in := flag.String("in", "", "input Go file with struct definitions")
outGo := flag.String("out-go", "", "output directory for generated Go code")
outCS := flag.String("out-cs", "", "output directory for generated C# code")
outTS := flag.String("out-ts", "", "output directory for generated TypeScript code")
namespace := flag.String("cs-namespace", "Arpack.Messages", "C# namespace")
flag.Parse()
if *in == "" {
log.Fatal("arpack: -in is required")
}
if *outGo == "" && *outCS == "" {
log.Fatal("arpack: at least one of -out-go or -out-cs is required")
if *outGo == "" && *outCS == "" && *outTS == "" {
log.Fatal("arpack: at least one of -out-go, -out-cs, or -out-ts is required")
}
schema, err := parser.ParseSchemaFile(*in)
@@ -74,6 +77,23 @@ func main() {
fmt.Printf("arpack: wrote %s\n", outPath)
}
if *outTS != "" {
src, err := generator.GenerateTypeScriptSchema(schema, "Arpack.Messages")
if err != nil {
log.Fatalf("arpack: TypeScript generation error: %v", err)
}
outPath := filepath.Join(*outTS, toTitle(baseName)+".gen.ts")
if err := os.MkdirAll(*outTS, 0755); err != nil {
log.Fatalf("arpack: mkdir %s: %v", *outTS, err)
}
if err := os.WriteFile(outPath, src, 0644); err != nil {
log.Fatalf("arpack: write %s: %v", outPath, err)
}
fmt.Printf("arpack: wrote %s\n", outPath)
}
}
func toTitle(s string) string {