check context and on changing context, load plugins that work

This commit is contained in:
Jonathan Rainville 2018-04-24 14:42:56 -04:00
parent 5fb3cb3730
commit 51c2c8f880
4 changed files with 34 additions and 7 deletions

View File

@ -1,3 +1,11 @@
{
"httpContractsDirectory": ".embark/contracts/"
"httpContractsDirectory": ".embark/contracts/",
"contexts": {
"simulator": "simulator",
"blockchain": "blockchain",
"any": "any"
},
"events": {
"contextChange": "contextChange"
}
}

View File

@ -9,6 +9,7 @@ let ServicesMonitor = require('./services_monitor.js');
let Pipeline = require('../pipeline/pipeline.js');
let Watch = require('../pipeline/watch.js');
let LibraryManager = require('../versions/library_manager.js');
const constants = require('../constants');
class Engine {
constructor(options) {
@ -19,6 +20,7 @@ class Engine {
this.logFile = options.logFile;
this.logLevel = options.logLevel;
this.events = options.events;
this.context = constants.contexts.simulator; // Will change to blockchain once we can connect to the blockchain
}
init(_options) {
@ -226,6 +228,16 @@ class Engine {
return cb({name: version, status: 'on'});
}
let nodeName = version.split("/")[0];
const oldContext = self.context;
if (nodeName === 'Geth' || nodeName.toLowerCase().indexOf('test') < 0) {
self.context = constants.contexts.blockchain;
} else {
self.context = constants.contexts.simulator;
}
if (oldContext !== self.context) {
console.log('Emiting context change');
self.events.emit(constants.events.contextChange, self.context);
}
let versionNumber = version.split("/")[1].split("-")[0];
let name = nodeName + " " + versionNumber + " (Ethereum)";

View File

@ -1,5 +1,6 @@
var fs = require('./fs.js');
var utils = require('../utils/utils.js');
const fs = require('./fs.js');
const utils = require('../utils/utils.js');
const constants = require('../constants');
// TODO: pass other params like blockchainConfig, contract files, etc..
var Plugin = function(options) {
@ -27,9 +28,15 @@ var Plugin = function(options) {
this.logger = options.logger;
this.events = options.events;
this.config = options.config;
this.context = options.pluginConfig.context || constants.contexts.any;
};
Plugin.prototype.loadPlugin = function() {
Plugin.prototype.loadPlugin = function(currentContext) {
if (this.context !== constants.contexts.any && this.context !== currentContext) {
this.events.on(constants.events.contextChange, this.loadPlugin.bind(this));
return;
}
this.events.removeListener(constants.events.contextChange, this.loadPlugin.bind(this));
if (this.shouldInterceptLogs) {
this.interceptLogs(this.pluginModule);
}

View File

@ -67,9 +67,9 @@ class Embark {
engine.init();
if (!options.useDashboard) {
console.log('========================'.bold.green);
console.log(('Welcome to Embark ' + this.version).yellow.bold);
console.log('========================'.bold.green);
engine.logger.info('========================'.bold.green);
engine.logger.info(('Welcome to Embark ' + this.version).yellow.bold);
engine.logger.info('========================'.bold.green);
}
async.parallel([