mirror of
https://github.com/grafana/grafana.git
synced 2024-12-01 04:59:15 -06:00
473898e47c
* Move some thema code inside grafana * Use new codegen instead of thema for core kinds * Replace TS generator * Use new generator for go types * Remove thema from oapi generator * Remove thema from generators * Don't use kindsys/thema for core kinds * Remove kindsys/thema from plugins * Remove last thema related * Remove most of cuectx and move utils_ts into codegen. It also deletes wire dependency * Merge plugins generators * Delete thema dependency 🎉 * Fix CODEOWNERS * Fix package name * Fix TS output names * More path fixes * Fix mod codeowners * Use original plugin's name * Remove kindsys dependency 🎉 * Modify oapi schema and create an apply function to fix elasticsearch errors * cue.mod was deleted by mistake * Fix TS panels * sort imports * Fixing elasticsearch output * Downgrade oapi-codegen library * Update output ts files * More fixes * Restore old elasticsearch generated file and skip its generation. Remove core imports into plugins * More lint fixes * Add codeowners * restore embed.go file * Fix embed.go
55 lines
1.4 KiB
Go
55 lines
1.4 KiB
Go
package codegen
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"path/filepath"
|
|
|
|
"cuelang.org/go/cue"
|
|
"github.com/grafana/codejen"
|
|
)
|
|
|
|
type OneToOne codejen.OneToOne[SchemaForGen]
|
|
type OneToMany codejen.OneToMany[SchemaForGen]
|
|
type ManyToOne codejen.ManyToOne[SchemaForGen]
|
|
type ManyToMany codejen.ManyToMany[SchemaForGen]
|
|
|
|
// SlashHeaderMapper produces a FileMapper that injects a comment header onto
|
|
// a [codejen.File] indicating the main generator that produced it (via the provided
|
|
// maingen, which should be a path) and the jenny or jennies that constructed the
|
|
// file.
|
|
func SlashHeaderMapper(maingen string) codejen.FileMapper {
|
|
return func(f codejen.File) (codejen.File, error) {
|
|
var leader string
|
|
// Never inject on certain filetypes, it's never valid
|
|
switch filepath.Ext(f.RelativePath) {
|
|
case ".json", ".md":
|
|
return f, nil
|
|
case ".yml", ".yaml":
|
|
leader = "#"
|
|
default:
|
|
leader = "//"
|
|
}
|
|
|
|
buf := new(bytes.Buffer)
|
|
if err := tmpls.Lookup("gen_header.tmpl").Execute(buf, tvars_gen_header{
|
|
MainGenerator: filepath.ToSlash(maingen),
|
|
Using: f.From,
|
|
Leader: leader,
|
|
}); err != nil {
|
|
return codejen.File{}, fmt.Errorf("failed executing gen header template: %w", err)
|
|
}
|
|
fmt.Fprint(buf, string(f.Data))
|
|
f.Data = buf.Bytes()
|
|
return f, nil
|
|
}
|
|
}
|
|
|
|
type SchemaForGen struct {
|
|
Name string
|
|
CueFile cue.Value
|
|
FilePath string
|
|
IsGroup bool
|
|
OutputName string // Some TS output files are capitalised and others not.
|
|
}
|