From eb2172a0f5016e3c18a84e3da391c1898b245a6f Mon Sep 17 00:00:00 2001 From: Anthony Laibe Date: Mon, 23 Jul 2018 09:34:21 +0100 Subject: [PATCH 01/16] Adding Console Command --- lib/cmd.js | 27 +++++++++++++++++++++++++++ lib/index.js | 4 ++++ 2 files changed, 31 insertions(+) diff --git a/lib/cmd.js b/lib/cmd.js index a0c33099..52a59bc0 100644 --- a/lib/cmd.js +++ b/lib/cmd.js @@ -13,6 +13,7 @@ class Cmd { this.demo(); this.build(); this.run(); + this.console(); this.blockchain(); this.simulator(); this.test(); @@ -138,6 +139,32 @@ class Cmd { }); } + console() { + program + .command('console [environment]') + .option('-p, --port [port]', __('port to run the dev webserver (default: %s)', '8000')) + .option('-c, --client [client]', __('Use a specific ethereum client or simulator (supported: %s)', 'geth, testrpc')) + .option('--no-color', __('no colors in case it\'s needed for compatbility purposes')) + .option('--logfile [logfile]', __('filename to output logs (default: %s)', 'none')) + .option('--loglevel [loglevel]', __('level of logging to display') + ' ["error", "warn", "info", "debug", "trace"]', /^(error|warn|info|debug|trace)$/i, 'debug') + .option('--locale [locale]', __('language to use (default: en)')) + .description(__('deploy, build dapp at ') + 'dist/ (default: development)' + __(' and display the console')) + .action(function (env, options) { + i18n.setOrDetectLocale(options.locale); + embark.console({ + env: env || 'development', + serverPort: options.port, + serverHost: options.host, + client: options.client || 'geth', + locale: options.locale, + runWebserver: !options.noserver, + useDashboard: !options.nodashboard, + logFile: options.logfile, + logLevel: options.loglevel + }); + }); + } + blockchain() { program .command('blockchain [environment]') diff --git a/lib/index.js b/lib/index.js index 860cd3dd..2b2582f5 100644 --- a/lib/index.js +++ b/lib/index.js @@ -237,6 +237,10 @@ class Embark { }); } + console(options) { + + } + graph(options) { this.context = options.context || [constants.contexts.graph]; options.onlyCompile = true; From 0aa151ee38af26e4408995bf130fba736f8317d6 Mon Sep 17 00:00:00 2001 From: Anthony Laibe Date: Mon, 23 Jul 2018 10:36:53 +0100 Subject: [PATCH 02/16] Adding light monitor --- lib/cmd.js | 2 - lib/constants.json | 1 + lib/dashboard/dashboard.js | 16 ++- lib/dashboard/light_monitor.js | 171 +++++++++++++++++++++++++++++++++ lib/dashboard/monitor.js | 4 +- lib/index.js | 90 +++++++++++++++-- 6 files changed, 266 insertions(+), 18 deletions(-) create mode 100644 lib/dashboard/light_monitor.js diff --git a/lib/cmd.js b/lib/cmd.js index 52a59bc0..e151e3f7 100644 --- a/lib/cmd.js +++ b/lib/cmd.js @@ -157,8 +157,6 @@ class Cmd { serverHost: options.host, client: options.client || 'geth', locale: options.locale, - runWebserver: !options.noserver, - useDashboard: !options.nodashboard, logFile: options.logfile, logLevel: options.loglevel }); diff --git a/lib/constants.json b/lib/constants.json index caf92da9..31b77984 100644 --- a/lib/constants.json +++ b/lib/constants.json @@ -7,6 +7,7 @@ "run": "run", "upload": "upload", "build": "build", + "console": "console", "graph": "graph", "test": "test", "reset": "reset", diff --git a/lib/dashboard/dashboard.js b/lib/dashboard/dashboard.js index 0bf7a7a5..b402c064 100644 --- a/lib/dashboard/dashboard.js +++ b/lib/dashboard/dashboard.js @@ -2,6 +2,7 @@ let async = require('async'); let windowSize = require('window-size'); let Monitor = require('./monitor.js'); +let LightMonitor = require('./light_monitor.js'); let Console = require('./console.js'); class Dashboard { @@ -11,6 +12,7 @@ class Dashboard { this.plugins = options.plugins; this.version = options.version; this.env = options.env; + this.light = options.light || false; this.events.on('firstDeploymentDone', this.checkWindowSize.bind(this)); this.events.on('outputDone', this.checkWindowSize.bind(this)); @@ -37,13 +39,17 @@ class Dashboard { callback(); }, function startMonitor(callback) { - monitor = new Monitor({env: self.env, console: console, events: self.events}); + 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}); + self.events.on('contractsState', monitor.setContracts); + self.events.on('status', monitor.setStatus.bind(monitor)); + self.events.on('servicesState', monitor.availableServices.bind(monitor)); + } self.logger.logFunction = monitor.logEntry; - self.events.on('contractsState', monitor.setContracts); - self.events.on('status', monitor.setStatus.bind(monitor)); - self.events.on('servicesState', monitor.availableServices.bind(monitor)); - self.events.setCommandHandler("console:command", monitor.executeCmd.bind(monitor)); self.logger.info('========================'.bold.green); diff --git a/lib/dashboard/light_monitor.js b/lib/dashboard/light_monitor.js new file mode 100644 index 00000000..3265b19c --- /dev/null +++ b/lib/dashboard/light_monitor.js @@ -0,0 +1,171 @@ +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; diff --git a/lib/dashboard/monitor.js b/lib/dashboard/monitor.js index 9965c9f6..c437599d 100644 --- a/lib/dashboard/monitor.js +++ b/lib/dashboard/monitor.js @@ -1,7 +1,7 @@ let blessed = require("neo-blessed"); let CommandHistory = require('./command_history.js'); -class Dashboard { +class Monitor { constructor(_options) { let options = _options || {}; this.env = options.env; @@ -378,4 +378,4 @@ class Dashboard { } -module.exports = Dashboard; +module.exports = Monitor; diff --git a/lib/index.js b/lib/index.js index 2b2582f5..c27f7d14 100644 --- a/lib/index.js +++ b/lib/index.js @@ -65,16 +65,16 @@ class Embark { self.context = options.context || [constants.contexts.run, constants.contexts.build]; let Dashboard = require('./dashboard/dashboard.js'); - let webServerConfig = { - enabled: options.runWebserver - }; + let webServerConfig = { + enabled: options.runWebserver + }; - if (options.serverHost) { - webServerConfig.host = options.serverHost; - } - if (options.serverPort) { - webServerConfig.port = options.serverPort; - } + if (options.serverHost) { + webServerConfig.host = options.serverHost; + } + if (options.serverPort) { + webServerConfig.port = options.serverPort; + } const Engine = require('./core/engine.js'); const engine = new Engine({ @@ -204,6 +204,7 @@ class Embark { engine.startService("deployment", {onlyCompile: options.onlyCompile}); engine.startService("storage"); engine.startService("codeGenerator"); + callback(); }, function deploy(callback) { @@ -238,7 +239,78 @@ class Embark { } console(options) { + this.context = options.context || [constants.contexts.run, constants.contexts.console]; + const Dashboard = require('./dashboard/dashboard.js'); + const Engine = require('./core/engine.js'); + const engine = new Engine({ + env: options.env, + client: options.client, + locale: options.locale, + version: this.version, + embarkConfig: options.embarkConfig || 'embark.json', + logFile: options.logFile, + logLevel: options.logLevel, + context: this.context, + useDashboard: true + }); + engine.init(); + async.parallel([ + function startDashboard(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(); + if (pluginList.length > 0) { + engine.logger.info(__("loaded plugins") + ": " + pluginList.join(", ")); + } + engine.startService("serviceMonitor"); + engine.startService("libraryManager"); + engine.startService("codeRunner"); + engine.startService("web3"); + engine.startService("pipeline"); + engine.startService("deployment"); + 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(); + } + ], function (err, _result) { + if (err) { + engine.logger.error(err.message); + engine.logger.info(err.stack); + } else { + engine.events.emit('firstDeploymentDone'); + } + }); } graph(options) { From 87de044c065cad763ea1ade49cb9200836dc8dbd Mon Sep 17 00:00:00 2001 From: Anthony Laibe Date: Mon, 23 Jul 2018 11:05:07 +0100 Subject: [PATCH 03/16] Remove not used options --- lib/cmd.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/cmd.js b/lib/cmd.js index e151e3f7..11691a90 100644 --- a/lib/cmd.js +++ b/lib/cmd.js @@ -142,7 +142,6 @@ class Cmd { console() { program .command('console [environment]') - .option('-p, --port [port]', __('port to run the dev webserver (default: %s)', '8000')) .option('-c, --client [client]', __('Use a specific ethereum client or simulator (supported: %s)', 'geth, testrpc')) .option('--no-color', __('no colors in case it\'s needed for compatbility purposes')) .option('--logfile [logfile]', __('filename to output logs (default: %s)', 'none')) @@ -153,8 +152,6 @@ class Cmd { i18n.setOrDetectLocale(options.locale); embark.console({ env: env || 'development', - serverPort: options.port, - serverHost: options.host, client: options.client || 'geth', locale: options.locale, logFile: options.logfile, From c283e8a29f13e300369751ad600868faa3aebe5b Mon Sep 17 00:00:00 2001 From: Anthony Laibe Date: Mon, 23 Jul 2018 11:19:44 +0100 Subject: [PATCH 04/16] Reuse Light Monitor --- lib/dashboard/monitor.js | 168 +-------------------------------------- 1 file changed, 3 insertions(+), 165 deletions(-) diff --git a/lib/dashboard/monitor.js b/lib/dashboard/monitor.js index c437599d..5ba287a8 100644 --- a/lib/dashboard/monitor.js +++ b/lib/dashboard/monitor.js @@ -1,42 +1,16 @@ let blessed = require("neo-blessed"); -let CommandHistory = require('./command_history.js'); +let LightMonitor = require('./light_monitor'); -class Monitor { +class Monitor extends LightMonitor { constructor(_options) { - let options = _options || {}; - this.env = options.env; - this.console = options.console; - this.history = new CommandHistory(); - this.events = options.events; + super(_options); - 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.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.availableServices = this.availableServices.bind(this); - this.status.setContent(this.env.green); - - this.screen.render(); - this.input.focus(); } availableServices(_services) { @@ -77,11 +51,6 @@ class Monitor { this.screen.render(); } - logEntry() { - this.logText.log(...arguments); - this.screen.render(); - } - layoutLog() { this.log = blessed.box({ label: __("Logs"), @@ -164,49 +133,7 @@ class Monitor { 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() { - this.wrapper = blessed.layout({ width: "25%", height: "42%", @@ -287,95 +214,6 @@ class Monitor { 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; From eadea087aef660e56c18cec9878a855533c8bed2 Mon Sep 17 00:00:00 2001 From: Anthony Laibe Date: Mon, 23 Jul 2018 13:30:58 +0100 Subject: [PATCH 05/16] Replace light monitor by REPL --- lib/dashboard/dashboard.js | 16 +-- lib/dashboard/light_monitor.js | 171 --------------------------------- lib/dashboard/monitor.js | 168 +++++++++++++++++++++++++++++++- lib/dashboard/repl.js | 17 ++++ lib/index.js | 57 ++++------- 5 files changed, 204 insertions(+), 225 deletions(-) delete mode 100644 lib/dashboard/light_monitor.js create mode 100644 lib/dashboard/repl.js diff --git a/lib/dashboard/dashboard.js b/lib/dashboard/dashboard.js index b402c064..0bf7a7a5 100644 --- a/lib/dashboard/dashboard.js +++ b/lib/dashboard/dashboard.js @@ -2,7 +2,6 @@ let async = require('async'); let windowSize = require('window-size'); let Monitor = require('./monitor.js'); -let LightMonitor = require('./light_monitor.js'); let Console = require('./console.js'); class Dashboard { @@ -12,7 +11,6 @@ class Dashboard { this.plugins = options.plugins; this.version = options.version; this.env = options.env; - this.light = options.light || false; this.events.on('firstDeploymentDone', this.checkWindowSize.bind(this)); this.events.on('outputDone', this.checkWindowSize.bind(this)); @@ -39,17 +37,13 @@ class Dashboard { 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}); - self.events.on('contractsState', monitor.setContracts); - self.events.on('status', monitor.setStatus.bind(monitor)); - self.events.on('servicesState', monitor.availableServices.bind(monitor)); - } + 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('status', monitor.setStatus.bind(monitor)); + self.events.on('servicesState', monitor.availableServices.bind(monitor)); + self.events.setCommandHandler("console:command", monitor.executeCmd.bind(monitor)); self.logger.info('========================'.bold.green); diff --git a/lib/dashboard/light_monitor.js b/lib/dashboard/light_monitor.js deleted file mode 100644 index 3265b19c..00000000 --- a/lib/dashboard/light_monitor.js +++ /dev/null @@ -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; diff --git a/lib/dashboard/monitor.js b/lib/dashboard/monitor.js index 5ba287a8..c437599d 100644 --- a/lib/dashboard/monitor.js +++ b/lib/dashboard/monitor.js @@ -1,16 +1,42 @@ let blessed = require("neo-blessed"); -let LightMonitor = require('./light_monitor'); +let CommandHistory = require('./command_history.js'); -class Monitor extends LightMonitor { +class Monitor { 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.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.availableServices = this.availableServices.bind(this); + this.status.setContent(this.env.green); + + this.screen.render(); + this.input.focus(); } availableServices(_services) { @@ -51,6 +77,11 @@ class Monitor extends LightMonitor { this.screen.render(); } + logEntry() { + this.logText.log(...arguments); + this.screen.render(); + } + layoutLog() { this.log = blessed.box({ label: __("Logs"), @@ -133,7 +164,49 @@ class Monitor extends LightMonitor { 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() { + this.wrapper = blessed.layout({ width: "25%", height: "42%", @@ -214,6 +287,95 @@ class Monitor extends LightMonitor { 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; diff --git a/lib/dashboard/repl.js b/lib/dashboard/repl.js new file mode 100644 index 00000000..44848db4 --- /dev/null +++ b/lib/dashboard/repl.js @@ -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; diff --git a/lib/index.js b/lib/index.js index c27f7d14..1efedbbe 100644 --- a/lib/index.js +++ b/lib/index.js @@ -240,7 +240,7 @@ class Embark { console(options) { 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 = new Engine({ env: options.env, @@ -250,58 +250,35 @@ class Embark { embarkConfig: options.embarkConfig || 'embark.json', logFile: options.logFile, logLevel: options.logLevel, - context: this.context, - useDashboard: true + context: this.context }); engine.init(); - async.parallel([ - function startDashboard(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) { + async.waterfall([ + function startServices(callback) { let pluginList = engine.plugins.listPlugins(); if (pluginList.length > 0) { engine.logger.info(__("loaded plugins") + ": " + pluginList.join(", ")); } - engine.startService("serviceMonitor"); engine.startService("libraryManager"); engine.startService("codeRunner"); engine.startService("web3"); - engine.startService("pipeline"); - engine.startService("deployment"); + engine.startService("deployment", {onlyCompile: true}); 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(); + }, + 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) { if (err) { From ce2618a1089b8ea176155c7ad96d2baa5895efb3 Mon Sep 17 00:00:00 2001 From: Anthony Laibe Date: Mon, 23 Jul 2018 13:36:15 +0100 Subject: [PATCH 06/16] Update console command options --- lib/cmd.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/cmd.js b/lib/cmd.js index 11691a90..63276131 100644 --- a/lib/cmd.js +++ b/lib/cmd.js @@ -143,11 +143,10 @@ class Cmd { program .command('console [environment]') .option('-c, --client [client]', __('Use a specific ethereum client or simulator (supported: %s)', 'geth, testrpc')) - .option('--no-color', __('no colors in case it\'s needed for compatbility purposes')) .option('--logfile [logfile]', __('filename to output logs (default: %s)', 'none')) .option('--loglevel [loglevel]', __('level of logging to display') + ' ["error", "warn", "info", "debug", "trace"]', /^(error|warn|info|debug|trace)$/i, 'debug') .option('--locale [locale]', __('language to use (default: en)')) - .description(__('deploy, build dapp at ') + 'dist/ (default: development)' + __(' and display the console')) + .description(__('Start the Embark console')) .action(function (env, options) { i18n.setOrDetectLocale(options.locale); embark.console({ From 57f06b2f19fe7a61f67e04a1fe0a62ca20e788fc Mon Sep 17 00:00:00 2001 From: Anthony Laibe Date: Mon, 23 Jul 2018 13:41:13 +0100 Subject: [PATCH 07/16] Add on exit --- lib/dashboard/repl.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/dashboard/repl.js b/lib/dashboard/repl.js index 44848db4..f416bc94 100644 --- a/lib/dashboard/repl.js +++ b/lib/dashboard/repl.js @@ -6,10 +6,14 @@ class REPL { } start(done) { - repl.start({ + let replServer = repl.start({ prompt: "Embark (" + this.env + ") > " }); + replServer.on('exit', () => { + process.exit(); + }); + done(); } } From 08a3879453fc556e391f06958cc335e443111605 Mon Sep 17 00:00:00 2001 From: Anthony Laibe Date: Mon, 23 Jul 2018 14:12:20 +0100 Subject: [PATCH 08/16] Add access to the contract --- lib/index.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/index.js b/lib/index.js index 1efedbbe..c83f56c8 100644 --- a/lib/index.js +++ b/lib/index.js @@ -263,14 +263,22 @@ class Embark { engine.startService("libraryManager"); engine.startService("codeRunner"); engine.startService("web3"); - engine.startService("deployment", {onlyCompile: true}); + engine.startService("pipeline"); + engine.startService("deployment", {onlyCompile: false}); engine.startService("storage"); + engine.startService("codeGenerator"); callback(); }, function deploy(callback) { engine.events.request('deploy:contracts', function (err) { - engine.logger.info("Finished deploying".underline); + callback(err); + }); + }, + function waitForWriteFinish(callback) { + engine.logger.info("Finished deploying".underline); + engine.events.on('outputDone', (err) => { + engine.logger.info(__("finished building").underline); callback(err); }); }, From da1691327aed9148ed89d955aa24567413d4130a Mon Sep 17 00:00:00 2001 From: Anthony Laibe Date: Mon, 23 Jul 2018 14:33:03 +0100 Subject: [PATCH 09/16] No need for pipeline service, assets are not compiled --- lib/index.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/index.js b/lib/index.js index c83f56c8..4f430cb0 100644 --- a/lib/index.js +++ b/lib/index.js @@ -263,7 +263,6 @@ class Embark { engine.startService("libraryManager"); engine.startService("codeRunner"); engine.startService("web3"); - engine.startService("pipeline"); engine.startService("deployment", {onlyCompile: false}); engine.startService("storage"); engine.startService("codeGenerator"); @@ -277,10 +276,7 @@ class Embark { }, function waitForWriteFinish(callback) { engine.logger.info("Finished deploying".underline); - engine.events.on('outputDone', (err) => { - engine.logger.info(__("finished building").underline); - callback(err); - }); + callback(); }, function startREPL(callback) { let repl = new REPL({env: engine.env}); From 3e328801db855183bdb621e761e5c569abe75d4c Mon Sep 17 00:00:00 2001 From: Anthony Laibe Date: Mon, 23 Jul 2018 17:05:01 +0100 Subject: [PATCH 10/16] nodashboard start a repl --- lib/coderunner/runCode.js | 7 ++++++- lib/dashboard/repl.js | 10 ++++++++-- lib/index.js | 9 ++++++++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/lib/coderunner/runCode.js b/lib/coderunner/runCode.js index 9560eec1..7d010410 100644 --- a/lib/coderunner/runCode.js +++ b/lib/coderunner/runCode.js @@ -23,8 +23,13 @@ function registerVar(varName, code) { __mainContext[varName] = code; } +function getContext() { + return __mainContext; +} + module.exports = { doEval: doEval, registerVar: registerVar, - initContext: initContext + initContext: initContext, + getContext: getContext }; diff --git a/lib/dashboard/repl.js b/lib/dashboard/repl.js index f416bc94..1dd5181f 100644 --- a/lib/dashboard/repl.js +++ b/lib/dashboard/repl.js @@ -1,4 +1,5 @@ const repl = require("repl"); +const RunCode = require('../coderunner/runCode'); class REPL { constructor(options) { @@ -6,16 +7,21 @@ class REPL { } start(done) { - let replServer = repl.start({ + this.replServer = repl.start({ prompt: "Embark (" + this.env + ") > " }); + this.initializeContext(this.replServer.context); - replServer.on('exit', () => { + this.replServer.on("exit", () => { process.exit(); }); done(); } + + initializeContext(context) { + context.embark = RunCode.getContext(); + } } module.exports = REPL; diff --git a/lib/index.js b/lib/index.js index 4f430cb0..63a2beb2 100644 --- a/lib/index.js +++ b/lib/index.js @@ -155,7 +155,14 @@ class Embark { }); } engine.startService("fileWatcher"); - callback(); + + if (!options.useDashboard) { + const REPL = require('./dashboard/repl.js'); + let repl = new REPL({env: engine.env}); + repl.start(function () { + callback(); + }); + } } ], function (err, _result) { if (err) { From 2d7876146ba77efef14b5fb1a497a5dcb55910f3 Mon Sep 17 00:00:00 2001 From: Anthony Laibe Date: Tue, 24 Jul 2018 09:40:48 +0100 Subject: [PATCH 11/16] Use global in repl --- lib/coderunner/runCode.js | 7 +------ lib/dashboard/repl.js | 8 ++------ lib/index.js | 6 +++++- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/lib/coderunner/runCode.js b/lib/coderunner/runCode.js index 7d010410..9560eec1 100644 --- a/lib/coderunner/runCode.js +++ b/lib/coderunner/runCode.js @@ -23,13 +23,8 @@ function registerVar(varName, code) { __mainContext[varName] = code; } -function getContext() { - return __mainContext; -} - module.exports = { doEval: doEval, registerVar: registerVar, - initContext: initContext, - getContext: getContext + initContext: initContext }; diff --git a/lib/dashboard/repl.js b/lib/dashboard/repl.js index 1dd5181f..d9a0dd01 100644 --- a/lib/dashboard/repl.js +++ b/lib/dashboard/repl.js @@ -1,5 +1,4 @@ const repl = require("repl"); -const RunCode = require('../coderunner/runCode'); class REPL { constructor(options) { @@ -8,9 +7,9 @@ class REPL { start(done) { this.replServer = repl.start({ - prompt: "Embark (" + this.env + ") > " + prompt: "Embark (" + this.env + ") > ", + useGlobal: true }); - this.initializeContext(this.replServer.context); this.replServer.on("exit", () => { process.exit(); @@ -19,9 +18,6 @@ class REPL { done(); } - initializeContext(context) { - context.embark = RunCode.getContext(); - } } module.exports = REPL; diff --git a/lib/index.js b/lib/index.js index 63a2beb2..266a4064 100644 --- a/lib/index.js +++ b/lib/index.js @@ -270,6 +270,7 @@ class Embark { engine.startService("libraryManager"); engine.startService("codeRunner"); engine.startService("web3"); + engine.startService("pipeline"); engine.startService("deployment", {onlyCompile: false}); engine.startService("storage"); engine.startService("codeGenerator"); @@ -283,7 +284,10 @@ class Embark { }, function waitForWriteFinish(callback) { engine.logger.info("Finished deploying".underline); - callback(); + engine.events.on('outputDone', (err) => { + engine.logger.info(__("finished building").underline); + callback(err); + }); }, function startREPL(callback) { let repl = new REPL({env: engine.env}); From a5b9502e825242f4280e96269ddde3e97e869e1b Mon Sep 17 00:00:00 2001 From: Anthony Laibe Date: Tue, 24 Jul 2018 16:46:52 +0100 Subject: [PATCH 12/16] Add watcher to console command --- lib/index.js | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/lib/index.js b/lib/index.js index 266a4064..1bdea960 100644 --- a/lib/index.js +++ b/lib/index.js @@ -155,14 +155,6 @@ class Embark { }); } engine.startService("fileWatcher"); - - if (!options.useDashboard) { - const REPL = require('./dashboard/repl.js'); - let repl = new REPL({env: engine.env}); - repl.start(function () { - callback(); - }); - } } ], function (err, _result) { if (err) { @@ -274,6 +266,7 @@ class Embark { engine.startService("deployment", {onlyCompile: false}); engine.startService("storage"); engine.startService("codeGenerator"); + engine.startService("fileWatcher"); callback(); }, @@ -284,16 +277,14 @@ class Embark { }, function waitForWriteFinish(callback) { engine.logger.info("Finished deploying".underline); - engine.events.on('outputDone', (err) => { + engine.events.once('outputDone', (err) => { engine.logger.info(__("finished building").underline); callback(err); }); }, function startREPL(callback) { let repl = new REPL({env: engine.env}); - repl.start(function () { - callback(); - }); + repl.start(callback); } ], function (err, _result) { if (err) { From b4ea6c03d952618603efb45597282e195344d525 Mon Sep 17 00:00:00 2001 From: Anthony Laibe Date: Wed, 25 Jul 2018 09:31:35 +0100 Subject: [PATCH 13/16] fix eslint --- lib/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/index.js b/lib/index.js index 1bdea960..7d22c47c 100644 --- a/lib/index.js +++ b/lib/index.js @@ -155,6 +155,7 @@ class Embark { }); } engine.startService("fileWatcher"); + callback(); } ], function (err, _result) { if (err) { From 5d5fda54e2279367c08ab6d043d8eb7a5aa954dc Mon Sep 17 00:00:00 2001 From: Anthony Laibe Date: Wed, 25 Jul 2018 10:15:43 +0100 Subject: [PATCH 14/16] Adding profile command --- lib/dashboard/repl.js | 14 ++++++++++++++ lib/index.js | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/dashboard/repl.js b/lib/dashboard/repl.js index d9a0dd01..28129bed 100644 --- a/lib/dashboard/repl.js +++ b/lib/dashboard/repl.js @@ -3,6 +3,7 @@ const repl = require("repl"); class REPL { constructor(options) { this.env = options.env; + this.plugins = options.plugins; } start(done) { @@ -15,6 +16,19 @@ class REPL { process.exit(); }); + let self = this; + this.replServer.defineCommand('profile', { + help: 'Profile a contract', + action(contract) { + this.clearBufferedCommand(); + let pluginCmds = self.plugins.getPluginsProperty('console', 'console'); + for (let pluginCmd of pluginCmds) { + pluginCmd.call(self, `profile ${contract}`, {}); + } + this.displayPrompt(); + } + }); + done(); } diff --git a/lib/index.js b/lib/index.js index 7d22c47c..3db589bc 100644 --- a/lib/index.js +++ b/lib/index.js @@ -284,7 +284,7 @@ class Embark { }); }, function startREPL(callback) { - let repl = new REPL({env: engine.env}); + let repl = new REPL({env: engine.env, plugins: engine.plugins}); repl.start(callback); } ], function (err, _result) { From ed9be59abe764e0462cd8e7be1e13b671faae493 Mon Sep 17 00:00:00 2001 From: Anthony Laibe Date: Thu, 26 Jul 2018 16:00:25 +0100 Subject: [PATCH 15/16] Use console and override evaluator --- lib/dashboard/repl.js | 30 ++++++++++++++++-------------- lib/index.js | 7 ++++++- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/lib/dashboard/repl.js b/lib/dashboard/repl.js index 28129bed..8f23b586 100644 --- a/lib/dashboard/repl.js +++ b/lib/dashboard/repl.js @@ -1,34 +1,36 @@ const repl = require("repl"); +const Console = require('./console.js'); + class REPL { constructor(options) { this.env = options.env; this.plugins = options.plugins; + this.events = options.events; + this.console = new Console({ + events: this.events, + plugins: this.plugins, + version: options.version + }); + } + + enhancedEval(cmd, context, filename, callback) { + this.console.executeCmd(cmd.trim(), (result) => { + callback(null, result); + }); } start(done) { this.replServer = repl.start({ prompt: "Embark (" + this.env + ") > ", - useGlobal: true + useGlobal: true, + eval: this.enhancedEval.bind(this) }); this.replServer.on("exit", () => { process.exit(); }); - let self = this; - this.replServer.defineCommand('profile', { - help: 'Profile a contract', - action(contract) { - this.clearBufferedCommand(); - let pluginCmds = self.plugins.getPluginsProperty('console', 'console'); - for (let pluginCmd of pluginCmds) { - pluginCmd.call(self, `profile ${contract}`, {}); - } - this.displayPrompt(); - } - }); - done(); } diff --git a/lib/index.js b/lib/index.js index 3db589bc..455deeb6 100644 --- a/lib/index.js +++ b/lib/index.js @@ -284,7 +284,12 @@ class Embark { }); }, function startREPL(callback) { - let repl = new REPL({env: engine.env, plugins: engine.plugins}); + let repl = new REPL({ + env: engine.env, + plugins: engine.plugins, + version: engine.version, + events: engine.events + }); repl.start(callback); } ], function (err, _result) { From 2f2626a7c8dc91145d0ff10b2d7c03b5d4fd3b2d Mon Sep 17 00:00:00 2001 From: Anthony Laibe Date: Thu, 26 Jul 2018 16:56:50 +0100 Subject: [PATCH 16/16] Add dedicated writer for string result --- lib/dashboard/repl.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/dashboard/repl.js b/lib/dashboard/repl.js index 8f23b586..bd5442fc 100644 --- a/lib/dashboard/repl.js +++ b/lib/dashboard/repl.js @@ -1,4 +1,5 @@ const repl = require("repl"); +const util = require("util"); const Console = require('./console.js'); @@ -20,11 +21,20 @@ class REPL { }); } + enhancedWriter(output) { + if ((typeof output) === "string") { + return output; + } else { + return util.inspect(output, {colors: true}); + } + } + start(done) { this.replServer = repl.start({ prompt: "Embark (" + this.env + ") > ", useGlobal: true, - eval: this.enhancedEval.bind(this) + eval: this.enhancedEval.bind(this), + writer: this.enhancedWriter.bind(this) }); this.replServer.on("exit", () => {