grafana/public/app/plugins/gen.go
sam boyer 8876d56495
schema: Migrate from scuemata to thema (#49805)
* Remove crufty scuemata bits

Buhbye to: cue/ dir with old definitions, CI steps for checking unnecessary
things, and the original dashboard scuemata file.

* Remove grafana-cli cue subcommand

* Remove old testdata

* Don't swallow errors from codegen

* Small nits and tweaks to cuectx package

* WIP - refactor pluggen to use Thema

Also consolidate the embed.FS in the repo root.

* Finish halfway rename

* Convert all panel models.cue to thema

* Rewrite pluggen to use Thema

* Remove pkg/schema, and trim command

* Remove schemaloader service and usages

Will be replaced by coremodel-centric hydrate/dehydrate system Soon™.

* Remove schemaloader from wire

* Remove hangover field on histogram models.cue

* Fix lint errors, some vestiges of trim service

* Remove unused cuetsify cli command
2022-06-06 17:52:44 -07:00

68 lines
1.5 KiB
Go

// go:build ignore
//go:build ignore
// +build ignore
package main
import (
"errors"
"fmt"
"os"
"path/filepath"
"cuelang.org/go/cue/cuecontext"
"github.com/grafana/grafana/pkg/codegen"
)
// Generate TypeScript for all plugin models.cue
func main() {
if len(os.Args) > 1 {
fmt.Fprintf(os.Stderr, "plugin thema code generator does not currently accept any arguments\n, got %q", os.Args)
os.Exit(1)
}
cwd, err := os.Getwd()
if err != nil {
fmt.Fprintf(os.Stderr, "could not get working directory: %s", err)
os.Exit(1)
}
var find func(path string) (string, error)
find = func(path string) (string, error) {
parent := filepath.Dir(path)
if parent == path {
return "", errors.New("grafana root directory could not be found")
}
fp := filepath.Join(path, "go.mod")
if _, err := os.Stat(fp); err == nil {
return path, nil
}
return find(parent)
}
groot, err := find(cwd)
if err != nil {
fmt.Fprint(os.Stderr, err)
os.Exit(1)
}
wd, err := codegen.CuetsifyPlugins(cuecontext.New(), groot)
if err != nil {
fmt.Fprintf(os.Stderr, "error while generating code:\n%s\n", err)
os.Exit(1)
}
if _, set := os.LookupEnv("CODEGEN_VERIFY"); set {
err = wd.Verify()
if err != nil {
fmt.Fprintf(os.Stderr, "generated code is out of sync with inputs:\n%s\nrun `make gen-cue` to regenerate\n\n", err)
os.Exit(1)
}
} else {
err = wd.Write()
if err != nil {
fmt.Fprintf(os.Stderr, "error while writing generated code to disk:\n%s\n", err)
os.Exit(1)
}
}
}