[MM-33506] Use embed package to include plugin manifest (#145)

This commit is contained in:
Ben Schumacher 2021-05-18 15:51:24 +02:00 committed by GitHub
parent f5cae51a20
commit ca9ee3c17c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 465 additions and 261 deletions

3
build/legacy.mk Normal file
View file

@ -0,0 +1,3 @@
.PHONY: apply
apply:
@echo make apply is deprecated and has no effect.

View file

@ -3,7 +3,6 @@ package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"github.com/mattermost/mattermost-server/v5/model"
@ -59,11 +58,6 @@ func main() {
fmt.Printf("true")
}
case "apply":
if err := applyManifest(manifest); err != nil {
panic("failed to apply manifest: " + err.Error())
}
default:
panic("unrecognized command: " + cmd)
}
@ -101,26 +95,3 @@ func dumpPluginID(manifest *model.Manifest) {
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() {
// 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, manifestStr)),
0600,
); err != nil {
return errors.Wrap(err, "failed to write server/manifest.go")
}
}
return nil
}