build/manifest: print whole manifest variable as it is (#73)
while generating manifest files for both JS and Go sources. fixes #72.
This commit is contained in:
parent
8f6268d813
commit
8cf303c943
6 changed files with 117 additions and 22 deletions
|
@ -14,19 +14,32 @@ const pluginIDGoFileTemplate = `// This file is automatically generated. Do not
|
|||
|
||||
package main
|
||||
|
||||
var manifest = struct {
|
||||
ID string
|
||||
Version string
|
||||
}{
|
||||
ID: "%s",
|
||||
Version: "%s",
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
)
|
||||
|
||||
var manifest *model.Manifest
|
||||
|
||||
const manifestStr = ` + "`" + `
|
||||
%s
|
||||
` + "`" + `
|
||||
|
||||
func init() {
|
||||
manifest = model.ManifestFromJson(strings.NewReader(manifestStr))
|
||||
}
|
||||
`
|
||||
|
||||
const pluginIDJSFileTemplate = `// This file is automatically generated. Do not modify it manually.
|
||||
|
||||
export const id = '%s';
|
||||
export const version = '%s';
|
||||
const manifest = JSON.parse(` + "`" + `
|
||||
%s
|
||||
` + "`" + `);
|
||||
|
||||
export default manifest;
|
||||
export const id = manifest.id;
|
||||
export const version = manifest.version;
|
||||
`
|
||||
|
||||
func main() {
|
||||
|
@ -103,9 +116,17 @@ func dumpPluginVersion(manifest *model.Manifest) {
|
|||
// applyManifest propagates the plugin_id into the server and webapp folders, as necessary
|
||||
func applyManifest(manifest *model.Manifest) error {
|
||||
if manifest.HasServer() {
|
||||
// generate JSON representation of Manifest.
|
||||
manifestBytes, err := json.MarshalIndent(manifest, "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
manifestStr := string(manifestBytes)
|
||||
|
||||
// write generated code to file by using Go file template.
|
||||
if err := ioutil.WriteFile(
|
||||
"server/manifest.go",
|
||||
[]byte(fmt.Sprintf(pluginIDGoFileTemplate, manifest.Id, manifest.Version)),
|
||||
[]byte(fmt.Sprintf(pluginIDGoFileTemplate, manifestStr)),
|
||||
0644,
|
||||
); err != nil {
|
||||
return errors.Wrap(err, "failed to write server/manifest.go")
|
||||
|
@ -113,9 +134,19 @@ func applyManifest(manifest *model.Manifest) error {
|
|||
}
|
||||
|
||||
if manifest.HasWebapp() {
|
||||
// generate JSON representation of Manifest.
|
||||
// JSON is very similar and compatible with JS's object literals. so, what we do here
|
||||
// is actually JS code generation.
|
||||
manifestBytes, err := json.MarshalIndent(manifest, "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
manifestStr := string(manifestBytes)
|
||||
|
||||
// write generated code to file by using JS file template.
|
||||
if err := ioutil.WriteFile(
|
||||
"webapp/src/manifest.js",
|
||||
[]byte(fmt.Sprintf(pluginIDJSFileTemplate, manifest.Id, manifest.Version)),
|
||||
[]byte(fmt.Sprintf(pluginIDJSFileTemplate, manifestStr)),
|
||||
0644,
|
||||
); err != nil {
|
||||
return errors.Wrap(err, "failed to open webapp/src/manifest.js")
|
||||
|
|
2
go.sum
2
go.sum
|
@ -111,6 +111,7 @@ github.com/gomodule/redigo v2.0.0+incompatible/go.mod h1:B4C85qUVwatsJoIUNIfCRsp
|
|||
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||
github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY=
|
||||
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ=
|
||||
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
|
||||
|
@ -219,7 +220,6 @@ github.com/mattn/go-sqlite3 v1.9.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOq
|
|||
github.com/mattn/go-sqlite3 v1.11.0 h1:LDdKkqtYlom37fkvqs8rMPFKAMe8+SgjbwZ6ex1/A/Q=
|
||||
github.com/mattn/go-sqlite3 v1.11.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
||||
github.com/mholt/archiver v3.1.1+incompatible h1:1dCVxuqs0dJseYEhi5pl7MYPH9zDa1wBi7mF09cbNkU=
|
||||
github.com/mholt/archiver/v3 v3.3.0 h1:vWjhY8SQp5yzM9P6OJ/eZEkmi3UAbRrxCq48MxjAzig=
|
||||
github.com/mholt/archiver/v3 v3.3.0/go.mod h1:YnQtqsp+94Rwd0D/rk5cnLrxusUBUXg+08Ebtr1Mqao=
|
||||
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
|
||||
|
|
42
server/manifest.go
generated
42
server/manifest.go
generated
|
@ -2,10 +2,40 @@
|
|||
|
||||
package main
|
||||
|
||||
var manifest = struct {
|
||||
ID string
|
||||
Version string
|
||||
}{
|
||||
ID: "com.mattermost.plugin-starter-template",
|
||||
Version: "0.1.0",
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
)
|
||||
|
||||
var manifest *model.Manifest
|
||||
|
||||
const manifestStr = `
|
||||
{
|
||||
"id": "com.mattermost.plugin-starter-template",
|
||||
"name": "Plugin Starter Template",
|
||||
"description": "This plugin serves as a starting point for writing a Mattermost plugin.",
|
||||
"version": "0.1.0",
|
||||
"min_server_version": "5.12.0",
|
||||
"server": {
|
||||
"executables": {
|
||||
"linux-amd64": "server/dist/plugin-linux-amd64",
|
||||
"darwin-amd64": "server/dist/plugin-darwin-amd64",
|
||||
"windows-amd64": "server/dist/plugin-windows-amd64.exe"
|
||||
},
|
||||
"executable": ""
|
||||
},
|
||||
"webapp": {
|
||||
"bundle_path": "webapp/dist/main.js"
|
||||
},
|
||||
"settings_schema": {
|
||||
"header": "",
|
||||
"footer": "",
|
||||
"settings": []
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
func init() {
|
||||
manifest = model.ManifestFromJson(strings.NewReader(manifestStr))
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import {id as pluginId} from './manifest';
|
||||
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.id, new Plugin());
|
||||
|
|
31
webapp/src/manifest.js
generated
31
webapp/src/manifest.js
generated
|
@ -1,4 +1,31 @@
|
|||
// This file is automatically generated. Do not modify it manually.
|
||||
|
||||
export const id = 'com.mattermost.plugin-starter-template';
|
||||
export const version = '0.1.0';
|
||||
const manifest = JSON.parse(`
|
||||
{
|
||||
"id": "com.mattermost.plugin-starter-template",
|
||||
"name": "Plugin Starter Template",
|
||||
"description": "This plugin serves as a starting point for writing a Mattermost plugin.",
|
||||
"version": "0.1.0",
|
||||
"min_server_version": "5.12.0",
|
||||
"server": {
|
||||
"executables": {
|
||||
"linux-amd64": "server/dist/plugin-linux-amd64",
|
||||
"darwin-amd64": "server/dist/plugin-darwin-amd64",
|
||||
"windows-amd64": "server/dist/plugin-windows-amd64.exe"
|
||||
},
|
||||
"executable": ""
|
||||
},
|
||||
"webapp": {
|
||||
"bundle_path": "webapp/dist/main.js"
|
||||
},
|
||||
"settings_schema": {
|
||||
"header": "",
|
||||
"footer": "",
|
||||
"settings": []
|
||||
}
|
||||
}
|
||||
`);
|
||||
|
||||
export default manifest;
|
||||
export const id = manifest.id;
|
||||
export const version = manifest.version;
|
||||
|
|
|
@ -1,5 +1,12 @@
|
|||
import {id, version} from './manifest';
|
||||
import manifest, {id, version} from './manifest';
|
||||
|
||||
test('Plugin manifest, id and version are defined', () => {
|
||||
expect(manifest).toBeDefined();
|
||||
expect(manifest.id).toBeDefined();
|
||||
expect(manifest.version).toBeDefined();
|
||||
});
|
||||
|
||||
// To ease migration, verify separate export of id and version.
|
||||
test('Plugin id and version are defined', () => {
|
||||
expect(id).toBeDefined();
|
||||
expect(version).toBeDefined();
|
||||
|
|
Reference in a new issue