Skip to content

Commit c77d52c

Browse files
authored
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
2 parents 5fb3cb3 + 97e91d4 commit c77d52c

File tree

5 files changed

+44
-11
lines changed

5 files changed

+44
-11
lines changed

lib/constants.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
{
2-
"httpContractsDirectory": ".embark/contracts/"
2+
"httpContractsDirectory": ".embark/contracts/",
3+
"contexts": {
4+
"simulator": "simulator",
5+
"blockchain": "blockchain",
6+
"any": "any"
7+
},
8+
"events": {
9+
"contextChange": "contextChange"
10+
}
311
}

lib/core/engine.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ let ServicesMonitor = require('./services_monitor.js');
99
let Pipeline = require('../pipeline/pipeline.js');
1010
let Watch = require('../pipeline/watch.js');
1111
let LibraryManager = require('../versions/library_manager.js');
12+
const constants = require('../constants');
1213

1314
class Engine {
1415
constructor(options) {
@@ -19,6 +20,7 @@ class Engine {
1920
this.logFile = options.logFile;
2021
this.logLevel = options.logLevel;
2122
this.events = options.events;
23+
this.context = constants.contexts.simulator; // Will change to blockchain once we can connect to the blockchain
2224
}
2325

2426
init(_options) {
@@ -226,6 +228,15 @@ class Engine {
226228
return cb({name: version, status: 'on'});
227229
}
228230
let nodeName = version.split("/")[0];
231+
const oldContext = self.context;
232+
if (nodeName === 'Geth' || nodeName.toLowerCase().indexOf('test') < 0) {
233+
self.context = constants.contexts.blockchain;
234+
} else {
235+
self.context = constants.contexts.simulator;
236+
}
237+
if (oldContext !== self.context) {
238+
self.events.emit(constants.events.contextChange, self.context);
239+
}
229240
let versionNumber = version.split("/")[1].split("-")[0];
230241
let name = nodeName + " " + versionNumber + " (Ethereum)";
231242

lib/core/plugin.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
var fs = require('./fs.js');
2-
var utils = require('../utils/utils.js');
1+
const fs = require('./fs.js');
2+
const utils = require('../utils/utils.js');
3+
const constants = require('../constants');
34

45
// TODO: pass other params like blockchainConfig, contract files, etc..
56
var Plugin = function(options) {
@@ -27,9 +28,20 @@ var Plugin = function(options) {
2728
this.logger = options.logger;
2829
this.events = options.events;
2930
this.config = options.config;
31+
this.loaded = false;
32+
this.context = options.pluginConfig.context || constants.contexts.any;
3033
};
3134

32-
Plugin.prototype.loadPlugin = function() {
35+
Plugin.prototype.loadPlugin = function(currentContext) {
36+
if (this.context !== constants.contexts.any && this.context !== currentContext) {
37+
if (currentContext) {
38+
this.logger.warn(`Plugin ${this.name} can only be loaded in the context of the ${this.context}`);
39+
}
40+
return this.events.on(constants.events.contextChange, this.loadPlugin.bind(this));
41+
}
42+
this.loaded = true;
43+
this.logger.info(`Loaded plugin ${this.name}`);
44+
this.events.removeListener(constants.events.contextChange, this.loadPlugin.bind(this));
3345
if (this.shouldInterceptLogs) {
3446
this.interceptLogs(this.pluginModule);
3547
}

lib/core/plugins.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ Plugins.prototype.loadPlugins = function() {
2020
};
2121

2222
Plugins.prototype.listPlugins = function() {
23-
var list = [];
24-
for (var className in this.pluginList) {
25-
list.push(className);
26-
}
23+
const list = [];
24+
this.plugins.forEach(plugin => {
25+
if (plugin.loaded) {
26+
list.push(plugin.name);
27+
}
28+
});
2729
return list;
2830
};
2931

lib/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ class Embark {
6767
engine.init();
6868

6969
if (!options.useDashboard) {
70-
console.log('========================'.bold.green);
71-
console.log(('Welcome to Embark ' + this.version).yellow.bold);
72-
console.log('========================'.bold.green);
70+
engine.logger.info('========================'.bold.green);
71+
engine.logger.info(('Welcome to Embark ' + this.version).yellow.bold);
72+
engine.logger.info('========================'.bold.green);
7373
}
7474

7575
async.parallel([

0 commit comments

Comments
 (0)