mirror of
https://github.com/grafana/grafana.git
synced 2025-07-31 17:22:09 +08:00
Chore: Generate plugin version and remove lineage version (#69781)
* Generate plugin version and remove lineage version * Generate version for each major * Remove pluginVersion from core plugins * Remove code version generation * Generate cue files * Move grafana version into jenny * fix go import
This commit is contained in:
@ -1,10 +1,14 @@
|
||||
package codegen
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/grafana/codejen"
|
||||
tsast "github.com/grafana/cuetsy/ts/ast"
|
||||
"github.com/grafana/grafana/pkg/build"
|
||||
corecodegen "github.com/grafana/grafana/pkg/codegen"
|
||||
"github.com/grafana/grafana/pkg/cuectx"
|
||||
"github.com/grafana/grafana/pkg/plugins/pfs"
|
||||
@ -37,6 +41,13 @@ func (j *pleJenny) Generate(decl *pfs.PluginDecl) (codejen.Files, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
version := "export const pluginVersion = \"%s\";"
|
||||
if decl.PluginMeta.Info.Version != nil {
|
||||
version = fmt.Sprintf(version, *decl.PluginMeta.Info.Version)
|
||||
} else {
|
||||
version = fmt.Sprintf(version, getGrafanaVersion())
|
||||
}
|
||||
|
||||
files := make(codejen.Files, len(jf))
|
||||
for i, file := range jf {
|
||||
tsf := &tsast.File{}
|
||||
@ -48,6 +59,10 @@ func (j *pleJenny) Generate(decl *pfs.PluginDecl) (codejen.Files, error) {
|
||||
}
|
||||
}
|
||||
|
||||
tsf.Nodes = append(tsf.Nodes, tsast.Raw{
|
||||
Data: version,
|
||||
})
|
||||
|
||||
tsf.Nodes = append(tsf.Nodes, tsast.Raw{
|
||||
Data: string(file.Data),
|
||||
})
|
||||
@ -70,3 +85,17 @@ func kinds2pd(rt *thema.Runtime, j codejen.OneToMany[kindsys.Kind]) codejen.OneT
|
||||
return kd
|
||||
})
|
||||
}
|
||||
|
||||
func getGrafanaVersion() string {
|
||||
dir, err := os.Getwd()
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
pkg, err := build.OpenPackageJSON(path.Join(dir, "../../../"))
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
return pkg.Version
|
||||
}
|
||||
|
@ -42,12 +42,6 @@ func (j *ptsJenny) Generate(decl *pfs.PluginDecl) (*codejen.File, error) {
|
||||
}
|
||||
}
|
||||
|
||||
v := decl.Lineage.Latest().Version()
|
||||
|
||||
tsf.Nodes = append(tsf.Nodes, tsast.Raw{
|
||||
Data: fmt.Sprintf("export const %sModelVersion = Object.freeze([%v, %v]);", decl.SchemaInterface.Name(), v[0], v[1]),
|
||||
})
|
||||
|
||||
jf, err := j.inner.Generate(decl)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
Reference in New Issue
Block a user