refactor: move dashboard board init logic into a separate module
This commit is contained in:
parent
70ee9f3276
commit
0e03d8f435
|
@ -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;
|
33
lib/index.js
33
lib/index.js
|
@ -16,8 +16,7 @@ var Logger = require('./core/logger.js');
|
||||||
var Config = require('./core/config.js');
|
var Config = require('./core/config.js');
|
||||||
var ServicesMonitor = require('./core/services.js');
|
var ServicesMonitor = require('./core/services.js');
|
||||||
|
|
||||||
var Monitor = require('./dashboard/monitor.js');
|
var Dashboard = require('./dashboard/dashboard.js');
|
||||||
var Console = require('./dashboard/console.js');
|
|
||||||
|
|
||||||
var Pipeline = require('./pipeline/pipeline.js');
|
var Pipeline = require('./pipeline/pipeline.js');
|
||||||
var Server = require('./pipeline/server.js');
|
var Server = require('./pipeline/server.js');
|
||||||
|
@ -102,28 +101,18 @@ var Embark = {
|
||||||
}
|
}
|
||||||
callback();
|
callback();
|
||||||
},
|
},
|
||||||
function startConsole(callback) {
|
function startDashboard(callback) {
|
||||||
Embark.console = new Console({plugins: self.plugins, version: self.version});
|
|
||||||
callback();
|
|
||||||
},
|
|
||||||
function startMonitor(callback) {
|
|
||||||
if (!options.useDashboard) {
|
if (!options.useDashboard) {
|
||||||
return callback();
|
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) {
|
Embark.dashboard = new Dashboard({
|
||||||
self.logger.info('========================'.bold.green);
|
logger: Embark.logger,
|
||||||
self.logger.info(('Welcome to Embark ' + Embark.version).yellow.bold);
|
plugins: self.plugins,
|
||||||
self.logger.info('========================'.bold.green);
|
version: self.version,
|
||||||
}
|
env: env
|
||||||
|
});
|
||||||
// TODO: do this after monitor is rendered
|
Embark.dashboard.start(callback);
|
||||||
callback();
|
|
||||||
},
|
},
|
||||||
function displayLoadedPlugins(callback) {
|
function displayLoadedPlugins(callback) {
|
||||||
var pluginList = self.plugins.listPlugins();
|
var pluginList = self.plugins.listPlugins();
|
||||||
|
@ -327,7 +316,9 @@ var Embark = {
|
||||||
function generateConsoleABI(contractsManager, callback) {
|
function generateConsoleABI(contractsManager, callback) {
|
||||||
var abiGenerator = new ABIGenerator({blockchainConfig: self.config.blockchainConfig, contractsManager: contractsManager, storageConfig: self.config.storageConfig, communicationConfig: self.config.communicationConfig});
|
var abiGenerator = new ABIGenerator({blockchainConfig: self.config.blockchainConfig, contractsManager: contractsManager, storageConfig: self.config.storageConfig, communicationConfig: self.config.communicationConfig});
|
||||||
var consoleABI = abiGenerator.generateABI({useEmbarkJS: false});
|
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);
|
callback(null, contractsManager);
|
||||||
},
|
},
|
||||||
function generateABI(contractsManager, callback) {
|
function generateABI(contractsManager, callback) {
|
||||||
|
|
Loading…
Reference in New Issue