embark/lib/dashboard/dashboard.js

58 lines
1.5 KiB
JavaScript
Raw Normal View History

2017-03-30 02:50:05 +09:00
let async = require('async');
2017-03-30 02:50:05 +09:00
let Monitor = require('./monitor.js');
let Console = require('./console.js');
2017-03-30 20:12:39 +09:00
class Dashboard {
constructor(options) {
this.logger = options.logger;
2017-12-17 18:34:41 -05:00
this.events = options.events;
2017-03-30 20:12:39 +09:00
this.plugins = options.plugins;
this.version = options.version;
this.env = options.env;
2017-07-06 19:50:36 -04:00
this.contractsConfig = options.contractsConfig;
2017-03-30 20:12:39 +09:00
}
start(done) {
let console, monitor;
let self = this;
async.waterfall([
function startConsole(callback) {
2017-12-17 18:34:41 -05:00
console = new Console({
events: self.events,
plugins: self.plugins,
version: self.version,
contractsConfig: self.contractsConfig
});
2017-03-30 20:12:39 +09:00
callback();
},
function startMonitor(callback) {
2018-02-27 17:04:41 -05:00
monitor = new Monitor({env: self.env, console: console, events: self.events});
2017-03-30 20:12:39 +09:00
self.logger.logFunction = monitor.logEntry;
self.events.on('contractsState', monitor.setContracts);
self.events.on('status', monitor.setStatus.bind(monitor));
2018-02-27 17:50:43 -05:00
self.events.setCommandHandler("console:command", (cmd, cb) => {
cb(monitor.executeCmd(cmd));
});
2017-03-30 20:12:39 +09:00
self.logger.info('========================'.bold.green);
self.logger.info(('Welcome to Embark ' + self.version).yellow.bold);
self.logger.info('========================'.bold.green);
// TODO: do this after monitor is rendered
callback();
}
], function () {
self.console = console;
self.monitor = monitor;
done();
});
}
}
module.exports = Dashboard;