mirror of
https://github.com/grafana/grafana.git
synced 2025-02-03 20:21:01 -06:00
be06d37a20
* Add go code generator for coremodels * Just generate the entire coremodel for now Maybe we'll need more flexibility as more coremodels are added, but for now this is fine. * Add note on type comment about stability, grodkit * Remove local replace directive for thema * Generate typescript from coremodel * Update pkg/coremodel/dashboard/addenda.go Co-authored-by: Ryan McKinley <ryantxu@gmail.com> * Update cuetsy to new release * Update thema to latest * Fix enum generation for FieldColorModeId * Put main generated object at the end of the file * Tweaks to generated Go output * Retweak back to var * Add generated coremodel test * Remove local replace statement again * Add Make target and call into cuetsy cmd from gen * Rename and comment linsrc for readability * Move key codegen bits into reusable package * Move body of cuetsifier into codegen pkg Also genericize the diffing output into reusable WriteDiffer. * Refactor coremodel generator to use WriteDiffer * Add gen-cue step to CI * Whip all the codegen automation into shape * Add simplistic coremodel canonicality controls * Remove erroneously committed test * Bump thema version * Remove dead code * Improve wording of non-canonicality comment Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
64 lines
1.4 KiB
Go
64 lines
1.4 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 _, 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)
|
|
}
|
|
}
|
|
}
|