Make console a module
This commit is contained in:
parent
234d2d39a1
commit
e0f73c7d22
|
@ -55,7 +55,6 @@ class EmbarkController {
|
||||||
let self = this;
|
let self = this;
|
||||||
self.context = options.context || [constants.contexts.run, constants.contexts.build];
|
self.context = options.context || [constants.contexts.run, constants.contexts.build];
|
||||||
let Dashboard = require('./dashboard/dashboard.js');
|
let Dashboard = require('./dashboard/dashboard.js');
|
||||||
let REPL = require('./dashboard/repl.js');
|
|
||||||
|
|
||||||
let webServerConfig = {
|
let webServerConfig = {
|
||||||
enabled: options.runWebserver
|
enabled: options.runWebserver
|
||||||
|
@ -93,15 +92,6 @@ class EmbarkController {
|
||||||
async.parallel([
|
async.parallel([
|
||||||
function startDashboard(callback) {
|
function startDashboard(callback) {
|
||||||
if (!options.useDashboard) {
|
if (!options.useDashboard) {
|
||||||
new REPL({
|
|
||||||
env: engine.env,
|
|
||||||
plugins: engine.plugins,
|
|
||||||
version: engine.version,
|
|
||||||
events: engine.events,
|
|
||||||
logger: engine.logger,
|
|
||||||
ipc: engine.ipc,
|
|
||||||
config: engine.config
|
|
||||||
}).startConsole();
|
|
||||||
return callback();
|
return callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,9 +100,7 @@ class EmbarkController {
|
||||||
logger: engine.logger,
|
logger: engine.logger,
|
||||||
plugins: engine.plugins,
|
plugins: engine.plugins,
|
||||||
version: self.version,
|
version: self.version,
|
||||||
env: engine.env,
|
env: engine.env
|
||||||
ipc: engine.ipc,
|
|
||||||
config: engine.config
|
|
||||||
});
|
});
|
||||||
dashboard.start(function () {
|
dashboard.start(function () {
|
||||||
engine.logger.info(__('dashboard start'));
|
engine.logger.info(__('dashboard start'));
|
||||||
|
@ -135,6 +123,7 @@ class EmbarkController {
|
||||||
engine.startService("storage");
|
engine.startService("storage");
|
||||||
engine.startService("codeGenerator");
|
engine.startService("codeGenerator");
|
||||||
engine.startService("namingSystem");
|
engine.startService("namingSystem");
|
||||||
|
engine.startService("console");
|
||||||
|
|
||||||
engine.events.on('check:backOnline:Ethereum', function () {
|
engine.events.on('check:backOnline:Ethereum', function () {
|
||||||
engine.logger.info(__('Ethereum node detected') + '..');
|
engine.logger.info(__('Ethereum node detected') + '..');
|
||||||
|
@ -262,16 +251,6 @@ 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();
|
||||||
|
@ -292,11 +271,13 @@ class EmbarkController {
|
||||||
engine.startService("codeGenerator");
|
engine.startService("codeGenerator");
|
||||||
engine.startService("webServer");
|
engine.startService("webServer");
|
||||||
engine.startService("namingSystem");
|
engine.startService("namingSystem");
|
||||||
|
engine.startService("console");
|
||||||
|
|
||||||
return callback();
|
return callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
engine.startService("codeRunner");
|
engine.startService("codeRunner");
|
||||||
|
engine.startService("console");
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -345,7 +326,7 @@ class EmbarkController {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function startREPL(callback) {
|
function startREPL(callback) {
|
||||||
repl.start(callback);
|
new REPL({events: engine.events, env: engine.env}).start(callback);
|
||||||
}
|
}
|
||||||
], function (err, _result) {
|
], function (err, _result) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|
|
@ -2,7 +2,6 @@ let async = require('async');
|
||||||
let windowSize = require('window-size');
|
let windowSize = require('window-size');
|
||||||
|
|
||||||
let Monitor = require('./monitor.js');
|
let Monitor = require('./monitor.js');
|
||||||
let Console = require('./console.js');
|
|
||||||
|
|
||||||
class Dashboard {
|
class Dashboard {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
|
@ -11,8 +10,6 @@ class Dashboard {
|
||||||
this.plugins = options.plugins;
|
this.plugins = options.plugins;
|
||||||
this.version = options.version;
|
this.version = options.version;
|
||||||
this.env = options.env;
|
this.env = options.env;
|
||||||
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));
|
||||||
|
@ -26,45 +23,23 @@ class Dashboard {
|
||||||
}
|
}
|
||||||
|
|
||||||
start(done) {
|
start(done) {
|
||||||
let console, monitor;
|
let monitor;
|
||||||
let self = this;
|
|
||||||
|
|
||||||
async.waterfall([
|
monitor = new Monitor({env: this.env, events: this.events});
|
||||||
function startConsole(callback) {
|
this.logger.logFunction = monitor.logEntry;
|
||||||
console = new Console({
|
|
||||||
events: self.events,
|
|
||||||
plugins: self.plugins,
|
|
||||||
version: self.version,
|
|
||||||
ipc: self.ipc,
|
|
||||||
logger: self.logger,
|
|
||||||
config: self.config
|
|
||||||
});
|
|
||||||
callback();
|
|
||||||
},
|
|
||||||
function startMonitor(callback) {
|
|
||||||
monitor = new Monitor({env: self.env, console: console, events: self.events});
|
|
||||||
self.logger.logFunction = monitor.logEntry;
|
|
||||||
|
|
||||||
self.events.on('contractsState', monitor.setContracts);
|
this.events.on('contractsState', monitor.setContracts);
|
||||||
self.events.on('status', monitor.setStatus.bind(monitor));
|
this.events.on('status', monitor.setStatus.bind(monitor));
|
||||||
self.events.on('servicesState', monitor.availableServices.bind(monitor));
|
this.events.on('servicesState', monitor.availableServices.bind(monitor));
|
||||||
|
|
||||||
self.events.setCommandHandler("console:command", monitor.executeCmd.bind(monitor));
|
this.events.setCommandHandler("console:command", monitor.executeCmd.bind(monitor));
|
||||||
|
|
||||||
self.logger.info('========================'.bold.green);
|
this.logger.info('========================'.bold.green);
|
||||||
self.logger.info((__('Welcome to Embark') + ' ' + self.version).yellow.bold);
|
this.logger.info((__('Welcome to Embark') + ' ' + this.version).yellow.bold);
|
||||||
self.logger.info('========================'.bold.green);
|
this.logger.info('========================'.bold.green);
|
||||||
|
|
||||||
// TODO: do this after monitor is rendered
|
done();
|
||||||
callback();
|
|
||||||
}
|
|
||||||
], function () {
|
|
||||||
self.console = console;
|
|
||||||
self.monitor = monitor;
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Dashboard;
|
module.exports = Dashboard;
|
||||||
|
|
|
@ -366,11 +366,10 @@ class Monitor {
|
||||||
}
|
}
|
||||||
|
|
||||||
executeCmd(cmd, cb) {
|
executeCmd(cmd, cb) {
|
||||||
const self = this;
|
this.logText.log('console> '.bold.green + cmd);
|
||||||
self.logText.log('console> '.bold.green + cmd);
|
this.events.request('console:executeCmd', cmd, (err, result) => {
|
||||||
self.console.executeCmd(cmd, function (err, result) {
|
|
||||||
let message = err || result;
|
let message = err || result;
|
||||||
self.logText.log(message);
|
this.logText.log(message);
|
||||||
if (cb) {
|
if (cb) {
|
||||||
cb(message);
|
cb(message);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,32 +1,13 @@
|
||||||
const repl = require("repl");
|
const repl = require("repl");
|
||||||
const util = require("util");
|
const util = require("util");
|
||||||
|
|
||||||
const Console = require('./console.js');
|
|
||||||
|
|
||||||
class REPL {
|
class REPL {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
this.logger = options.logger;
|
|
||||||
this.env = options.env;
|
|
||||||
this.plugins = options.plugins;
|
|
||||||
this.events = options.events;
|
this.events = options.events;
|
||||||
this.version = options.version;
|
this.env = options.env
|
||||||
this.ipc = options.ipc;
|
|
||||||
this.config = options.config;
|
|
||||||
}
|
|
||||||
|
|
||||||
startConsole(){
|
|
||||||
this.console = new Console({
|
|
||||||
events: this.events,
|
|
||||||
plugins: this.plugins,
|
|
||||||
version: this.version,
|
|
||||||
ipc: this.ipc,
|
|
||||||
logger: this.logger,
|
|
||||||
config: this.config
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
enhancedEval(cmd, context, filename, callback) {
|
enhancedEval(cmd, context, filename, callback) {
|
||||||
this.console.executeCmd(cmd.trim(), callback);
|
this.events.request('console:executeCmd', cmd.trim(), callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
enhancedWriter(output) {
|
enhancedWriter(output) {
|
||||||
|
@ -38,7 +19,6 @@ class REPL {
|
||||||
}
|
}
|
||||||
|
|
||||||
start(done) {
|
start(done) {
|
||||||
this.startConsole();
|
|
||||||
this.replServer = repl.start({
|
this.replServer = repl.start({
|
||||||
prompt: "Embark (" + this.env + ") > ",
|
prompt: "Embark (" + this.env + ") > ",
|
||||||
useGlobal: true,
|
useGlobal: true,
|
||||||
|
|
|
@ -60,6 +60,7 @@ class Engine {
|
||||||
"fileWatcher": this.fileWatchService,
|
"fileWatcher": this.fileWatchService,
|
||||||
"webServer": this.webServerService,
|
"webServer": this.webServerService,
|
||||||
"namingSystem": this.namingSystem,
|
"namingSystem": this.namingSystem,
|
||||||
|
"console": this.console,
|
||||||
"web3": this.web3Service,
|
"web3": this.web3Service,
|
||||||
"libraryManager": this.libraryManagerService,
|
"libraryManager": this.libraryManagerService,
|
||||||
"processManager": this.processManagerService,
|
"processManager": this.processManagerService,
|
||||||
|
@ -129,6 +130,17 @@ class Engine {
|
||||||
this.registerModule('ens');
|
this.registerModule('ens');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console(_options) {
|
||||||
|
this.registerModule('console', {
|
||||||
|
events: this.events,
|
||||||
|
plugins: this.plugins,
|
||||||
|
version: this.version,
|
||||||
|
ipc: this.ipc,
|
||||||
|
logger: this.logger,
|
||||||
|
config: this.config
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
codeRunnerService(_options) {
|
codeRunnerService(_options) {
|
||||||
const CodeRunner = require('./modules/coderunner/codeRunner.js');
|
const CodeRunner = require('./modules/coderunner/codeRunner.js');
|
||||||
this.codeRunner = new CodeRunner({
|
this.codeRunner = new CodeRunner({
|
||||||
|
|
|
@ -13,7 +13,6 @@ class CodeRunner {
|
||||||
this.IpcClientListen();
|
this.IpcClientListen();
|
||||||
this.registerEvents();
|
this.registerEvents();
|
||||||
this.registerCommands();
|
this.registerCommands();
|
||||||
this.events.emit('runcode:ready');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
registerIpcEvents() {
|
registerIpcEvents() {
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
let utils = require('../../lib/utils/utils.js');
|
let utils = require('../../utils/utils');
|
||||||
const EmbarkJS = require('embarkjs');
|
const EmbarkJS = require('embarkjs');
|
||||||
const IpfsApi = require('ipfs-api');
|
const IpfsApi = require('ipfs-api');
|
||||||
const Web3 = require('web3');
|
const Web3 = require('web3');
|
||||||
|
|
||||||
class Console {
|
class Console {
|
||||||
constructor(options) {
|
constructor(_embark, options) {
|
||||||
this.events = options.events;
|
this.events = options.events;
|
||||||
this.plugins = options.plugins;
|
this.plugins = options.plugins;
|
||||||
this.version = options.version;
|
this.version = options.version;
|
||||||
|
@ -14,7 +15,7 @@ class Console {
|
||||||
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.events.setCommandHandler("console:executeCmd", this.executeCmd.bind(this));
|
||||||
this.registerEmbarkJs();
|
this.registerEmbarkJs();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,11 +73,9 @@ class Console {
|
||||||
}
|
}
|
||||||
|
|
||||||
registerEmbarkJs() {
|
registerEmbarkJs() {
|
||||||
this.events.on('runcode:ready', () => {
|
this.events.emit('runcode:register', 'IpfsApi', IpfsApi, false);
|
||||||
this.events.emit('runcode:register', 'IpfsApi', IpfsApi, false);
|
this.events.emit('runcode:register', 'Web3', Web3, false);
|
||||||
this.events.emit('runcode:register', 'Web3', Web3, false);
|
this.events.emit('runcode:register', 'EmbarkJS', EmbarkJS, false);
|
||||||
this.events.emit('runcode:register', 'EmbarkJS', EmbarkJS, false);
|
|
||||||
});
|
|
||||||
|
|
||||||
this.events.on('code-generator-ready', () => {
|
this.events.on('code-generator-ready', () => {
|
||||||
if (this.ipc.connected) {
|
if (this.ipc.connected) {
|
|
@ -1,5 +1,5 @@
|
||||||
/*globals describe, it*/
|
/*globals describe, it*/
|
||||||
let Console = require('../cmd/dashboard/console.js');
|
let Console = require('../lib/modules/console/');
|
||||||
let Plugins = require('../lib/core/plugins.js');
|
let Plugins = require('../lib/core/plugins.js');
|
||||||
let IPC = require('../lib/core/ipc.js');
|
let IPC = require('../lib/core/ipc.js');
|
||||||
let assert = require('assert');
|
let assert = require('assert');
|
||||||
|
@ -8,8 +8,8 @@ let version = require('../package.json').version;
|
||||||
describe('embark.Console', function() {
|
describe('embark.Console', function() {
|
||||||
let ipc = new IPC({ipcRole: 'none'});
|
let ipc = new IPC({ipcRole: 'none'});
|
||||||
let plugins = new Plugins({plugins: {}});
|
let plugins = new Plugins({plugins: {}});
|
||||||
let events = {on: () => {}}
|
let events = {on: () => {}, setCommandHandler: () => {}, emit: () => {}};
|
||||||
let console = new Console({plugins, version, ipc, events});
|
let console = new Console({}, {plugins, version, ipc, events});
|
||||||
|
|
||||||
describe('#executeCmd', function() {
|
describe('#executeCmd', function() {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue