mirror of
https://github.com/coder/coder.git
synced 2025-07-13 21:36:50 +00:00
chore: generate rbac resource types to typescript (#13975)
* chore: generate rbac resource types to typescript The existing typesGenerated.ts cannot support this as the generator only inspects the types, not the values. So traversing the value AST would have to be added. The rbac gen is already used for the sdk, this extends it to the typescript
This commit is contained in:
@ -10,11 +10,11 @@ import (
|
||||
"go/format"
|
||||
"go/parser"
|
||||
"go/token"
|
||||
"html/template"
|
||||
"log"
|
||||
"os"
|
||||
"slices"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
@ -27,6 +27,9 @@ var rbacObjectTemplate string
|
||||
//go:embed codersdk.gotmpl
|
||||
var codersdkTemplate string
|
||||
|
||||
//go:embed typescript.tstmpl
|
||||
var typescriptTemplate string
|
||||
|
||||
func usage() {
|
||||
_, _ = fmt.Println("Usage: rbacgen <codersdk|rbac>")
|
||||
_, _ = fmt.Println("Must choose a template target.")
|
||||
@ -43,6 +46,7 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
formatSource := format.Source
|
||||
// It did not make sense to have 2 different generators that do essentially
|
||||
// the same thing, but different format for the BE and the sdk.
|
||||
// So the argument switches the go template to use.
|
||||
@ -52,8 +56,14 @@ func main() {
|
||||
source = codersdkTemplate
|
||||
case "rbac":
|
||||
source = rbacObjectTemplate
|
||||
case "typescript":
|
||||
source = typescriptTemplate
|
||||
formatSource = func(src []byte) ([]byte, error) {
|
||||
// No typescript formatting
|
||||
return src, nil
|
||||
}
|
||||
default:
|
||||
_, _ = fmt.Fprintf(os.Stderr, "%q is not a valid templte target\n", flag.Args()[0])
|
||||
_, _ = fmt.Fprintf(os.Stderr, "%q is not a valid template target\n", flag.Args()[0])
|
||||
usage()
|
||||
os.Exit(2)
|
||||
}
|
||||
@ -63,7 +73,7 @@ func main() {
|
||||
log.Fatalf("Generate source: %s", err.Error())
|
||||
}
|
||||
|
||||
formatted, err := format.Source(out)
|
||||
formatted, err := formatSource(out)
|
||||
if err != nil {
|
||||
log.Fatalf("Format template: %s", err.Error())
|
||||
}
|
||||
|
Reference in New Issue
Block a user