Extract plugin version from manifest

This commit is contained in:
Hanzei 2018-08-24 23:07:03 +02:00
parent fac781a229
commit 8cb9ff92df
No known key found for this signature in database
GPG key ID: 69A2DEFD98937BA0
6 changed files with 28 additions and 12 deletions

View file

@ -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")
}
}

View file

@ -8,7 +8,7 @@ endif
$(shell cd build/manifest && $(GO) build -o ../bin/manifest)
# Extract the plugin id from the manifest.
PLUGIN_ID ?= $(shell build/bin/manifest plugin_id)
PLUGIN_ID ?= $(shell build/bin/manifest id)
ifeq ($(PLUGIN_ID),)
$(error "Cannot parse id from $(MANIFEST_FILE)")
endif

View file

@ -1,3 +1,4 @@
package main
const PluginId = "com.mattermost.sample-plugin"
const PluginVersion = "0.0.1"

View file

@ -1,4 +1,4 @@
import PluginId from './plugin_id';
import Manifest from './manifest';
export default class Plugin {
// eslint-disable-next-line no-unused-vars
@ -7,4 +7,4 @@ export default class Plugin {
}
}
window.registerPlugin(PluginId, new Plugin());
window.registerPlugin(Manifest.PluginId, new Plugin());

4
webapp/src/manifest.js Normal file
View file

@ -0,0 +1,4 @@
export default {
PluginId: 'com.mattermost.sample-plugin',
PluginVersion: '0.0.1',
};

View file

@ -1 +0,0 @@
export default 'com.mattermost.sample-plugin';