Skip to content

Commit 51c2c8f

Browse files
committed
check context and on changing context, load plugins that work
1 parent 5fb3cb3 commit 51c2c8f

File tree

4 files changed

+34
-7
lines changed

4 files changed

+34
-7
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: 12 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,16 @@ 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+
console.log('Emiting context change');
239+
self.events.emit(constants.events.contextChange, self.context);
240+
}
229241
let versionNumber = version.split("/")[1].split("-")[0];
230242
let name = nodeName + " " + versionNumber + " (Ethereum)";
231243

lib/core/plugin.js

Lines changed: 10 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,15 @@ var Plugin = function(options) {
2728
this.logger = options.logger;
2829
this.events = options.events;
2930
this.config = options.config;
31+
this.context = options.pluginConfig.context || constants.contexts.any;
3032
};
3133

32-
Plugin.prototype.loadPlugin = function() {
34+
Plugin.prototype.loadPlugin = function(currentContext) {
35+
if (this.context !== constants.contexts.any && this.context !== currentContext) {
36+
this.events.on(constants.events.contextChange, this.loadPlugin.bind(this));
37+
return;
38+
}
39+
this.events.removeListener(constants.events.contextChange, this.loadPlugin.bind(this));
3340
if (this.shouldInterceptLogs) {
3441
this.interceptLogs(this.pluginModule);
3542
}

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)