-
Notifications
You must be signed in to change notification settings - Fork 43
/
Magefile.go
58 lines (49 loc) · 1.29 KB
/
Magefile.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//go:build mage
// +build mage
package main
import (
"encoding/json"
"io/ioutil"
"fmt"
// mage:import
build "github.com/grafana/grafana-plugin-sdk-go/build"
)
// Hello prints a message (shows that you can define custom Mage targets).
func Hello() {
fmt.Println("hello plugin developer!")
build.SetBeforeBuildCallback(func(cfg build.Config) (build.Config, error) {
return cfg, nil
})
}
func getValueFromJSON(fpath string, key string) (string, error) {
byteValue, err := ioutil.ReadFile(fpath)
if err != nil {
return "", err
}
var result map[string]interface{}
err = json.Unmarshal(byteValue, &result)
if err != nil {
return "", err
}
executable := result[key]
name, ok := executable.(string)
if !ok || name == "" {
return "", fmt.Errorf("plugin.json is missing: %s", key)
}
return name, nil
}
func init() {
pluginVersion, err := getValueFromJSON("package.json", "version")
if err != nil || len(pluginVersion) == 0 {
fmt.Println("build failed: get pluginVersion error", err)
}
fmt.Println("build pkg version: ", pluginVersion)
build.SetBeforeBuildCallback(func(cfg build.Config) (build.Config, error) {
cfg.CustomVars = map[string]string{
"common.PluginVersion": pluginVersion,
}
return cfg, nil
})
}
// Default configures the default target.
var Default = build.BuildAll