Extract plugin version from manifest
This commit is contained in:
parent
fac781a229
commit
8cb9ff92df
6 changed files with 28 additions and 12 deletions
|
@ -13,9 +13,13 @@ import (
|
|||
const PluginIdGoFileTemplate = `package main
|
||||
|
||||
const PluginId = "%s"
|
||||
const PluginVersion = "%s"
|
||||
`
|
||||
|
||||
const PluginIdJsFileTemplate = `export default '%s';
|
||||
const PluginIdJsFileTemplate = `export default {
|
||||
PluginId: '%s',
|
||||
PluginVersion: '%s',
|
||||
};
|
||||
`
|
||||
|
||||
func main() {
|
||||
|
@ -30,9 +34,12 @@ func main() {
|
|||
|
||||
cmd := os.Args[1]
|
||||
switch cmd {
|
||||
case "plugin_id":
|
||||
case "id":
|
||||
dumpPluginId(manifest)
|
||||
|
||||
case "version":
|
||||
dumpPluginVersion(manifest)
|
||||
|
||||
case "has_server":
|
||||
if manifest.HasServer() {
|
||||
fmt.Printf("true")
|
||||
|
@ -81,25 +88,30 @@ func dumpPluginId(manifest *model.Manifest) {
|
|||
fmt.Printf("%s", manifest.Id)
|
||||
}
|
||||
|
||||
// dumpPluginVersion writes the plugin version from the given manifest to standard out
|
||||
func dumpPluginVersion(manifest *model.Manifest) {
|
||||
fmt.Printf("%s", manifest.Version)
|
||||
}
|
||||
|
||||
// applyManifest propagates the plugin_id into the server and webapp folders, as necessary
|
||||
func applyManifest(manifest *model.Manifest) error {
|
||||
if manifest.HasServer() {
|
||||
if err := ioutil.WriteFile(
|
||||
"server/plugin_id.go",
|
||||
[]byte(fmt.Sprintf(PluginIdGoFileTemplate, manifest.Id)),
|
||||
"server/manifest.go",
|
||||
[]byte(fmt.Sprintf(PluginIdGoFileTemplate, manifest.Id, manifest.Version)),
|
||||
0644,
|
||||
); err != nil {
|
||||
return errors.Wrap(err, "failed to write server/plugin_id.go")
|
||||
return errors.Wrap(err, "failed to write server/manifest.go")
|
||||
}
|
||||
}
|
||||
|
||||
if manifest.HasWebapp() {
|
||||
if err := ioutil.WriteFile(
|
||||
"webapp/src/plugin_id.js",
|
||||
[]byte(fmt.Sprintf(PluginIdJsFileTemplate, manifest.Id)),
|
||||
"webapp/src/manifest.js",
|
||||
[]byte(fmt.Sprintf(PluginIdJsFileTemplate, manifest.Id, manifest.Version)),
|
||||
0644,
|
||||
); err != nil {
|
||||
return errors.Wrap(err, "failed to open webapp/src/plugin_id.js")
|
||||
return errors.Wrap(err, "failed to open webapp/src/manifest.js")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue