Files
mesh-catalog/modules/mesh-build-go/buildstep/cmd/seatgen/main.go
T
jschoubben 7b08f25d4a CAT-BG4/BN1: the seat generator moves into buildstep, one program for Go and TypeScript
Its version is the build module's own, so a new generator is a new build of
mesh-build-go and mesh-build-node and a new fingerprint of what they compare;
no repository of its own. Moved from seatgen c1fdd7c unchanged but for the
import path.

Claude-Session: https://claude.ai/code/session_01JG73KJNrH5EgFXMKKYSrig
2026-11-04 15:12:46 +01:00

79 lines
2.2 KiB
Go

// 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", "git.novox.be/novox/mesh-contracts/go", "the generated Go tree's module path")
tsPackage := flag.String("ts-package", "@novox/mesh-contracts", "the generated TypeScript package's name")
flag.Parse()
dir := flag.Arg(0)
m, err := seatgen.Load(dir, *goModule, *tsPackage)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
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")
}