From f927586dc523fc5bd5dffc9e608c976dc95892d5 Mon Sep 17 00:00:00 2001 From: Jesse Hallam Date: Tue, 12 Dec 2023 16:32:37 -0400 Subject: [PATCH] Revert "Don't generate manifest.ts (#127)" This reverts commit 18d30b50bc7ba800c9f05bfd82970781db0aea3e. --- .gitattributes | 1 + build/manifest/main.go | 35 +++++++++++++++++++++++++++++++++++ webapp/src/manifest.ts | 38 ++++++++++++++++++++++++++++++++++++-- 3 files changed, 72 insertions(+), 2 deletions(-) diff --git a/.gitattributes b/.gitattributes index f8621eb4..4bd338f4 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,2 @@ server/manifest.go linguist-generated=true +webapp/src/manifest.js linguist-generated=true diff --git a/build/manifest/main.go b/build/manifest/main.go index 44a53195..d0fa5b68 100644 --- a/build/manifest/main.go +++ b/build/manifest/main.go @@ -5,6 +5,7 @@ import ( "fmt" "io/ioutil" "os" + "strings" "github.com/mattermost/mattermost/server/public/model" "github.com/pkg/errors" @@ -31,6 +32,17 @@ 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") @@ -122,5 +134,28 @@ 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 } diff --git a/webapp/src/manifest.ts b/webapp/src/manifest.ts index 314911ba..48ab4912 100644 --- a/webapp/src/manifest.ts +++ b/webapp/src/manifest.ts @@ -1,3 +1,37 @@ -import manifest from '@/../../plugin.json'; +// This file is automatically generated. Do not modify it manually. -export {manifest}; +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.", + "homepage_url": "/~https://github.com/mattermost/mattermost-plugin-starter-template", + "support_url": "/~https://github.com/mattermost/mattermost-plugin-starter-template/issues", + "release_notes_url": "/~https://github.com/mattermost/mattermost-plugin-starter-template/releases/tag/v0.1.0", + "icon_path": "assets/starter-template-icon.svg", + "version": "0.1.0", + "min_server_version": "6.2.1", + "server": { + "executables": { + "darwin-amd64": "server/dist/plugin-darwin-amd64", + "darwin-arm64": "server/dist/plugin-darwin-arm64", + "linux-amd64": "server/dist/plugin-linux-amd64", + "linux-arm64": "server/dist/plugin-linux-arm64", + "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;