From 0e03d8f4350f7374f5e0fd9af5987d63dd874ae0 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Mon, 20 Feb 2017 18:02:17 -0500 Subject: [PATCH] refactor: move dashboard board init logic into a separate module --- lib/dashboard/dashboard.js | 43 ++++++++++++++++++++++++++++++++++++++ lib/index.js | 33 +++++++++++------------------ 2 files changed, 55 insertions(+), 21 deletions(-) create mode 100644 lib/dashboard/dashboard.js diff --git a/lib/dashboard/dashboard.js b/lib/dashboard/dashboard.js new file mode 100644 index 00000000..d67b142d --- /dev/null +++ b/lib/dashboard/dashboard.js @@ -0,0 +1,43 @@ +var async = require('async'); + +var Monitor = require('./monitor.js'); +var Console = require('./console.js'); + +var Dashboard = function(options) { + this.logger = options.logger; + this.plugins = options.plugins; + this.version = options.version; + this.env = options.env; +}; + +Dashboard.prototype.start = function(done) { + var console, monitor; + var self = this; + + async.waterfall([ + function startConsole(callback) { + console = new Console({plugins: self.plugins, version: self.version}); + callback(); + }, + function startMonitor(callback) { + monitor = new Monitor({env: self.env, console: console}); + self.logger.logFunction = monitor.logEntry; + self.logger.contractsState = monitor.setContracts; + self.logger.availableServices = monitor.availableServices; + self.logger.setStatus = monitor.setStatus.bind(monitor); + + 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; diff --git a/lib/index.js b/lib/index.js index 94450d34..370b3b54 100644 --- a/lib/index.js +++ b/lib/index.js @@ -16,8 +16,7 @@ var Logger = require('./core/logger.js'); var Config = require('./core/config.js'); var ServicesMonitor = require('./core/services.js'); -var Monitor = require('./dashboard/monitor.js'); -var Console = require('./dashboard/console.js'); +var Dashboard = require('./dashboard/dashboard.js'); var Pipeline = require('./pipeline/pipeline.js'); var Server = require('./pipeline/server.js'); @@ -102,28 +101,18 @@ var Embark = { } callback(); }, - function startConsole(callback) { - Embark.console = new Console({plugins: self.plugins, version: self.version}); - callback(); - }, - function startMonitor(callback) { + function startDashboard(callback) { if (!options.useDashboard) { return callback(); } - Embark.monitor = new Monitor({env: env, console: Embark.console}); - self.logger.logFunction = Embark.monitor.logEntry; - self.logger.contractsState = Embark.monitor.setContracts; - self.logger.availableServices = Embark.monitor.availableServices; - self.logger.setStatus = Embark.monitor.setStatus.bind(Embark.monitor); - if (options.useDashboard) { - self.logger.info('========================'.bold.green); - self.logger.info(('Welcome to Embark ' + Embark.version).yellow.bold); - self.logger.info('========================'.bold.green); - } - - // TODO: do this after monitor is rendered - callback(); + Embark.dashboard = new Dashboard({ + logger: Embark.logger, + plugins: self.plugins, + version: self.version, + env: env + }); + Embark.dashboard.start(callback); }, function displayLoadedPlugins(callback) { var pluginList = self.plugins.listPlugins(); @@ -327,7 +316,9 @@ var Embark = { function generateConsoleABI(contractsManager, callback) { var abiGenerator = new ABIGenerator({blockchainConfig: self.config.blockchainConfig, contractsManager: contractsManager, storageConfig: self.config.storageConfig, communicationConfig: self.config.communicationConfig}); var consoleABI = abiGenerator.generateABI({useEmbarkJS: false}); - Embark.console.runCode(consoleABI); + // not good, better generate events when deployment is done and do this + // through a listener + Embark.dashboard.console.runCode(consoleABI); callback(null, contractsManager); }, function generateABI(contractsManager, callback) {