mirror of
https://github.com/grafana/grafana.git
synced 2024-11-25 18:30:41 -06:00
8f29450594
* Remove Raw references * Remove more raws * Re-generate files * Remove raw folder from veneer * Fix import * Fix lint * Bring back raw folder in grafana-schema * Another lint * Remove use of "Structured" word in kinds * Delete unused function and remove some structured words * Bunch more removals of structured name Co-authored-by: sam boyer <sdboyer@grafana.com>
54 lines
1.3 KiB
Go
54 lines
1.3 KiB
Go
package codegen
|
|
|
|
import (
|
|
"fmt"
|
|
"path/filepath"
|
|
|
|
"github.com/grafana/codejen"
|
|
)
|
|
|
|
// LatestJenny returns a jenny that runs another jenny for only the latest
|
|
// schema in a DeclForGen, and prefixes the resulting file with the provided
|
|
// parentdir (e.g. "pkg/kinds/") and with a directory based on the kind's
|
|
// machine name (e.g. "dashboard/").
|
|
func LatestJenny(parentdir string, inner codejen.OneToOne[SchemaForGen]) OneToOne {
|
|
if inner == nil {
|
|
panic("inner jenny must not be nil")
|
|
}
|
|
|
|
return &latestj{
|
|
parentdir: parentdir,
|
|
inner: inner,
|
|
}
|
|
}
|
|
|
|
type latestj struct {
|
|
parentdir string
|
|
inner codejen.OneToOne[SchemaForGen]
|
|
}
|
|
|
|
func (j *latestj) JennyName() string {
|
|
return "LatestJenny"
|
|
}
|
|
|
|
func (j *latestj) Generate(decl *DeclForGen) (*codejen.File, error) {
|
|
comm := decl.Properties.Common()
|
|
sfg := SchemaForGen{
|
|
Name: comm.Name,
|
|
Schema: decl.Lineage().Latest(),
|
|
IsGroup: comm.LineageIsGroup,
|
|
}
|
|
|
|
f, err := j.inner.Generate(sfg)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("%s jenny failed on %s schema for %s: %w", j.inner.JennyName(), sfg.Schema.Version(), decl.Properties.Common().Name, err)
|
|
}
|
|
if f == nil || !f.Exists() {
|
|
return nil, nil
|
|
}
|
|
|
|
f.RelativePath = filepath.Join(j.parentdir, comm.MachineName, f.RelativePath)
|
|
f.From = append(f.From, j)
|
|
return f, nil
|
|
}
|