Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/constants.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
{
"httpContractsDirectory": ".embark/contracts/"
"httpContractsDirectory": ".embark/contracts/",
"contexts": {
"simulator": "simulator",
"blockchain": "blockchain",
"any": "any"
},
"events": {
"contextChange": "contextChange"
}
}
11 changes: 11 additions & 0 deletions lib/core/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -226,6 +228,15 @@ 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) {
self.events.emit(constants.events.contextChange, self.context);
}
let versionNumber = version.split("/")[1].split("-")[0];
let name = nodeName + " " + versionNumber + " (Ethereum)";

Expand Down
18 changes: 15 additions & 3 deletions lib/core/plugin.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -27,9 +28,20 @@ var Plugin = function(options) {
this.logger = options.logger;
this.events = options.events;
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) {
this.interceptLogs(this.pluginModule);
}
Expand Down
10 changes: 6 additions & 4 deletions lib/core/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ Plugins.prototype.loadPlugins = function() {
};

Plugins.prototype.listPlugins = function() {
var list = [];
for (var className in this.pluginList) {
list.push(className);
}
const list = [];
this.plugins.forEach(plugin => {
if (plugin.loaded) {
list.push(plugin.name);
}
});
return list;
};

Expand Down
6 changes: 3 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down