[MM-33506] Use embed package to include plugin manifest (#145)
This commit is contained in:
parent
f5cae51a20
commit
ca9ee3c17c
9 changed files with 465 additions and 261 deletions
|
@ -1,7 +1,7 @@
|
|||
version: 2.1
|
||||
|
||||
orbs:
|
||||
plugin-ci: mattermost/plugin-ci@0.1.0
|
||||
plugin-ci: mattermost/plugin-ci@0.1.6
|
||||
|
||||
workflows:
|
||||
version: 2
|
||||
|
|
1
.gitattributes
vendored
1
.gitattributes
vendored
|
@ -1 +0,0 @@
|
|||
server/manifest.go linguist-generated=true
|
10
Makefile
10
Makefile
|
@ -20,6 +20,7 @@ default: all
|
|||
|
||||
# Verify environment, and define PLUGIN_ID, PLUGIN_VERSION, HAS_SERVER and HAS_WEBAPP as needed.
|
||||
include build/setup.mk
|
||||
include build/legacy.mk
|
||||
|
||||
BUNDLE_NAME ?= $(PLUGIN_ID)-$(PLUGIN_VERSION).tar.gz
|
||||
|
||||
|
@ -32,11 +33,6 @@ endif
|
|||
.PHONY: all
|
||||
all: check-style test dist
|
||||
|
||||
## Propagates plugin manifest information into the server/ and webapp/ folders.
|
||||
.PHONY: apply
|
||||
apply:
|
||||
./build/bin/manifest apply
|
||||
|
||||
## Runs eslint and golangci-lint
|
||||
.PHONY: check-style
|
||||
check-style: webapp/node_modules
|
||||
|
@ -119,7 +115,7 @@ endif
|
|||
|
||||
## Builds and bundles the plugin.
|
||||
.PHONY: dist
|
||||
dist: apply server webapp bundle
|
||||
dist: server webapp bundle
|
||||
|
||||
## Builds and installs the plugin to a server.
|
||||
.PHONY: deploy
|
||||
|
@ -128,7 +124,7 @@ deploy: dist
|
|||
|
||||
## Builds and installs the plugin to a server, updating the webapp automatically when changed.
|
||||
.PHONY: watch
|
||||
watch: apply server bundle
|
||||
watch: server bundle
|
||||
ifeq ($(MM_DEBUG),)
|
||||
cd webapp && $(NPM) run build:watch
|
||||
else
|
||||
|
|
3
build/legacy.mk
Normal file
3
build/legacy.mk
Normal file
|
@ -0,0 +1,3 @@
|
|||
.PHONY: apply
|
||||
apply:
|
||||
@echo make apply is deprecated and has no effect.
|
|
@ -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
|
||||
}
|
||||
|
|
9
go.mod
9
go.mod
|
@ -1,12 +1,9 @@
|
|||
module github.com/mattermost/mattermost-plugin-starter-template
|
||||
|
||||
go 1.12
|
||||
go 1.16
|
||||
|
||||
require (
|
||||
github.com/kr/text v0.2.0 // indirect
|
||||
github.com/mattermost/mattermost-server/v5 v5.26.2
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
|
||||
github.com/mattermost/mattermost-server/v5 v5.32.1
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/stretchr/testify v1.6.1
|
||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
|
||||
github.com/stretchr/testify v1.7.0
|
||||
)
|
||||
|
|
17
plugin.go
Normal file
17
plugin.go
Normal file
|
@ -0,0 +1,17 @@
|
|||
package root
|
||||
|
||||
import (
|
||||
_ "embed" // Need to embed manifest file
|
||||
"strings"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
)
|
||||
|
||||
//go:embed plugin.json
|
||||
var manifestString string
|
||||
|
||||
var Manifest model.Manifest
|
||||
|
||||
func init() {
|
||||
Manifest = *model.ManifestFromJson(strings.NewReader(manifestString))
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
// This file is automatically generated. Do not modify it manually.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/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))
|
||||
}
|
Reference in a new issue