Add dev server plugin support for loading js files
This makes it possible for users to load multiple files as plugins at once. Change-Id: Ib1ae55d45aa05558465c6077faacb4c58bd3ced6
This commit is contained in:
@@ -97,6 +97,22 @@ bazel build polygerrit &&
|
||||
-d ../gerrit_testsite --console-log --show-stack-trace
|
||||
```
|
||||
|
||||
Serving plugins
|
||||
|
||||
> Local dev plugins must be put inside of gerrit/plugins
|
||||
|
||||
Loading a single plugin file:
|
||||
|
||||
```sh
|
||||
./run-server.sh --plugins=plugins/my_plugin/static/my_plugin.js
|
||||
```
|
||||
|
||||
Loading multiple plugin files:
|
||||
|
||||
```sh
|
||||
./run-server.sh --plugins=plugins/my_plugin/static/my_plugin.js,plugins/my_plugin/static/my_plugin.html
|
||||
```
|
||||
|
||||
## Running Tests
|
||||
|
||||
This step requires the `web-component-tester` npm module.
|
||||
|
||||
@@ -35,7 +35,7 @@ var (
|
||||
port = flag.String("port", ":8081", "Port to serve HTTP requests on")
|
||||
prod = flag.Bool("prod", false, "Serve production assets")
|
||||
scheme = flag.String("scheme", "https", "URL scheme")
|
||||
plugins = flag.String("plugins", "", "Path to local plugins folder")
|
||||
plugins = flag.String("plugins", "", "comma seperated plugin paths to serve")
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -54,8 +54,8 @@ func main() {
|
||||
http.HandleFunc("/accounts/self/detail", handleAccountDetail)
|
||||
if len(*plugins) > 0 {
|
||||
http.Handle("/plugins/", http.StripPrefix("/plugins/",
|
||||
http.FileServer(http.Dir(*plugins))))
|
||||
log.Println("Local plugins from", *plugins)
|
||||
http.FileServer(http.Dir("../plugins"))))
|
||||
log.Println("Local plugins from", "../plugins")
|
||||
} else {
|
||||
http.HandleFunc("/plugins/", handleRESTProxy)
|
||||
}
|
||||
@@ -144,19 +144,23 @@ func injectLocalPlugins(r io.Reader) io.Reader {
|
||||
}
|
||||
|
||||
// Configuration path in the JSON server response
|
||||
pluginsPath := []string{"plugin", "html_resource_paths"}
|
||||
jsPluginsPath := []string{"plugin", "js_resource_paths"}
|
||||
htmlPluginsPath := []string{"plugin", "html_resource_paths"}
|
||||
htmlResources := getJsonPropByPath(response, htmlPluginsPath).([]interface{})
|
||||
jsResources := getJsonPropByPath(response, jsPluginsPath).([]interface{})
|
||||
|
||||
htmlResources := getJsonPropByPath(response, pluginsPath).([]interface{})
|
||||
files, err := ioutil.ReadDir(*plugins)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
for _, f := range files {
|
||||
if strings.HasSuffix(f.Name(), ".html") {
|
||||
htmlResources = append(htmlResources, "plugins/"+f.Name())
|
||||
for _, p := range strings.Split(*plugins, ",") {
|
||||
if strings.HasSuffix(p, ".html") {
|
||||
htmlResources = append(htmlResources, p)
|
||||
}
|
||||
|
||||
if strings.HasSuffix(p, ".js") {
|
||||
jsResources = append(jsResources, p)
|
||||
}
|
||||
}
|
||||
setJsonPropByPath(response, pluginsPath, htmlResources)
|
||||
|
||||
setJsonPropByPath(response, jsPluginsPath, jsResources)
|
||||
setJsonPropByPath(response, htmlPluginsPath, htmlResources)
|
||||
|
||||
reader, writer := io.Pipe()
|
||||
go func() {
|
||||
|
||||
Reference in New Issue
Block a user