summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2018-07-31 07:44:44 -0700
committerGitHub <noreply@github.com>2018-07-31 07:44:44 -0700
commit82dfe9e61df90c9eb6c6540ca6d82b328661b652 (patch)
tree9507e82769c3be7783b746454e8939c010db50e8
parent8766690c81fcefdbe0c9d85590de1eea07a908d7 (diff)
downloadchat-82dfe9e61df90c9eb6c6540ca6d82b328661b652.tar.gz
chat-82dfe9e61df90c9eb6c6540ca6d82b328661b652.tar.bz2
chat-82dfe9e61df90c9eb6c6540ca6d82b328661b652.zip
Adding support for code split plugins. (#9184)
-rw-r--r--model/manifest.go2
-rw-r--r--plugin/environment.go20
-rw-r--r--web/static.go3
3 files changed, 18 insertions, 7 deletions
diff --git a/model/manifest.go b/model/manifest.go
index e4ed6e4ef..705cc740e 100644
--- a/model/manifest.go
+++ b/model/manifest.go
@@ -188,7 +188,7 @@ func (m *Manifest) ClientManifest() *Manifest {
if cm.Webapp != nil {
cm.Webapp = new(ManifestWebapp)
*cm.Webapp = *m.Webapp
- cm.Webapp.BundlePath = "/static/" + m.Id + "_bundle.js"
+ cm.Webapp.BundlePath = "/static/" + m.Id + "/" + m.Id + "_bundle.js"
}
return cm
}
diff --git a/plugin/environment.go b/plugin/environment.go
index 7d639bdd7..6f915fd80 100644
--- a/plugin/environment.go
+++ b/plugin/environment.go
@@ -6,11 +6,13 @@ package plugin
import (
"fmt"
"io/ioutil"
+ "os"
"path/filepath"
"sync"
"github.com/mattermost/mattermost-server/mlog"
"github.com/mattermost/mattermost-server/model"
+ "github.com/mattermost/mattermost-server/utils"
"github.com/pkg/errors"
)
@@ -172,15 +174,21 @@ func (env *Environment) Activate(id string) (reterr error) {
return fmt.Errorf("invalid webapp bundle path")
}
bundlePath = filepath.Join(env.pluginDir, id, bundlePath)
+ destinationPath := filepath.Join(env.webappPluginDir, id)
- webappBundle, err := ioutil.ReadFile(bundlePath)
- if err != nil {
- return errors.Wrapf(err, "unable to read webapp bundle: %v", id)
+ if err := os.RemoveAll(destinationPath); err != nil {
+ return errors.Wrapf(err, "unable to remove old webapp bundle directory: %v", destinationPath)
}
- err = ioutil.WriteFile(fmt.Sprintf("%s/%s_bundle.js", env.webappPluginDir, id), webappBundle, 0644)
- if err != nil {
- return errors.Wrapf(err, "unable to write webapp bundle: %v", id)
+ if err := utils.CopyDir(filepath.Dir(bundlePath), destinationPath); err != nil {
+ return errors.Wrapf(err, "unable to copy webapp bundle directory: %v", id)
+ }
+
+ if err := os.Rename(
+ filepath.Join(destinationPath, filepath.Base(bundlePath)),
+ filepath.Join(destinationPath, fmt.Sprintf("%s_bundle.js", id)),
+ ); err != nil {
+ return errors.Wrapf(err, "unable to rename webapp bundle: %v", id)
}
}
diff --git a/web/static.go b/web/static.go
index 4c27d6325..7c1d37252 100644
--- a/web/static.go
+++ b/web/static.go
@@ -5,6 +5,7 @@ package web
import (
"fmt"
+ "mime"
"net/http"
"path"
"path/filepath"
@@ -26,6 +27,8 @@ func (w *Web) InitStatic() {
subpath, _ := utils.GetSubpathFromConfig(w.App.Config())
+ mime.AddExtensionType(".wasm", "application/wasm")
+
staticHandler := staticHandler(http.StripPrefix(path.Join(subpath, "static"), http.FileServer(http.Dir(staticDir))))
pluginHandler := pluginHandler(w.App.Config, http.StripPrefix(path.Join(subpath, "static", "plugins"), http.FileServer(http.Dir(*w.App.Config().PluginSettings.ClientDirectory))))