File tree Expand file tree Collapse file tree 5 files changed +44
-11
lines changed Expand file tree Collapse file tree 5 files changed +44
-11
lines changed Original file line number Diff line number Diff line change 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}
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ let ServicesMonitor = require('./services_monitor.js');
99let Pipeline = require ( '../pipeline/pipeline.js' ) ;
1010let Watch = require ( '../pipeline/watch.js' ) ;
1111let LibraryManager = require ( '../versions/library_manager.js' ) ;
12+ const constants = require ( '../constants' ) ;
1213
1314class 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
Original file line number Diff line number Diff line change 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..
56var 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 }
Original file line number Diff line number Diff line change @@ -20,10 +20,12 @@ Plugins.prototype.loadPlugins = function() {
2020} ;
2121
2222Plugins . 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
Original file line number Diff line number Diff 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 ( [
You can’t perform that action at this time.
0 commit comments