Merge pull request #10 from mattermost/tweak-plugin-version

tweak plugin id/version injection
This commit is contained in:
Joram Wilander 2018-09-21 08:37:03 -04:00 committed by GitHub
commit 8e081f9969
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 27 additions and 20 deletions

View file

@ -4,11 +4,12 @@ NPM ?= $(shell command -v npm 2> /dev/null)
HTTP ?= $(shell command -v http 2> /dev/null) HTTP ?= $(shell command -v http 2> /dev/null)
CURL ?= $(shell command -v curl 2> /dev/null) CURL ?= $(shell command -v curl 2> /dev/null)
MANIFEST_FILE ?= plugin.json MANIFEST_FILE ?= plugin.json
BUNDLE_NAME = $(PLUGIN_ID)_$(PLUGIN_VERSION).tar.gz
# Verify environment, and define PLUGIN_ID, HAS_SERVER and HAS_WEBAPP as needed. # Verify environment, and define PLUGIN_ID, PLUGIN_VERSION, HAS_SERVER and HAS_WEBAPP as needed.
include build/setup.mk include build/setup.mk
BUNDLE_NAME ?= $(PLUGIN_ID)-$(PLUGIN_VERSION).tar.gz
# all, the default target, tests, builds and bundles the plugin. # all, the default target, tests, builds and bundles the plugin.
all: test dist all: test dist

View file

@ -10,16 +10,19 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
) )
const PluginIdGoFileTemplate = `package main const pluginIdGoFileTemplate = `package main
const PluginId = "%s" var manifest = struct {
const PluginVersion = "%s" Id string
Version string
}{
Id: "%s",
Version: "%s",
}
` `
const PluginIdJsFileTemplate = `export default { const pluginIdJsFileTemplate = `export const id = '%s';
PluginId: '%s', export const version = '%s';
PluginVersion: '%s',
};
` `
func main() { func main() {
@ -98,7 +101,7 @@ func applyManifest(manifest *model.Manifest) error {
if manifest.HasServer() { if manifest.HasServer() {
if err := ioutil.WriteFile( if err := ioutil.WriteFile(
"server/manifest.go", "server/manifest.go",
[]byte(fmt.Sprintf(PluginIdGoFileTemplate, manifest.Id, manifest.Version)), []byte(fmt.Sprintf(pluginIdGoFileTemplate, manifest.Id, manifest.Version)),
0644, 0644,
); err != nil { ); err != nil {
return errors.Wrap(err, "failed to write server/manifest.go") return errors.Wrap(err, "failed to write server/manifest.go")
@ -108,7 +111,7 @@ func applyManifest(manifest *model.Manifest) error {
if manifest.HasWebapp() { if manifest.HasWebapp() {
if err := ioutil.WriteFile( if err := ioutil.WriteFile(
"webapp/src/manifest.js", "webapp/src/manifest.js",
[]byte(fmt.Sprintf(PluginIdJsFileTemplate, manifest.Id, manifest.Version)), []byte(fmt.Sprintf(pluginIdJsFileTemplate, manifest.Id, manifest.Version)),
0644, 0644,
); err != nil { ); err != nil {
return errors.Wrap(err, "failed to open webapp/src/manifest.js") return errors.Wrap(err, "failed to open webapp/src/manifest.js")

View file

@ -16,7 +16,7 @@ endif
# Extract the plugin version from the manifest. # Extract the plugin version from the manifest.
PLUGIN_VERSION ?= $(shell build/bin/manifest version) PLUGIN_VERSION ?= $(shell build/bin/manifest version)
ifeq ($(PLUGIN_VERSION),) ifeq ($(PLUGIN_VERSION),)
$(error "Cannot parse id from $(MANIFEST_FILE)") $(error "Cannot parse version from $(MANIFEST_FILE)")
endif endif
# Determine if a server is defined in the manifest. # Determine if a server is defined in the manifest.

View file

@ -1,4 +1,9 @@
package main package main
const PluginId = "com.mattermost.sample-plugin" var manifest = struct {
const PluginVersion = "0.0.1" Id string
Version string
}{
Id: "com.mattermost.sample-plugin",
Version: "0.0.1",
}

View file

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

View file

@ -1,4 +1,2 @@
export default { export const id = 'com.mattermost.sample-plugin';
PluginId: 'com.mattermost.sample-plugin', export const version = '0.0.1';
PluginVersion: '0.0.1',
};