mirror of
https://github.com/status-im/embark-area-51.git
synced 2025-02-08 21:34:55 +00:00
reduce complexity of engine main metod
This commit is contained in:
parent
383d69c194
commit
617d263341
@ -27,9 +27,28 @@ Engine.prototype.init = function(_options) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Engine.prototype.startService = function(serviceName, _options) {
|
Engine.prototype.startService = function(serviceName, _options) {
|
||||||
var self = this;
|
|
||||||
var options = _options || {};
|
var options = _options || {};
|
||||||
if (serviceName === "monitor") {
|
|
||||||
|
var services = {
|
||||||
|
"monitor": this.monitorService,
|
||||||
|
"pipeline": this.pipelineService,
|
||||||
|
"abi": this.abiService,
|
||||||
|
"deployment": this.deploymentService,
|
||||||
|
"fileWatcher": this.fileWatchService,
|
||||||
|
"webServer": this.webServerService
|
||||||
|
};
|
||||||
|
|
||||||
|
var service = services[serviceName];
|
||||||
|
|
||||||
|
if (!service) {
|
||||||
|
throw new Error("unknown service: " + serviceName);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.logger.trace("calling: " + serviceName + "(" + JSON.stringify(options) + ")");
|
||||||
|
return service.apply(this, [options]);
|
||||||
|
};
|
||||||
|
|
||||||
|
Engine.prototype.monitorService = function(options) {
|
||||||
var servicesMonitor = new ServicesMonitor({
|
var servicesMonitor = new ServicesMonitor({
|
||||||
logger: this.logger,
|
logger: this.logger,
|
||||||
config: this.config,
|
config: this.config,
|
||||||
@ -39,7 +58,10 @@ Engine.prototype.startService = function(serviceName, _options) {
|
|||||||
version: this.version
|
version: this.version
|
||||||
});
|
});
|
||||||
servicesMonitor.startMonitor();
|
servicesMonitor.startMonitor();
|
||||||
} else if (serviceName === "pipeline") {
|
};
|
||||||
|
|
||||||
|
Engine.prototype.pipelineService = function(options) {
|
||||||
|
var self = this;
|
||||||
this.logger.setStatus("Building Assets");
|
this.logger.setStatus("Building Assets");
|
||||||
var pipeline = new Pipeline({
|
var pipeline = new Pipeline({
|
||||||
buildDir: this.config.buildDir,
|
buildDir: this.config.buildDir,
|
||||||
@ -58,7 +80,10 @@ Engine.prototype.startService = function(serviceName, _options) {
|
|||||||
pipeline.build(self.abi, path);
|
pipeline.build(self.abi, path);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (serviceName === "abi") {
|
};
|
||||||
|
|
||||||
|
Engine.prototype.abiService = function(options) {
|
||||||
|
var self = this;
|
||||||
var generateABICode = function(contractsManager) {
|
var generateABICode = function(contractsManager) {
|
||||||
var abiGenerator = new ABIGenerator({
|
var abiGenerator = new ABIGenerator({
|
||||||
blockchainConfig: self.config.blockchainConfig,
|
blockchainConfig: self.config.blockchainConfig,
|
||||||
@ -77,7 +102,10 @@ Engine.prototype.startService = function(serviceName, _options) {
|
|||||||
};
|
};
|
||||||
this.events.on('contractsDeployed', generateABICode);
|
this.events.on('contractsDeployed', generateABICode);
|
||||||
this.events.on('blockchainDisabled', generateABICode);
|
this.events.on('blockchainDisabled', generateABICode);
|
||||||
} else if (serviceName === "deployment") {
|
};
|
||||||
|
|
||||||
|
Engine.prototype.deploymentService = function(options) {
|
||||||
|
var self = this;
|
||||||
this.deployManager = new DeployManager({
|
this.deployManager = new DeployManager({
|
||||||
web3: options.web3,
|
web3: options.web3,
|
||||||
trackContracts: options.trackContracts,
|
trackContracts: options.trackContracts,
|
||||||
@ -90,14 +118,18 @@ Engine.prototype.startService = function(serviceName, _options) {
|
|||||||
this.events.on('file-event', function(fileType, path) {
|
this.events.on('file-event', function(fileType, path) {
|
||||||
if (fileType === 'contract' || fileType === 'config') {
|
if (fileType === 'contract' || fileType === 'config') {
|
||||||
self.config.reloadConfig();
|
self.config.reloadConfig();
|
||||||
deployManager.deployContracts(function() {});
|
self.deployManager.deployContracts(function() {});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (serviceName === "fileWatcher") {
|
};
|
||||||
|
|
||||||
|
Engine.prototype.fileWatchService = function(options) {
|
||||||
this.logger.setStatus("Watching for changes");
|
this.logger.setStatus("Watching for changes");
|
||||||
var watch = new Watch({logger: this.logger, events: this.events});
|
var watch = new Watch({logger: this.logger, events: this.events});
|
||||||
watch.start();
|
watch.start();
|
||||||
} else if (serviceName === "webServer") {
|
};
|
||||||
|
|
||||||
|
Engine.prototype.webServerService = function(options) {
|
||||||
this.logger.setStatus("Starting Server");
|
this.logger.setStatus("Starting Server");
|
||||||
var server = new Server({
|
var server = new Server({
|
||||||
logger: this.logger,
|
logger: this.logger,
|
||||||
@ -105,9 +137,6 @@ Engine.prototype.startService = function(serviceName, _options) {
|
|||||||
port: options.serverPort
|
port: options.serverPort
|
||||||
});
|
});
|
||||||
server.start(function(){});
|
server.start(function(){});
|
||||||
} else {
|
|
||||||
throw new Error("unknown service: " + serviceName);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = Engine;
|
module.exports = Engine;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user