mirror of
https://github.com/grafana/grafana.git
synced 2025-08-03 02:42:22 +08:00
plugindef: Move pluginmeta out of coremodels as standalone thema lineage (#56765)
* Get pluginmeta mostly moved over to pkg/plugins/plugindef * Remove dead func * Fix up pfs, use sync.Once in plugindef * Update to latest thema * Chase Endec->Codec conversion in Thema * Comments on slash header gen; use ToSlash * Also generate JSON schema for plugindef * Generate JSON Schema as well * Fix slot loading from kindsys cue decls * Remove unused vars * skip generating plugin.schema.json for now Co-authored-by: Marcus Efraimsson <marcus.efraimsson@gmail.com>
This commit is contained in:
@ -3,6 +3,7 @@ package codegen
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/grafana/codejen"
|
||||
"github.com/grafana/grafana/pkg/kindsys"
|
||||
@ -39,12 +40,22 @@ func (decl *DeclForGen) Lineage() thema.Lineage {
|
||||
return decl.lin
|
||||
}
|
||||
|
||||
// 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) {
|
||||
b := new(bytes.Buffer)
|
||||
fmt.Fprintf(b, headerTmpl, maingen, f.FromString())
|
||||
fmt.Fprint(b, string(f.Data))
|
||||
f.Data = b.Bytes()
|
||||
// Never inject on certain filetypes, it's never valid
|
||||
switch filepath.Ext(f.RelativePath) {
|
||||
case ".json", ".yml", ".yaml":
|
||||
return f, nil
|
||||
default:
|
||||
b := new(bytes.Buffer)
|
||||
fmt.Fprintf(b, headerTmpl, filepath.ToSlash(maingen), f.FromString())
|
||||
fmt.Fprint(b, string(f.Data))
|
||||
f.Data = b.Bytes()
|
||||
}
|
||||
return f, nil
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user