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")
|
||||
|
|
Reference in a new issue