// Command seatgen writes, or with -check compares, a contracts module's generated Go and TypeScript. package main import ( "flag" "fmt" "os" "path/filepath" "sort" "git.novox.be/novox/mesh-catalog/modules/mesh-build-go/buildstep/seatgen" ) func main() { check := flag.Bool("check", false, "compare instead of writing: name every path out of step") goModule := flag.String("go-module", "", "the generated Go tree's module path, such as git.novox.be/novox/mesh-contracts//go (there is no root module)") tsPackage := flag.String("ts-package", "", "the generated TypeScript package's name, such as @novox/mesh-contracts-") domainSDK := flag.String("domain-sdk", "", "the Go module of the contracts module's domain SDK, which a client may import (ADR 0634 §2); empty when it has none") flag.Parse() dir := flag.Arg(0) m, err := seatgen.Load(dir, *goModule, *tsPackage) if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } m.DomainSDK = *domainSDK files, err := seatgen.Generate(m) if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } if *check { out, err := seatgen.Compare(dir, files) if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } // The clients beside the contracts (ADR 0627 §3) and module.json's Go and npm package artifacts (ADR 0625 §1, §3). for _, check := range []func(string, *seatgen.Module) ([]string, error){seatgen.CheckClients, seatgen.CheckArtifacts} { more, err := check(dir, m) if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } out = append(out, more...) } for _, p := range out { fmt.Println(p) } if len(out) > 0 { os.Exit(1) } return } for _, root := range seatgen.GeneratedRoots { _ = os.RemoveAll(filepath.Join(dir, root, "src")) } // Each seat's npm package's sources too (ADR 0625 §1), so a file no definition writes any more is gone. stale, _ := filepath.Glob(filepath.Join(dir, "ts", "seats", "*", "src")) for _, p := range stale { _ = os.RemoveAll(p) } paths := make([]string, 0, len(files)) for p := range files { paths = append(paths, p) } sort.Strings(paths) for _, p := range paths { full := filepath.Join(dir, p) if err := os.MkdirAll(filepath.Dir(full), 0o755); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } if err := os.WriteFile(full, files[p], 0o644); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } } fmt.Println(len(paths), "files") }