Replace light monitor by REPL

This commit is contained in:
Anthony Laibe 2018-07-23 13:30:58 +01:00 committed by Iuri Matias
parent b368eb4e04
commit a161e6856c
5 changed files with 204 additions and 225 deletions

View File

@ -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 LightMonitor = require('./light_monitor.js');
let Console = require('./console.js'); let Console = require('./console.js');
class Dashboard { class Dashboard {
@ -12,7 +11,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.light = options.light || false;
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));
@ -39,16 +37,12 @@ class Dashboard {
callback(); callback();
}, },
function startMonitor(callback) { function startMonitor(callback) {
let monitor;
if(self.light) {
monitor = new LightMonitor({env: self.env, console: console, events: self.events});
} else {
monitor = new Monitor({env: self.env, console: console, events: self.events}); monitor = new Monitor({env: self.env, console: console, events: self.events});
self.logger.logFunction = monitor.logEntry;
self.events.on('contractsState', monitor.setContracts); self.events.on('contractsState', monitor.setContracts);
self.events.on('status', monitor.setStatus.bind(monitor)); self.events.on('status', monitor.setStatus.bind(monitor));
self.events.on('servicesState', monitor.availableServices.bind(monitor)); self.events.on('servicesState', monitor.availableServices.bind(monitor));
}
self.logger.logFunction = monitor.logEntry;
self.events.setCommandHandler("console:command", monitor.executeCmd.bind(monitor)); self.events.setCommandHandler("console:command", monitor.executeCmd.bind(monitor));

View File

@ -1,171 +0,0 @@
let blessed = require("neo-blessed");
let CommandHistory = require('./command_history.js');
class LightMonitor {
constructor(_options) {
let options = _options || {};
this.env = options.env;
this.console = options.console;
this.history = new CommandHistory();
this.events = options.events;
this.color = options.color || "green";
this.minimal = options.minimal || false;
this.screen = blessed.screen({
smartCSR: true,
title: options.title || ("Embark " + options.version),
dockBorders: false,
fullUnicode: true,
autoPadding: true
});
this.layoutLog();
this.layoutCmd();
this.screen.key(["C-c"], function () {
process.exit(0);
});
this.logEntry = this.logEntry.bind(this);
this.screen.render();
this.input.focus();
}
logEntry() {
this.logText.log(...arguments);
this.screen.render();
}
layoutLog() {
this.log = blessed.box({
label: __("Logs"),
padding: 1,
width: "100%",
height: "100%",
left: "0%",
top: "0%",
border: {
type: "line"
},
style: {
fg: -1,
border: {
fg: this.color
}
}
});
this.logText = blessed.log({
parent: this.log,
tags: true,
width: "100%-5",
//height: '90%',
scrollable: true,
input: false,
alwaysScroll: true,
scrollbar: {
ch: " ",
inverse: true
},
keys: false,
vi: false,
mouse: true
});
this.screen.append(this.log);
}
layoutCmd() {
this.consoleBox = blessed.box({
label: __('Console'),
tags: true,
padding: 0,
width: '100%',
height: '6%',
left: '0%',
top: '95%',
border: {
type: 'line'
},
style: {
fg: 'black',
border: {
fg: this.color
}
}
});
this.input = blessed.textbox({
parent: this.consoleBox,
name: 'input',
input: true,
keys: false,
top: 0,
left: 1,
height: '50%',
width: '100%-2',
inputOnFocus: true,
style: {
fg: 'green',
bg: 'black',
focus: {
bg: 'black',
fg: 'green'
}
}
});
let self = this;
this.input.key(["C-c"], function () {
self.events.emit('exit');
process.exit(0);
});
this.input.key(["C-w"], function () {
self.input.clearValue();
self.input.focus();
});
this.input.key(["up"], function () {
let cmd = self.history.getPreviousCommand();
self.input.setValue(cmd);
self.input.focus();
});
this.input.key(["down"], function () {
let cmd = self.history.getNextCommand();
self.input.setValue(cmd);
self.input.focus();
});
this.input.on('submit', this.submitCmd.bind(this));
this.screen.append(this.consoleBox);
}
submitCmd(cmd) {
if (cmd !== '') {
this.history.addCommand(cmd);
this.executeCmd(cmd);
}
this.input.clearValue();
this.input.focus();
}
executeCmd(cmd, cb) {
const self = this;
self.logText.log('console> '.bold.green + cmd);
self.console.executeCmd(cmd, function (result) {
self.logText.log(result);
if (cb) {
cb(result);
}
});
}
}
module.exports = LightMonitor;

View File

@ -1,16 +1,42 @@
let blessed = require("neo-blessed"); let blessed = require("neo-blessed");
let LightMonitor = require('./light_monitor'); let CommandHistory = require('./command_history.js');
class Monitor extends LightMonitor { class Monitor {
constructor(_options) { constructor(_options) {
super(_options); let options = _options || {};
this.env = options.env;
this.console = options.console;
this.history = new CommandHistory();
this.events = options.events;
this.color = options.color || "green";
this.minimal = options.minimal || false;
this.screen = blessed.screen({
smartCSR: true,
title: options.title || ("Embark " + options.version),
dockBorders: false,
fullUnicode: true,
autoPadding: true
});
this.layoutLog();
this.layoutStatus(); this.layoutStatus();
this.layoutModules(); this.layoutModules();
this.layoutCmd();
this.screen.key(["C-c"], function () {
process.exit(0);
});
this.logEntry = this.logEntry.bind(this);
this.setContracts = this.setContracts.bind(this); this.setContracts = this.setContracts.bind(this);
this.availableServices = this.availableServices.bind(this); this.availableServices = this.availableServices.bind(this);
this.status.setContent(this.env.green); this.status.setContent(this.env.green);
this.screen.render();
this.input.focus();
} }
availableServices(_services) { availableServices(_services) {
@ -51,6 +77,11 @@ class Monitor extends LightMonitor {
this.screen.render(); this.screen.render();
} }
logEntry() {
this.logText.log(...arguments);
this.screen.render();
}
layoutLog() { layoutLog() {
this.log = blessed.box({ this.log = blessed.box({
label: __("Logs"), label: __("Logs"),
@ -133,7 +164,49 @@ class Monitor extends LightMonitor {
this.screen.append(this.modules); this.screen.append(this.modules);
} }
layoutAssets() {
this.assets = blessed.box({
label: __("Asset Pipeline"),
tags: true,
padding: 1,
width: "50%",
height: "55%",
left: "50%",
top: "42%",
border: {
type: "line"
},
style: {
fg: -1,
border: {
fg: this.color
}
}
});
this.assetTable = blessed.table({
parent: this.assets,
height: "100%",
width: "100%-5",
align: "left",
pad: 1,
scrollable: true,
alwaysScroll: true,
scrollbar: {
ch: " ",
inverse: true
},
keys: false,
vi: false,
mouse: true,
data: [["Name", "Size"]]
});
this.screen.append(this.assets);
}
layoutStatus() { layoutStatus() {
this.wrapper = blessed.layout({ this.wrapper = blessed.layout({
width: "25%", width: "25%",
height: "42%", height: "42%",
@ -214,6 +287,95 @@ class Monitor extends LightMonitor {
this.screen.append(this.wrapper); this.screen.append(this.wrapper);
} }
layoutCmd() {
this.consoleBox = blessed.box({
label: __('Console'),
tags: true,
padding: 0,
width: '100%',
height: '6%',
left: '0%',
top: '95%',
border: {
type: 'line'
},
style: {
fg: 'black',
border: {
fg: this.color
}
}
});
this.input = blessed.textbox({
parent: this.consoleBox,
name: 'input',
input: true,
keys: false,
top: 0,
left: 1,
height: '50%',
width: '100%-2',
inputOnFocus: true,
style: {
fg: 'green',
bg: 'black',
focus: {
bg: 'black',
fg: 'green'
}
}
});
let self = this;
this.input.key(["C-c"], function () {
self.events.emit('exit');
process.exit(0);
});
this.input.key(["C-w"], function () {
self.input.clearValue();
self.input.focus();
});
this.input.key(["up"], function () {
let cmd = self.history.getPreviousCommand();
self.input.setValue(cmd);
self.input.focus();
});
this.input.key(["down"], function () {
let cmd = self.history.getNextCommand();
self.input.setValue(cmd);
self.input.focus();
});
this.input.on('submit', this.submitCmd.bind(this));
this.screen.append(this.consoleBox);
}
submitCmd(cmd) {
if (cmd !== '') {
this.history.addCommand(cmd);
this.executeCmd(cmd);
}
this.input.clearValue();
this.input.focus();
}
executeCmd(cmd, cb) {
const self = this;
self.logText.log('console> '.bold.green + cmd);
self.console.executeCmd(cmd, function (result) {
self.logText.log(result);
if (cb) {
cb(result);
}
});
}
} }
module.exports = Monitor; module.exports = Monitor;

17
lib/dashboard/repl.js Normal file
View File

@ -0,0 +1,17 @@
const repl = require("repl");
class REPL {
constructor(options) {
this.env = options.env;
}
start(done) {
repl.start({
prompt: "Embark (" + this.env + ") > "
});
done();
}
}
module.exports = REPL;

View File

@ -237,7 +237,7 @@ class Embark {
console(options) { console(options) {
this.context = options.context || [constants.contexts.run, constants.contexts.console]; this.context = options.context || [constants.contexts.run, constants.contexts.console];
const Dashboard = require('./dashboard/dashboard.js'); const REPL = require('./dashboard/repl.js');
const Engine = require('./core/engine.js'); const Engine = require('./core/engine.js');
const engine = new Engine({ const engine = new Engine({
env: options.env, env: options.env,
@ -247,58 +247,35 @@ class Embark {
embarkConfig: options.embarkConfig || 'embark.json', embarkConfig: options.embarkConfig || 'embark.json',
logFile: options.logFile, logFile: options.logFile,
logLevel: options.logLevel, logLevel: options.logLevel,
context: this.context, context: this.context
useDashboard: true
}); });
engine.init(); engine.init();
async.parallel([ async.waterfall([
function startDashboard(callback) { function startServices(callback) {
let dashboard = new Dashboard({
events: engine.events,
logger: engine.logger,
plugins: engine.plugins,
version: engine.version,
light: true,
env: engine.env
});
dashboard.start(function () {
engine.logger.info(__('dashboard start'));
callback();
});
},
function (callback) {
let pluginList = engine.plugins.listPlugins(); let pluginList = engine.plugins.listPlugins();
if (pluginList.length > 0) { if (pluginList.length > 0) {
engine.logger.info(__("loaded plugins") + ": " + pluginList.join(", ")); engine.logger.info(__("loaded plugins") + ": " + pluginList.join(", "));
} }
engine.startService("serviceMonitor");
engine.startService("libraryManager"); engine.startService("libraryManager");
engine.startService("codeRunner"); engine.startService("codeRunner");
engine.startService("web3"); engine.startService("web3");
engine.startService("pipeline"); engine.startService("deployment", {onlyCompile: true});
engine.startService("deployment");
engine.startService("storage"); engine.startService("storage");
engine.startService("codeGenerator");
engine.events.on('check:backOnline:Ethereum', function () {
engine.logger.info(__('Ethereum node detected') + '..');
engine.config.reloadConfig();
engine.events.request('deploy:contracts', function (err) {
if (err) {
return;
}
engine.logger.info(__('Deployment Done'));
});
});
engine.events.on('outputDone', function () {
engine.logger.info((__("Looking for documentation? You can find it at") + " ").cyan + "http://embark.status.im/docs/".green.underline + ".".cyan);
engine.logger.info(__("Ready").underline);
engine.events.emit("status", __("Ready").green);
});
callback(); callback();
},
function deploy(callback) {
engine.events.request('deploy:contracts', function (err) {
engine.logger.info("Finished deploying".underline);
callback(err);
});
},
function startREPL(callback) {
let repl = new REPL({env: engine.env});
repl.start(function () {
callback();
});
} }
], function (err, _result) { ], function (err, _result) {
if (err) { if (err) {