From 31cb79bf5b698b8476dadda53d5249804bc3b84b Mon Sep 17 00:00:00 2001 From: Anthony Laibe Date: Thu, 30 Aug 2018 10:41:13 +0100 Subject: [PATCH] PR feedback --- cmd/cmd_controller.js | 24 +++++++----- cmd/dashboard/console.js | 47 ++++++++++++++++++++++- cmd/dashboard/dashboard.js | 4 +- cmd/dashboard/repl.js | 4 +- lib/core/modules/coderunner/codeRunner.js | 47 +---------------------- templates/demo/app/components/ens.js | 2 +- 6 files changed, 69 insertions(+), 59 deletions(-) diff --git a/cmd/cmd_controller.js b/cmd/cmd_controller.js index 305d6ea2..42265c7a 100644 --- a/cmd/cmd_controller.js +++ b/cmd/cmd_controller.js @@ -99,7 +99,8 @@ class EmbarkController { version: engine.version, events: engine.events, logger: engine.logger, - ipc: engine.ipc + ipc: engine.ipc, + config: engine.config }).startConsole(); return callback(); } @@ -110,7 +111,8 @@ class EmbarkController { plugins: engine.plugins, version: self.version, env: engine.env, - ipc: engine.ipc + ipc: engine.ipc, + config: engine.config }); dashboard.start(function () { engine.logger.info(__('dashboard start')); @@ -260,6 +262,16 @@ class EmbarkController { webpackConfigName: options.webpackConfigName }); engine.init(); + const repl = new REPL({ + env: engine.env, + plugins: engine.plugins, + version: engine.version, + events: engine.events, + logger: engine.logger, + ipc: engine.ipc, + config: engine.config + }); + repl.startConsole(); async.waterfall([ function startServices(callback) { let pluginList = engine.plugins.listPlugins(); @@ -333,14 +345,6 @@ class EmbarkController { }); }, function startREPL(callback) { - let repl = new REPL({ - env: engine.env, - plugins: engine.plugins, - version: engine.version, - events: engine.events, - logger: engine.logger, - ipc: engine.ipc - }); repl.start(callback); } ], function (err, _result) { diff --git a/cmd/dashboard/console.js b/cmd/dashboard/console.js index 79399301..31036ed7 100644 --- a/cmd/dashboard/console.js +++ b/cmd/dashboard/console.js @@ -1,5 +1,7 @@ let utils = require('../../lib/utils/utils.js'); - +const EmbarkJS = require('embarkjs'); +const IpfsApi = require('ipfs-api'); +const Web3 = require('web3'); class Console { constructor(options) { this.events = options.events; @@ -7,10 +9,13 @@ class Console { this.version = options.version; this.logger = options.logger; this.ipc = options.ipc; + this.config = options.config; if (this.ipc.isServer()) { this.ipc.on('console:executeCmd', this.executeCmd.bind(this)); } + + this.registerEmbarkJs(); } processEmbarkCmd (cmd) { @@ -65,6 +70,46 @@ class Console { callback(e); } } + + registerEmbarkJs() { + this.events.on('runcode:ready', () => { + this.events.emit('runcode:register', 'IpfsApi', IpfsApi, false); + this.events.emit('runcode:register', 'Web3', Web3, false); + this.events.emit('runcode:register', 'EmbarkJS', EmbarkJS, false); + }); + + this.events.on('code-generator-ready', () => { + if (this.ipc.connected) { + return; + } + + this.events.request('code-generator:embarkjs:provider-code', (code) => { + const func = () => {}; + this.events.request('runcode:eval', code, func, true); + this.events.request('runcode:eval', this.getInitProviderCode(), func, true); + }); + }); + } + + getInitProviderCode() { + const codeTypes = { + 'communication': this.config.communicationConfig || {}, + 'names': this.config.namesystemConfig || {}, + 'storage': this.config.storageConfig || {} + }; + + return this.plugins.getPluginsFor('initConsoleCode').reduce((acc, plugin) => { + Object.keys(codeTypes).forEach(codeTypeName => { + (plugin.embarkjs_init_console_code[codeTypeName] || []).forEach(initCode => { + let [block, shouldInit] = initCode; + if (shouldInit.call(plugin, codeTypes[codeTypeName])) { + acc += block; + } + }); + }); + return acc; + }, ''); + } } module.exports = Console; diff --git a/cmd/dashboard/dashboard.js b/cmd/dashboard/dashboard.js index 107ebb97..4c707faa 100644 --- a/cmd/dashboard/dashboard.js +++ b/cmd/dashboard/dashboard.js @@ -12,6 +12,7 @@ class Dashboard { this.version = options.version; this.env = options.env; this.ipc = options.ipc; + this.config = options.config; this.events.on('firstDeploymentDone', this.checkWindowSize.bind(this)); this.events.on('outputDone', this.checkWindowSize.bind(this)); @@ -35,7 +36,8 @@ class Dashboard { plugins: self.plugins, version: self.version, ipc: self.ipc, - logger: self.logger + logger: self.logger, + config: self.config }); callback(); }, diff --git a/cmd/dashboard/repl.js b/cmd/dashboard/repl.js index b89c20f1..a99bcd5b 100644 --- a/cmd/dashboard/repl.js +++ b/cmd/dashboard/repl.js @@ -11,6 +11,7 @@ class REPL { this.events = options.events; this.version = options.version; this.ipc = options.ipc; + this.config = options.config; } startConsole(){ @@ -19,7 +20,8 @@ class REPL { plugins: this.plugins, version: this.version, ipc: this.ipc, - logger: this.logger + logger: this.logger, + config: this.config }); } diff --git a/lib/core/modules/coderunner/codeRunner.js b/lib/core/modules/coderunner/codeRunner.js index 66f99578..daaf9e43 100644 --- a/lib/core/modules/coderunner/codeRunner.js +++ b/lib/core/modules/coderunner/codeRunner.js @@ -1,7 +1,4 @@ const RunCode = require('./runCode.js'); -const EmbarkJS = require('embarkjs'); -const IpfsApi = require('ipfs-api'); -const Web3 = require('web3'); class CodeRunner { constructor(options) { @@ -16,7 +13,7 @@ class CodeRunner { this.IpcClientListen(); this.registerEvents(); this.registerCommands(); - this.registerEmbarkJs(); + this.events.emit('runcode:ready'); } registerIpcEvents() { @@ -55,23 +52,6 @@ class CodeRunner { this.events.setCommandHandler('runcode:eval', this.evalCode.bind(this)); } - registerEmbarkJs() { - this.registerVar('IpfsApi', IpfsApi, false); - this.registerVar('Web3', Web3, false); - this.registerVar('EmbarkJS', EmbarkJS, false); - - if (this.ipc.connected) { - return; - } - this.events.on('code-generator-ready', () => { - this.events.request('code-generator:embarkjs:provider-code', (code) => { - const func = () => {}; - this.evalCode(code, func, true); - this.evalCode(this.getInitProviderCode(), func, true); - }); - }); - } - registerVar(varName, code, toRecord = true) { if (this.ipc.isServer() && toRecord) { this.commands.push({varName, code}); @@ -81,9 +61,7 @@ class CodeRunner { } evalCode(code, cb, forConsoleOnly = false) { - if (!cb) { - cb = function() {}; - } + cb = cb || function() {}; const awaitIdx = code.indexOf('await'); if (awaitIdx > -1) { if (awaitIdx < 2) { @@ -109,27 +87,6 @@ class CodeRunner { cb(null, result); } - - getInitProviderCode() { - const codeTypes = { - 'communication': this.config.communicationConfig || {}, - 'names': this.config.namesystemConfig || {}, - 'storage': this.config.storageConfig || {} - }; - - return this.plugins.getPluginsFor('initConsoleCode').reduce((acc, plugin) => { - Object.keys(codeTypes).forEach(codeTypeName => { - (plugin.embarkjs_init_console_code[codeTypeName] || []).forEach(initCode => { - let [block, shouldInit] = initCode; - if (shouldInit.call(plugin, codeTypes[codeTypeName])) { - acc += block; - } - }); - }); - return acc; - }, ''); - - } } module.exports = CodeRunner; diff --git a/templates/demo/app/components/ens.js b/templates/demo/app/components/ens.js index b5dd7c22..1afaf510 100644 --- a/templates/demo/app/components/ens.js +++ b/templates/demo/app/components/ens.js @@ -146,7 +146,7 @@ class ENS extends React.Component { -

Register subdomain for eth

+

Register subdomain

this.checkEnter(e, this.registerSubDomain)}> {this.state.responseRegister &&