2017-03-29 17:50:05 +00:00
|
|
|
let async = require('async');
|
2018-06-01 17:19:48 +00:00
|
|
|
let windowSize = require('window-size');
|
2017-02-20 23:02:17 +00:00
|
|
|
|
2017-03-29 17:50:05 +00:00
|
|
|
let Monitor = require('./monitor.js');
|
|
|
|
let Console = require('./console.js');
|
2017-02-20 23:02:17 +00:00
|
|
|
|
2017-03-30 11:12:39 +00:00
|
|
|
class Dashboard {
|
|
|
|
constructor(options) {
|
|
|
|
this.logger = options.logger;
|
2017-12-17 23:34:41 +00:00
|
|
|
this.events = options.events;
|
2017-03-30 11:12:39 +00:00
|
|
|
this.plugins = options.plugins;
|
|
|
|
this.version = options.version;
|
|
|
|
this.env = options.env;
|
2018-06-01 17:19:48 +00:00
|
|
|
|
|
|
|
this.events.on('firstDeploymentDone', this.checkWindowSize.bind(this));
|
|
|
|
this.events.on('outputDone', this.checkWindowSize.bind(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
checkWindowSize() {
|
|
|
|
let size = windowSize.get();
|
|
|
|
if (size.height < 40 || size.width < 118) {
|
|
|
|
this.logger.warn(__("tip: you can resize the terminal or disable the dashboard with") + " embark run --nodashboard".bold.underline);
|
|
|
|
}
|
2017-03-30 11:12:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
start(done) {
|
|
|
|
let console, monitor;
|
|
|
|
let self = this;
|
|
|
|
|
|
|
|
async.waterfall([
|
|
|
|
function startConsole(callback) {
|
2017-12-17 23:34:41 +00:00
|
|
|
console = new Console({
|
|
|
|
events: self.events,
|
|
|
|
plugins: self.plugins,
|
2018-07-09 08:15:13 +00:00
|
|
|
version: self.version
|
2017-12-17 23:34:41 +00:00
|
|
|
});
|
2017-03-30 11:12:39 +00:00
|
|
|
callback();
|
|
|
|
},
|
|
|
|
function startMonitor(callback) {
|
2018-02-27 22:04:41 +00:00
|
|
|
monitor = new Monitor({env: self.env, console: console, events: self.events});
|
2017-03-30 11:12:39 +00:00
|
|
|
self.logger.logFunction = monitor.logEntry;
|
|
|
|
|
2018-02-27 20:40:05 +00:00
|
|
|
self.events.on('contractsState', monitor.setContracts);
|
2018-02-27 20:49:21 +00:00
|
|
|
self.events.on('status', monitor.setStatus.bind(monitor));
|
2018-03-10 17:46:02 +00:00
|
|
|
self.events.on('servicesState', monitor.availableServices.bind(monitor));
|
2018-02-27 20:40:05 +00:00
|
|
|
|
2018-03-15 20:38:20 +00:00
|
|
|
self.events.setCommandHandler("console:command", monitor.executeCmd.bind(monitor));
|
2018-02-27 22:50:43 +00:00
|
|
|
|
2017-03-30 11:12:39 +00:00
|
|
|
self.logger.info('========================'.bold.green);
|
2018-05-08 21:49:46 +00:00
|
|
|
self.logger.info((__('Welcome to Embark') + ' ' + self.version).yellow.bold);
|
2017-03-30 11:12:39 +00:00
|
|
|
self.logger.info('========================'.bold.green);
|
|
|
|
|
|
|
|
// TODO: do this after monitor is rendered
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
], function () {
|
|
|
|
self.console = console;
|
|
|
|
self.monitor = monitor;
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2017-02-20 23:02:17 +00:00
|
|
|
|
|
|
|
module.exports = Dashboard;
|