Adding support for code split plugins. (#9184)

Этот коммит содержится в:
Christopher Speller
2018-07-31 07:44:44 -07:00
коммит произвёл GitHub
родитель 8766690c81
Коммит 82dfe9e61d
3 изменённых файлов: 18 добавлений и 7 удалений

Просмотреть файл

@@ -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
}

Просмотреть файл

@@ -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)
}
}

Просмотреть файл

@@ -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))))