PR feedback

This commit is contained in:
Anthony Laibe 2018-08-30 10:41:13 +01:00
parent 581b0c9f42
commit 31cb79bf5b
6 changed files with 69 additions and 59 deletions

View File

@ -99,7 +99,8 @@ class EmbarkController {
version: engine.version, version: engine.version,
events: engine.events, events: engine.events,
logger: engine.logger, logger: engine.logger,
ipc: engine.ipc ipc: engine.ipc,
config: engine.config
}).startConsole(); }).startConsole();
return callback(); return callback();
} }
@ -110,7 +111,8 @@ class EmbarkController {
plugins: engine.plugins, plugins: engine.plugins,
version: self.version, version: self.version,
env: engine.env, env: engine.env,
ipc: engine.ipc ipc: engine.ipc,
config: engine.config
}); });
dashboard.start(function () { dashboard.start(function () {
engine.logger.info(__('dashboard start')); engine.logger.info(__('dashboard start'));
@ -260,6 +262,16 @@ class EmbarkController {
webpackConfigName: options.webpackConfigName webpackConfigName: options.webpackConfigName
}); });
engine.init(); 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([ async.waterfall([
function startServices(callback) { function startServices(callback) {
let pluginList = engine.plugins.listPlugins(); let pluginList = engine.plugins.listPlugins();
@ -333,14 +345,6 @@ class EmbarkController {
}); });
}, },
function startREPL(callback) { 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); repl.start(callback);
} }
], function (err, _result) { ], function (err, _result) {

View File

@ -1,5 +1,7 @@
let utils = require('../../lib/utils/utils.js'); let utils = require('../../lib/utils/utils.js');
const EmbarkJS = require('embarkjs');
const IpfsApi = require('ipfs-api');
const Web3 = require('web3');
class Console { class Console {
constructor(options) { constructor(options) {
this.events = options.events; this.events = options.events;
@ -7,10 +9,13 @@ class Console {
this.version = options.version; this.version = options.version;
this.logger = options.logger; this.logger = options.logger;
this.ipc = options.ipc; this.ipc = options.ipc;
this.config = options.config;
if (this.ipc.isServer()) { if (this.ipc.isServer()) {
this.ipc.on('console:executeCmd', this.executeCmd.bind(this)); this.ipc.on('console:executeCmd', this.executeCmd.bind(this));
} }
this.registerEmbarkJs();
} }
processEmbarkCmd (cmd) { processEmbarkCmd (cmd) {
@ -65,6 +70,46 @@ class Console {
callback(e); 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; module.exports = Console;

View File

@ -12,6 +12,7 @@ class Dashboard {
this.version = options.version; this.version = options.version;
this.env = options.env; this.env = options.env;
this.ipc = options.ipc; this.ipc = options.ipc;
this.config = options.config;
this.events.on('firstDeploymentDone', this.checkWindowSize.bind(this)); this.events.on('firstDeploymentDone', this.checkWindowSize.bind(this));
this.events.on('outputDone', this.checkWindowSize.bind(this)); this.events.on('outputDone', this.checkWindowSize.bind(this));
@ -35,7 +36,8 @@ class Dashboard {
plugins: self.plugins, plugins: self.plugins,
version: self.version, version: self.version,
ipc: self.ipc, ipc: self.ipc,
logger: self.logger logger: self.logger,
config: self.config
}); });
callback(); callback();
}, },

View File

@ -11,6 +11,7 @@ class REPL {
this.events = options.events; this.events = options.events;
this.version = options.version; this.version = options.version;
this.ipc = options.ipc; this.ipc = options.ipc;
this.config = options.config;
} }
startConsole(){ startConsole(){
@ -19,7 +20,8 @@ class REPL {
plugins: this.plugins, plugins: this.plugins,
version: this.version, version: this.version,
ipc: this.ipc, ipc: this.ipc,
logger: this.logger logger: this.logger,
config: this.config
}); });
} }

View File

@ -1,7 +1,4 @@
const RunCode = require('./runCode.js'); const RunCode = require('./runCode.js');
const EmbarkJS = require('embarkjs');
const IpfsApi = require('ipfs-api');
const Web3 = require('web3');
class CodeRunner { class CodeRunner {
constructor(options) { constructor(options) {
@ -16,7 +13,7 @@ class CodeRunner {
this.IpcClientListen(); this.IpcClientListen();
this.registerEvents(); this.registerEvents();
this.registerCommands(); this.registerCommands();
this.registerEmbarkJs(); this.events.emit('runcode:ready');
} }
registerIpcEvents() { registerIpcEvents() {
@ -55,23 +52,6 @@ class CodeRunner {
this.events.setCommandHandler('runcode:eval', this.evalCode.bind(this)); 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) { registerVar(varName, code, toRecord = true) {
if (this.ipc.isServer() && toRecord) { if (this.ipc.isServer() && toRecord) {
this.commands.push({varName, code}); this.commands.push({varName, code});
@ -81,9 +61,7 @@ class CodeRunner {
} }
evalCode(code, cb, forConsoleOnly = false) { evalCode(code, cb, forConsoleOnly = false) {
if (!cb) { cb = cb || function() {};
cb = function() {};
}
const awaitIdx = code.indexOf('await'); const awaitIdx = code.indexOf('await');
if (awaitIdx > -1) { if (awaitIdx > -1) {
if (awaitIdx < 2) { if (awaitIdx < 2) {
@ -109,27 +87,6 @@ class CodeRunner {
cb(null, result); 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; module.exports = CodeRunner;

View File

@ -146,7 +146,7 @@ class ENS extends React.Component {
</FormGroup> </FormGroup>
</Form> </Form>
<h3>Register subdomain for eth</h3> <h3>Register subdomain</h3>
<Form inline onKeyDown={(e) => this.checkEnter(e, this.registerSubDomain)}> <Form inline onKeyDown={(e) => this.checkEnter(e, this.registerSubDomain)}>
<FormGroup> <FormGroup>
{this.state.responseRegister && {this.state.responseRegister &&