diff --git a/cmd/cmd_controller.js b/cmd/cmd_controller.js index f7c46b1ef..27785a35e 100644 --- a/cmd/cmd_controller.js +++ b/cmd/cmd_controller.js @@ -126,6 +126,7 @@ class EmbarkController { } engine.startService("processManager"); + engine.startService("embark"); engine.startService("serviceMonitor"); engine.startService("libraryManager"); engine.startService("codeRunner"); diff --git a/embark-ui/src/components/Console.js b/embark-ui/src/components/Console.js index cd99cc1f9..dcf6c0df4 100644 --- a/embark-ui/src/components/Console.js +++ b/embark-ui/src/components/Console.js @@ -31,24 +31,43 @@ class Console extends Component { this.setState({value: event.target.value}); } + renderCommandsResult(){ + const {commands} = this.props; + return ( + this.state.selectedProcess === this.DEFAULT_PROCESS && + commands.map((command, index) => { + return ; + }) + ); + } + renderTabs() { - const {processLogs, processes, commands} = this.props; - return processes.map(process => ( - this.clickTab(e, x)}> - - { - processLogs.reverse().filter((item) => item.name === process.name) - .map((item, i) =>

) - } - {process.name === "embark" && commands.map((command, index) => )} -
-
+ const {processLogs, processes} = this.props; + return processes + .sort((a, b) => { // ensure the "Embark" tab is displayed first + if (a.name === this.DEFAULT_PROCESS) return -1; + if (b.name === this.DEFAULT_PROCESS) return 1; + return 0; + }) + .map(process => ( + this.clickTab(e, x)}> + + { + processLogs + .reverse() + .filter((item) => item.name === process.name) + .sort((a, b) => a.timestamp - b.timestamp) + .map((item, i) =>

) + } +
+
)); } render() { const tabs = this.renderTabs(); + const commandsResult = this.renderCommandsResult(); const {value} = this.state; return ( @@ -65,6 +84,7 @@ class Console extends Component { {tabs} + {commandsResult} diff --git a/lib/core/engine.js b/lib/core/engine.js index 7005a7301..9fd9b8373 100644 --- a/lib/core/engine.js +++ b/lib/core/engine.js @@ -38,9 +38,6 @@ class Engine { if (this.interceptLogs || this.interceptLogs === undefined) { utils.interceptLogs(console, this.logger); } - - // register API calls for the logger - this.logger.registerAPICall(this.plugins); this.ipc = new IPC({logger: this.logger, ipcRole: this.ipcRole}); if (this.ipc.isClient()) { @@ -81,7 +78,8 @@ class Engine { "pluginCommand": this.pluginCommandService, "testRunner": this.testRunnerService, "codeCoverage": this.codeCoverageService, - "scaffolding": this.scaffoldingService + "scaffolding": this.scaffoldingService, + "embark": this.embarkService }; let service = services[serviceName]; @@ -95,6 +93,13 @@ class Engine { return service.apply(this, [options]); } + embarkService(_options){ + this.registerModule('embark', { + events: this.events, + logger: this.logger + }); + } + processManagerService(_options) { const ProcessManager = require('./processes/processManager.js'); this.processManager = new ProcessManager({ diff --git a/lib/core/logger.js b/lib/core/logger.js index ac75bfb45..0d0624b36 100644 --- a/lib/core/logger.js +++ b/lib/core/logger.js @@ -9,8 +9,8 @@ class Logger { this.logLevel = options.logLevel || 'info'; this.logFunction = options.logFunction || console.log; this.logFile = options.logFile; - this.dateFormat = 'YYYY-MM-DD HH:mm:ss'; - this.logRegex = /\[(?\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d)\] (?:\[(?\w*)\]:?)?\s?\s?(?.*)/gmi; + this.dateFormat = 'YYYY-MM-DD HH:mm:ss:SSS'; + this.logRegex = /\[(?\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d:\d\d\d)\] (?:\[(?\w*)\]:?)?\s?\s?(?.*)/gmi; // Use a default logFile if none is specified in the cli, // in the format .embark/embark-log__YYYY-MM-DD_HH-mm-ss.log. @@ -44,13 +44,6 @@ Logger.prototype.registerAPICall = function (plugins) { }); } ); - plugin.registerAPICall( - 'get', - '/embark-api/process-logs/embark', - (req, res) => { - res.send(this.parseLogFile()); - } - ); }; /** diff --git a/lib/core/processes/processManager.js b/lib/core/processes/processManager.js index 5a65bc1a2..2fa52af0e 100644 --- a/lib/core/processes/processManager.js +++ b/lib/core/processes/processManager.js @@ -11,7 +11,7 @@ class ProcessManager { } _registerAsPlugin() { - const self =this; + const self = this; self.plugin = this.plugins.createPlugin('processManager', {}); self.plugin.registerAPICall( 'get', @@ -21,8 +21,7 @@ class ProcessManager { acc.push({state: self.processes[processName].state, name: processName}); return acc; }; - // add "embark" process to list of running processes - res.send(Object.keys(self.processes).reduce(formatter, []).concat({ state: "running", name: "embark" })); + res.send(Object.keys(self.processes).reduce(formatter, [])); } ); } diff --git a/lib/modules/embark/index.js b/lib/modules/embark/index.js new file mode 100644 index 000000000..1f5a96cca --- /dev/null +++ b/lib/modules/embark/index.js @@ -0,0 +1,29 @@ +class Embark { + constructor(embark) { + this.embark = embark; + this.logger = embark.logger; + this.events = embark.events; + + this.registerProcess(); + this.registerAPICalls(); + } + + registerProcess() { + this.events.request('processes:register', 'embark', (setRunning) => { + this.events.on('outputDone', setRunning); + }); + this.events.request('processes:launch', 'embark', () => {}); + } + + registerAPICalls(){ + this.embark.registerAPICall( + 'get', + '/embark-api/process-logs/embark', + (req, res) => { + res.send(this.logger.parseLogFile()); + } + ); + } +} + +module.exports = Embark;