mirror of https://github.com/grafana/grafana
Kindsys: Rename mudball to common schemas, allow multiple input cue files (#61703)
* kindsys: Rename mudball to common schemas * Update all core plugin imports * Add missed table types * Remove invalid JSON comment * Remove coremodel dir from codeownerspull/61648/head
parent
ef6d73e575
commit
492bdbd585
@ -0,0 +1,69 @@ |
||||
package common |
||||
|
||||
// Internally, this is the "type" of cell that's being displayed |
||||
// in the table such as colored text, JSON, gauge, etc. |
||||
// The color-background-solid, gradient-gauge, and lcd-gauge |
||||
// modes are deprecated in favor of new cell subOptions |
||||
TableCellDisplayMode: "auto" | "color-text" | "color-background" | "color-background-solid" | "gradient-gauge" | "lcd-gauge" | "json-view" | "basic" | "image" | "gauge" @cuetsy(kind="enum",memberNames="Auto|ColorText|ColorBackground|ColorBackgroundSolid|GradientGauge|LcdGauge|JSONView|BasicGauge|Image|Gauge") |
||||
|
||||
// Display mode to the "Colored Background" display |
||||
// mode for table cells. Either displays a solid color (basic mode) |
||||
// or a gradient. |
||||
TableCellBackgroundDisplayMode: "basic" | "gradient" @cuetsy(kind="enum",memberNames="Basic|Gradient") |
||||
|
||||
// TODO docs |
||||
TableSortByFieldState: { |
||||
displayName: string |
||||
desc?: bool |
||||
} @cuetsy(kind="interface") |
||||
|
||||
// Auto mode table cell options |
||||
TableAutoCellOptions: { |
||||
type: TableCellDisplayMode & "auto" |
||||
} @cuetsy(kind="interface") |
||||
|
||||
// Colored text cell options |
||||
TableColorTextCellOptions: { |
||||
type: TableCellDisplayMode & "color-text" |
||||
} @cuetsy(kind="interface") |
||||
|
||||
// Json view cell options |
||||
TableJsonViewCellOptions: { |
||||
type: TableCellDisplayMode & "json-view" |
||||
} @cuetsy(kind="interface") |
||||
|
||||
// Json view cell options |
||||
TableImageCellOptions: { |
||||
type: TableCellDisplayMode & "image" |
||||
} @cuetsy(kind="interface") |
||||
|
||||
// Gauge cell options |
||||
TableBarGaugeCellOptions: { |
||||
type: TableCellDisplayMode & "gauge" |
||||
mode?: BarGaugeDisplayMode |
||||
} @cuetsy(kind="interface") |
||||
|
||||
// Colored background cell options |
||||
TableColoredBackgroundCellOptions: { |
||||
type: TableCellDisplayMode & "color-background" |
||||
mode?: TableCellBackgroundDisplayMode |
||||
} @cuetsy(kind="interface") |
||||
|
||||
// Table cell options. Each cell has a display mode |
||||
// and other potential options for that display. |
||||
TableCellOptions: TableAutoCellOptions | TableBarGaugeCellOptions | TableColoredBackgroundCellOptions | TableColorTextCellOptions | TableImageCellOptions | TableJsonViewCellOptions @cuetsy(kind="type") |
||||
|
||||
// Field options for each field within a table (e.g 10, "The String", 64.20, etc.) |
||||
// Generally defines alignment, filtering capabilties, display options, etc. |
||||
TableFieldOptions: { |
||||
width?: number |
||||
minWidth?: number |
||||
align: FieldTextAlignment | *"auto" |
||||
// This field is deprecated in favor of using cellOptions |
||||
displayMode?: TableCellDisplayMode |
||||
cellOptions: TableCellOptions |
||||
hidden?: bool // ?? default is missing or false ?? |
||||
inspect: bool | *false |
||||
filterable?: bool |
||||
} @cuetsy(kind="interface") |
||||
|
@ -0,0 +1,10 @@ |
||||
package common |
||||
|
||||
// Use UTC/GMT timezone |
||||
TimeZoneUtc: "utc" @cuetsy(kind="type") |
||||
|
||||
// Use the timezone defined by end user web browser |
||||
TimeZoneBrowser: "browser" @cuetsy(kind="type") |
||||
|
||||
// A specific timezone from https://en.wikipedia.org/wiki/Tz_database |
||||
TimeZone: TimeZoneUtc | TimeZoneBrowser | string | *"browser" @cuetsy(kind="type") |
@ -1,5 +1,4 @@ |
||||
{ |
||||
// dashboard_experimental.gen.ts needs ignoring as isolatedModules requires it to contain an import or export statement. |
||||
"exclude": ["dist/**/*", "src/schema/dashboard/dashboard_experimental.gen.ts", "**/*.test.ts*"], |
||||
"exclude": ["dist/**/*", "**/*.test.ts*"], |
||||
"extends": "./tsconfig.json" |
||||
} |
||||
|
@ -1,104 +0,0 @@ |
||||
//go:build ignore
|
||||
// +build ignore
|
||||
|
||||
//go:generate go run gen.go
|
||||
|
||||
package main |
||||
|
||||
import ( |
||||
"fmt" |
||||
"os" |
||||
"path/filepath" |
||||
|
||||
"cuelang.org/go/cue/cuecontext" |
||||
"cuelang.org/go/cue/load" |
||||
"github.com/grafana/cuetsy" |
||||
gcgen "github.com/grafana/grafana/pkg/codegen" |
||||
) |
||||
|
||||
const sep = string(filepath.Separator) |
||||
|
||||
var tsroot, cmroot, groot string |
||||
|
||||
func init() { |
||||
cwd, err := os.Getwd() |
||||
if err != nil { |
||||
fmt.Fprintf(os.Stderr, "could not get working directory: %s", err) |
||||
os.Exit(1) |
||||
} |
||||
|
||||
// TODO this binds us to only having coremodels in a single directory. If we need more, compgen is the way
|
||||
groot = filepath.Dir(filepath.Dir(filepath.Dir(cwd))) // the working dir is <grafana_dir>/pkg/framework/coremodel. Going up 3 dirs we get the grafana root
|
||||
|
||||
cmroot = filepath.Join(groot, "pkg", "coremodel") |
||||
tsroot = filepath.Join(groot, "packages", "grafana-schema", "src") |
||||
} |
||||
|
||||
// Generate Go and Typescript implementations for all coremodels, and populate the
|
||||
// coremodel static registry.
|
||||
func main() { |
||||
if len(os.Args) > 1 { |
||||
fmt.Fprintf(os.Stderr, "coremodel code generator does not currently accept any arguments\n, got %q", os.Args) |
||||
os.Exit(1) |
||||
} |
||||
|
||||
wd := gcgen.NewWriteDiffer() |
||||
|
||||
// TODO generating these is here temporarily until we make a more permanent home
|
||||
wdsh, err := genSharedSchemas(groot) |
||||
if err != nil { |
||||
fmt.Fprintf(os.Stderr, "TS gen error for shared schemas in %s: %w", filepath.Join(groot, "packages", "grafana-schema", "src", "schema"), err) |
||||
os.Exit(1) |
||||
} |
||||
wd.Merge(wdsh) |
||||
|
||||
if _, set := os.LookupEnv("CODEGEN_VERIFY"); set { |
||||
err = wd.Verify() |
||||
if err != nil { |
||||
fmt.Fprintf(os.Stderr, "generated code is not up to date:\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) |
||||
} |
||||
} |
||||
} |
||||
|
||||
func genSharedSchemas(groot string) (gcgen.WriteDiffer, error) { |
||||
abspath := filepath.Join(groot, "packages", "grafana-schema", "src", "schema") |
||||
cfg := &load.Config{ |
||||
ModuleRoot: groot, |
||||
Module: "github.com/grafana/grafana", |
||||
Dir: abspath, |
||||
} |
||||
|
||||
bi := load.Instances(nil, cfg) |
||||
if len(bi) > 1 { |
||||
return nil, fmt.Errorf("loading CUE files in %s resulted in more than one instance", abspath) |
||||
} |
||||
|
||||
ctx := cuecontext.New() |
||||
v := ctx.BuildInstance(bi[0]) |
||||
if v.Err() != nil { |
||||
return nil, fmt.Errorf("errors while building CUE in %s: %s", abspath, v.Err()) |
||||
} |
||||
|
||||
b, err := cuetsy.Generate(v, cuetsy.Config{ |
||||
Export: true, |
||||
}) |
||||
if err != nil { |
||||
return nil, fmt.Errorf("failed to generate TS: %w", err) |
||||
} |
||||
|
||||
wd := gcgen.NewWriteDiffer() |
||||
wd[filepath.Join(abspath, "mudball.gen.ts")] = append([]byte(`//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~
|
||||
// This file is autogenerated. DO NOT EDIT.
|
||||
//
|
||||
// To regenerate, run "make gen-cue" from the repository root.
|
||||
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
`), b...) |
||||
return wd, nil |
||||
} |
Loading…
Reference in new issue