mirror of https://github.com/embarklabs/embark.git
Merge pull request #378 from embark-framework/bug_fix/limit-plugins-on-envs
Add context to limit plugins that should not run in the simulator
This commit is contained in:
commit
c77d52c926
|
@ -1,3 +1,11 @@
|
||||||
{
|
{
|
||||||
"httpContractsDirectory": ".embark/contracts/"
|
"httpContractsDirectory": ".embark/contracts/",
|
||||||
|
"contexts": {
|
||||||
|
"simulator": "simulator",
|
||||||
|
"blockchain": "blockchain",
|
||||||
|
"any": "any"
|
||||||
|
},
|
||||||
|
"events": {
|
||||||
|
"contextChange": "contextChange"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ let ServicesMonitor = require('./services_monitor.js');
|
||||||
let Pipeline = require('../pipeline/pipeline.js');
|
let Pipeline = require('../pipeline/pipeline.js');
|
||||||
let Watch = require('../pipeline/watch.js');
|
let Watch = require('../pipeline/watch.js');
|
||||||
let LibraryManager = require('../versions/library_manager.js');
|
let LibraryManager = require('../versions/library_manager.js');
|
||||||
|
const constants = require('../constants');
|
||||||
|
|
||||||
class Engine {
|
class Engine {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
|
@ -19,6 +20,7 @@ class Engine {
|
||||||
this.logFile = options.logFile;
|
this.logFile = options.logFile;
|
||||||
this.logLevel = options.logLevel;
|
this.logLevel = options.logLevel;
|
||||||
this.events = options.events;
|
this.events = options.events;
|
||||||
|
this.context = constants.contexts.simulator; // Will change to blockchain once we can connect to the blockchain
|
||||||
}
|
}
|
||||||
|
|
||||||
init(_options) {
|
init(_options) {
|
||||||
|
@ -226,6 +228,15 @@ class Engine {
|
||||||
return cb({name: version, status: 'on'});
|
return cb({name: version, status: 'on'});
|
||||||
}
|
}
|
||||||
let nodeName = version.split("/")[0];
|
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) {
|
||||||
|
self.events.emit(constants.events.contextChange, self.context);
|
||||||
|
}
|
||||||
let versionNumber = version.split("/")[1].split("-")[0];
|
let versionNumber = version.split("/")[1].split("-")[0];
|
||||||
let name = nodeName + " " + versionNumber + " (Ethereum)";
|
let name = nodeName + " " + versionNumber + " (Ethereum)";
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
var fs = require('./fs.js');
|
const fs = require('./fs.js');
|
||||||
var utils = require('../utils/utils.js');
|
const utils = require('../utils/utils.js');
|
||||||
|
const constants = require('../constants');
|
||||||
|
|
||||||
// TODO: pass other params like blockchainConfig, contract files, etc..
|
// TODO: pass other params like blockchainConfig, contract files, etc..
|
||||||
var Plugin = function(options) {
|
var Plugin = function(options) {
|
||||||
|
@ -27,9 +28,20 @@ var Plugin = function(options) {
|
||||||
this.logger = options.logger;
|
this.logger = options.logger;
|
||||||
this.events = options.events;
|
this.events = options.events;
|
||||||
this.config = options.config;
|
this.config = options.config;
|
||||||
|
this.loaded = false;
|
||||||
|
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) {
|
||||||
|
if (currentContext) {
|
||||||
|
this.logger.warn(`Plugin ${this.name} can only be loaded in the context of the ${this.context}`);
|
||||||
|
}
|
||||||
|
return this.events.on(constants.events.contextChange, this.loadPlugin.bind(this));
|
||||||
|
}
|
||||||
|
this.loaded = true;
|
||||||
|
this.logger.info(`Loaded plugin ${this.name}`);
|
||||||
|
this.events.removeListener(constants.events.contextChange, this.loadPlugin.bind(this));
|
||||||
if (this.shouldInterceptLogs) {
|
if (this.shouldInterceptLogs) {
|
||||||
this.interceptLogs(this.pluginModule);
|
this.interceptLogs(this.pluginModule);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,10 +20,12 @@ Plugins.prototype.loadPlugins = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
Plugins.prototype.listPlugins = function() {
|
Plugins.prototype.listPlugins = function() {
|
||||||
var list = [];
|
const list = [];
|
||||||
for (var className in this.pluginList) {
|
this.plugins.forEach(plugin => {
|
||||||
list.push(className);
|
if (plugin.loaded) {
|
||||||
}
|
list.push(plugin.name);
|
||||||
|
}
|
||||||
|
});
|
||||||
return list;
|
return list;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -67,9 +67,9 @@ class Embark {
|
||||||
engine.init();
|
engine.init();
|
||||||
|
|
||||||
if (!options.useDashboard) {
|
if (!options.useDashboard) {
|
||||||
console.log('========================'.bold.green);
|
engine.logger.info('========================'.bold.green);
|
||||||
console.log(('Welcome to Embark ' + this.version).yellow.bold);
|
engine.logger.info(('Welcome to Embark ' + this.version).yellow.bold);
|
||||||
console.log('========================'.bold.green);
|
engine.logger.info('========================'.bold.green);
|
||||||
}
|
}
|
||||||
|
|
||||||
async.parallel([
|
async.parallel([
|
||||||
|
|
Loading…
Reference in New Issue