Skip to content

Commit

Permalink
Don't generate manifest.ts (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
hanzei authored Sep 22, 2020
1 parent eae9f98 commit 18d30b5
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 63 deletions.
1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
server/manifest.go linguist-generated=true
webapp/src/manifest.js linguist-generated=true
35 changes: 0 additions & 35 deletions build/manifest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"io/ioutil"
"os"
"strings"

"github.com/mattermost/mattermost-server/v5/model"
"github.com/pkg/errors"
Expand All @@ -32,17 +31,6 @@ func init() {
}
`

const pluginIDJSFileTemplate = `// This file is automatically generated. Do not modify it manually.
const manifest = JSON.parse(` + "`" + `
%s
` + "`" + `);
export default manifest;
export const id = manifest.id;
export const version = manifest.version;
`

func main() {
if len(os.Args) <= 1 {
panic("no cmd specified")
Expand Down Expand Up @@ -134,28 +122,5 @@ 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)

// Escape newlines
manifestStr = strings.ReplaceAll(manifestStr, `\n`, `\\n`)

// write generated code to file by using JS file template.
if err := ioutil.WriteFile(
"webapp/src/manifest.ts",
[]byte(fmt.Sprintf(pluginIDJSFileTemplate, manifestStr)),
0600,
); err != nil {
return errors.Wrap(err, "failed to open webapp/src/manifest.js")
}
}

return nil
}
28 changes: 1 addition & 27 deletions webapp/src/manifest.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,4 @@
// This file is automatically generated. Do not modify it manually.

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": []
}
}
`);
import manifest from '../../plugin.json';

export default manifest;
export const id = manifest.id;
Expand Down

0 comments on commit 18d30b5

Please sign in to comment.