mirror of https://github.com/embarklabs/embark.git
Addressed PR feedback
- Created an “embark” module so that an “embark” process could be registered in the correct way. This service is only used on `embark run` (can be extended to other commands if needed). - extracted “embark” to a const `DEFAULT_PROCESS` param in the `Console` component. - extracted commands result rendering to it’s own function to keep the `renderTabs` function from getting cluttered - Added sorting of logs by timestamp - Added milliseconds to the log file data (which helps in sorting log messages).
This commit is contained in:
parent
487b18c8b2
commit
7de72cb474
|
@ -126,6 +126,7 @@ class EmbarkController {
|
||||||
}
|
}
|
||||||
|
|
||||||
engine.startService("processManager");
|
engine.startService("processManager");
|
||||||
|
engine.startService("embark");
|
||||||
engine.startService("serviceMonitor");
|
engine.startService("serviceMonitor");
|
||||||
engine.startService("libraryManager");
|
engine.startService("libraryManager");
|
||||||
engine.startService("codeRunner");
|
engine.startService("codeRunner");
|
||||||
|
|
|
@ -31,17 +31,35 @@ class Console extends Component {
|
||||||
this.setState({value: event.target.value});
|
this.setState({value: event.target.value});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
renderCommandsResult(){
|
||||||
|
const {commands} = this.props;
|
||||||
|
return (
|
||||||
|
this.state.selectedProcess === this.DEFAULT_PROCESS &&
|
||||||
|
commands.map((command, index) => {
|
||||||
|
return <CommandResult key={index} result={command.result}/>;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
renderTabs() {
|
renderTabs() {
|
||||||
const {processLogs, processes, commands} = this.props;
|
const {processLogs, processes} = this.props;
|
||||||
return processes.map(process => (
|
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 => (
|
||||||
<Tab title={process.name} key={process.name} onClick={(e, x) => this.clickTab(e, x)}>
|
<Tab title={process.name} key={process.name} onClick={(e, x) => this.clickTab(e, x)}>
|
||||||
<Logs>
|
<Logs>
|
||||||
{
|
{
|
||||||
processLogs.reverse().filter((item) => item.name === process.name)
|
processLogs
|
||||||
|
.reverse()
|
||||||
|
.filter((item) => item.name === process.name)
|
||||||
|
.sort((a, b) => a.timestamp - b.timestamp)
|
||||||
.map((item, i) => <p key={i} className={item.logLevel}
|
.map((item, i) => <p key={i} className={item.logLevel}
|
||||||
dangerouslySetInnerHTML={{__html: convert.toHtml(item.msg)}}></p>)
|
dangerouslySetInnerHTML={{__html: convert.toHtml(item.msg)}}></p>)
|
||||||
}
|
}
|
||||||
{process.name === "embark" && commands.map((command, index) => <CommandResult key={index} result={command.result}/>)}
|
|
||||||
</Logs>
|
</Logs>
|
||||||
</Tab>
|
</Tab>
|
||||||
));
|
));
|
||||||
|
@ -49,6 +67,7 @@ class Console extends Component {
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const tabs = this.renderTabs();
|
const tabs = this.renderTabs();
|
||||||
|
const commandsResult = this.renderCommandsResult();
|
||||||
const {value} = this.state;
|
const {value} = this.state;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -65,6 +84,7 @@ class Console extends Component {
|
||||||
</TabbedHeader>
|
</TabbedHeader>
|
||||||
<TabbedContainer selectedTitle={this.props.activeProcess}>
|
<TabbedContainer selectedTitle={this.props.activeProcess}>
|
||||||
{tabs}
|
{tabs}
|
||||||
|
{commandsResult}
|
||||||
</TabbedContainer>
|
</TabbedContainer>
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
</Card.Body>
|
</Card.Body>
|
||||||
|
|
|
@ -39,9 +39,6 @@ class Engine {
|
||||||
utils.interceptLogs(console, this.logger);
|
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});
|
this.ipc = new IPC({logger: this.logger, ipcRole: this.ipcRole});
|
||||||
if (this.ipc.isClient()) {
|
if (this.ipc.isClient()) {
|
||||||
return this.ipc.connect((_err) => {
|
return this.ipc.connect((_err) => {
|
||||||
|
@ -81,7 +78,8 @@ class Engine {
|
||||||
"pluginCommand": this.pluginCommandService,
|
"pluginCommand": this.pluginCommandService,
|
||||||
"testRunner": this.testRunnerService,
|
"testRunner": this.testRunnerService,
|
||||||
"codeCoverage": this.codeCoverageService,
|
"codeCoverage": this.codeCoverageService,
|
||||||
"scaffolding": this.scaffoldingService
|
"scaffolding": this.scaffoldingService,
|
||||||
|
"embark": this.embarkService
|
||||||
};
|
};
|
||||||
|
|
||||||
let service = services[serviceName];
|
let service = services[serviceName];
|
||||||
|
@ -95,6 +93,13 @@ class Engine {
|
||||||
return service.apply(this, [options]);
|
return service.apply(this, [options]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
embarkService(_options){
|
||||||
|
this.registerModule('embark', {
|
||||||
|
events: this.events,
|
||||||
|
logger: this.logger
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
processManagerService(_options) {
|
processManagerService(_options) {
|
||||||
const ProcessManager = require('./processes/processManager.js');
|
const ProcessManager = require('./processes/processManager.js');
|
||||||
this.processManager = new ProcessManager({
|
this.processManager = new ProcessManager({
|
||||||
|
|
|
@ -9,8 +9,8 @@ class Logger {
|
||||||
this.logLevel = options.logLevel || 'info';
|
this.logLevel = options.logLevel || 'info';
|
||||||
this.logFunction = options.logFunction || console.log;
|
this.logFunction = options.logFunction || console.log;
|
||||||
this.logFile = options.logFile;
|
this.logFile = options.logFile;
|
||||||
this.dateFormat = 'YYYY-MM-DD HH:mm:ss';
|
this.dateFormat = 'YYYY-MM-DD HH:mm:ss:SSS';
|
||||||
this.logRegex = /\[(?<date>\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d)\] (?:\[(?<logLevel>\w*)\]:?)?\s?\s?(?<msg>.*)/gmi;
|
this.logRegex = /\[(?<date>\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d:\d\d\d)\] (?:\[(?<logLevel>\w*)\]:?)?\s?\s?(?<msg>.*)/gmi;
|
||||||
|
|
||||||
// Use a default logFile if none is specified in the cli,
|
// Use a default logFile if none is specified in the cli,
|
||||||
// in the format .embark/embark-log__YYYY-MM-DD_HH-mm-ss.log.
|
// 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());
|
|
||||||
}
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -21,8 +21,7 @@ class ProcessManager {
|
||||||
acc.push({state: self.processes[processName].state, name: processName});
|
acc.push({state: self.processes[processName].state, name: processName});
|
||||||
return acc;
|
return acc;
|
||||||
};
|
};
|
||||||
// add "embark" process to list of running processes
|
res.send(Object.keys(self.processes).reduce(formatter, []));
|
||||||
res.send(Object.keys(self.processes).reduce(formatter, []).concat({ state: "running", name: "embark" }));
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
Loading…
Reference in New Issue