Implement webpack build for web interface

Set up webpack for the master server's web interface and fix the issues
from the imported interface source files.  The .jsx files in
package/master/web are bundled together into package/master/static and
served by the master server via express.
This commit is contained in:
Hornwitser committed 2020-09-28 04:23:45 +02:00
1 parent 2382f4bbdc
commit 701ff87bcd
25 files changed
+219 -191

No files matched your search

+23 -37
View File
@@ -1,49 +1,41 @@
const link = require("./../lib/link");
const plugin = require("./../lib/plugin");
const errors = require("./../lib/errors");
const chalk = require("chalk");
const link = require("@clusterio/lib/link");
const plugin = require("@clusterio/lib/plugin");
const errors = require("@clusterio/lib/errors");
/**
* Format a parsed Factorio output message with colors
* Format a parsed Factorio output message
*
* Formats a parsed Factorio output from lib/factorio into a readable
* colorized output using terminal escape codes that can be printed.
* Formats a parsed Factorio output from lib/factorio back into the
* text string it was parsed from.
*
* @param {Object} output - Factorio server output.
* @returns {string} terminal colorized message.
* @returns {string} origial output text.
* @private
*/
function formatOutputColored(output) {
function formatOutput(output) {
let time = "";
if (output.format === "seconds") {
time = chalk.yellow(output.time.padStart(8)) + " ";
time = `${output.time.padStart(8)} `;
} else if (output.format === "date") {
time = chalk.yellow(output.time) + " ";
time = `${output.time} `;
}
let info = "";
if (output.type === "log") {
let level = output.level;
if (level === "Info") {
level = chalk.bold.blueBright(level);
} else if (output.level === "Warning") {
level = chalk.bold.yellowBright(level);
} else if (output.level === "Error") {
level = chalk.bold.redBright(level);
}
info = level + " " + chalk.gray(output.file) + ": ";
info = `${output.level} ${output.file}: `;
} else if (output.type === "action") {
info = "[" + chalk.yellow(output.action) + "] ";
info = `[${output.action}] `;
}
return time + info + output.message;
return `${time}${info}${output.message}`;
}
/**
* Connector for control connection to master server
* @private
*/
class ControlConnector extends link.WebSocketClientConnector {
export class ControlConnector extends link.WebSocketClientConnector {
constructor(url, reconnectDelay, token) {
super(url, reconnectDelay);
this._token = token;
@@ -53,7 +45,7 @@ class ControlConnector extends link.WebSocketClientConnector {
console.log("SOCKET | registering control");
this.sendHandshake("register_control", {
token: this._token,
agent: "clusterctl",
agent: "web",
version: "2.0.0-alpha",
});
}
@@ -65,16 +57,15 @@ class ControlConnector extends link.WebSocketClientConnector {
* Connects to the master server over WebSocket and sends commands to it.
* @static
*/
class Control extends link.Link {
export class Control extends link.Link {
constructor(connector, controlPlugins) {
super("control", "master", connector);
link.attachAllMessages(this);
/**
* Mapping of plugin names to their instance for loaded plugins.
* @type {Map<string, module:lib/plugin.BaseControlPlugin>}
*/
/**
* Mapping of plugin names to their instance for loaded plugins.
* @type {Map<string, module:lib/plugin.BaseControlPlugin>}
*/
this.plugins = controlPlugins;
for (let controlPlugin of controlPlugins.values()) {
plugin.attachPluginMessages(this, controlPlugin.info, controlPlugin);
@@ -83,7 +74,7 @@ class Control extends link.Link {
async instanceOutputEventHandler(message) {
let { instance_id, output } = message.data;
console.log(formatOutputColored(output));
console.log(formatOutput(output));
window.instanceOutputEventHandler && window.instanceOutputEventHandler({instance_id, output})
}
@@ -105,8 +96,3 @@ class Control extends link.Link {
await this.connector.close(1001, "Control Quit");
}
}
export {
ControlConnector,
Control
}
+4 -26
View File
@@ -1,11 +1,13 @@
import { Control, ControlConnector } from "./../util/websocket"
import * as errors from "./../lib/errors"
import * as link from "./../lib/link"
import * as errors from "@clusterio/lib/errors"
import * as link from "@clusterio/lib/link"
import config from "@clusterio/lib/config"
let control, controlConnector
// Create WS connection to master. Used by all components through the interface exported here.
(async () => {
config.finalizeConfigs();
controlConnector = new ControlConnector(
localStorage.getItem("master_url"),
10, // Reconnect delay
@@ -16,31 +18,7 @@ let control, controlConnector
await controlConnector.connect();
} catch (err) {
console.log(err)
if (err instanceof errors.AuthenticationFailed) {
throw new errors.StartupError(err.message);
}
throw err;
}
let response = await link.messages.listSlaves.send(control);
// console.log(response.list);
console.log(link.messages)
let data = {}
// for (let key in {
// ...link.messages,
// }) {
// if (link.messages[key].constructor.name === "Request") {
// let resp, error
// try{
// resp = await link.messages[key].send(control)
// } catch(e){
// error = e
// }
// data[key] = resp
// data[key].error = error
// }
// }
// console.log(data)
})()
let listSlaves = createListFunction("listSlaves")