From a3de13e01140257cb291494889a308913fde7a9b Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Thu, 31 May 2018 13:12:56 -0400 Subject: [PATCH 1/9] refactor to addPluginType --- lib/core/plugin.js | 47 +++++++++++++++++++--------------------------- 1 file changed, 19 insertions(+), 28 deletions(-) diff --git a/lib/core/plugin.js b/lib/core/plugin.js index fa8c8650..b0197522 100644 --- a/lib/core/plugin.js +++ b/lib/core/plugin.js @@ -120,52 +120,50 @@ Plugin.prototype.interceptLogs = function(context) { // TODO: add deploy provider Plugin.prototype.registerClientWeb3Provider = function(cb) { this.clientWeb3Providers.push(cb); - this.pluginTypes.push('clientWeb3Provider'); - this.pluginTypes = _.uniq(this.pluginTypes); + this.addPluginType('clientWeb3Provider'); }; Plugin.prototype.registerContractsGeneration = function(cb) { this.contractsGenerators.push(cb); - this.pluginTypes.push('contractGeneration'); - this.pluginTypes = _.uniq(this.pluginTypes); + this.addPluginType('contractGeneration'); }; Plugin.prototype.registerPipeline = function(matcthingFiles, cb) { // TODO: generate error for more than one pipeline per plugin this.pipeline.push({matcthingFiles: matcthingFiles, cb: cb}); - this.pluginTypes.push('pipeline'); - this.pluginTypes = _.uniq(this.pluginTypes); + this.addPluginType('pipeline'); }; Plugin.prototype.addFileToPipeline = function(file, intendedPath, options) { this.pipelineFiles.push({file: file, intendedPath: intendedPath, options: options}); - this.pluginTypes.push('pipelineFiles'); - this.pluginTypes = _.uniq(this.pluginTypes); + this.addPluginType('pipelineFiles'); }; Plugin.prototype.addContractFile = function(file) { this.contractsFiles.push(file); - this.pluginTypes.push('contractFiles'); - this.pluginTypes = _.uniq(this.pluginTypes); + this.addPluginType('contractFiles'); }; Plugin.prototype.registerConsoleCommand = function(cb) { this.console.push(cb); - this.pluginTypes.push('console'); - this.pluginTypes = _.uniq(this.pluginTypes); + this.addPluginType('console'); }; // TODO: this only works for services done on startup Plugin.prototype.registerServiceCheck = function(checkName, checkFn, time) { this.serviceChecks.push({checkName: checkName, checkFn: checkFn, time: time}); - this.pluginTypes.push('serviceChecks'); - this.pluginTypes = _.uniq(this.pluginTypes); + this.addPluginType('serviceChecks'); }; Plugin.prototype.has = function(pluginType) { return this.pluginTypes.indexOf(pluginType) >= 0; }; +Plugin.prototype.addPluginType = function(pluginType) { + this.pluginTypes.push(pluginType); + this.pluginTypes = _.uniq(this.pluginTypes); +}; + Plugin.prototype.generateProvider = function(args) { return this.clientWeb3Providers.map(function(cb) { return cb.call(this, args); @@ -180,39 +178,33 @@ Plugin.prototype.generateContracts = function(args) { Plugin.prototype.registerContractConfiguration = function(config) { this.contractsConfigs.push(config); - this.pluginTypes.push('contractsConfig'); - this.pluginTypes = _.uniq(this.pluginTypes); + this.addPluginType('contractsConfig'); }; Plugin.prototype.registerCompiler = function(extension, cb) { this.compilers.push({extension: extension, cb: cb}); - this.pluginTypes.push('compilers'); - this.pluginTypes = _.uniq(this.pluginTypes); + this.addPluginType('compilers'); }; Plugin.prototype.registerUploadCommand = function(cmd, cb) { this.uploadCmds.push({cmd: cmd, cb: cb}); - this.pluginTypes.push('uploadCmds'); - this.pluginTypes = _.uniq(this.pluginTypes); + this.addPluginType('uploadCmds'); }; Plugin.prototype.addCodeToEmbarkJS = function(code) { this.embarkjs_code.push(code); - this.pluginTypes.push('embarkjsCode'); - this.pluginTypes = _.uniq(this.pluginTypes); + this.addPluginType('embarkjsCode'); }; Plugin.prototype.addProviderInit = function(providerType, code, initCondition) { this.embarkjs_init_code[providerType] = this.embarkjs_init_code[providerType] || []; this.embarkjs_init_code[providerType].push([code, initCondition]); - this.pluginTypes.push('initCode'); - this.pluginTypes = _.uniq(this.pluginTypes); + this.addPluginType('initCode'); }; Plugin.prototype.registerImportFile = function(importName, importLocation) { this.imports.push([importName, importLocation]); - this.pluginTypes.push('imports'); - this.pluginTypes = _.uniq(this.pluginTypes); + this.addPluginType('imports'); }; Plugin.prototype.registerActionForEvent = function(eventName, cb) { @@ -220,8 +212,7 @@ Plugin.prototype.registerActionForEvent = function(eventName, cb) { this.eventActions[eventName] = []; } this.eventActions[eventName].push(cb); - this.pluginTypes.push('eventActions'); - this.pluginTypes = _.uniq(this.pluginTypes); + this.addPluginType('eventActions'); }; Plugin.prototype.runFilePipeline = function() { From 0dbefad48bd4882db3c810b0716ac5c26bb78fff Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Fri, 1 Jun 2018 11:57:01 -0400 Subject: [PATCH 2/9] move requires to methods that actually need them --- lib/cmd.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/cmd.js b/lib/cmd.js index e58b852e..77af4017 100644 --- a/lib/cmd.js +++ b/lib/cmd.js @@ -1,6 +1,4 @@ const program = require('commander'); -const promptly = require('promptly'); -const utils = require('./utils/utils.js'); const Embark = require('../lib/index'); const i18n = require('./i18n/i18n.js'); let embark = new Embark; @@ -50,6 +48,7 @@ class Cmd { .action(function (name, options) { i18n.setOrDetectLocale(options.locale); if (name === undefined) { + const promptly = require('promptly'); return promptly.prompt(__("Name your app (default is %s):", 'embarkDapp'), { default: "embarkDApp", validator: validateName @@ -259,6 +258,7 @@ class Cmd { program .action(function (cmd) { console.log((__('unknown command') + ' "%s"').red, cmd); + let utils = require('./utils/utils.js'); let dictionary = ['new', 'demo', 'build', 'run', 'blockchain', 'simulator', 'test', 'upload', 'version']; let suggestion = utils.proposeAlternative(cmd, dictionary); if (suggestion) { From 0804779a2074cbbd0818cbe1d4287179338e5ad5 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Fri, 1 Jun 2018 11:57:32 -0400 Subject: [PATCH 3/9] don't sync i18n files anymore --- lib/i18n/locales/en.json | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/i18n/locales/en.json b/lib/i18n/locales/en.json index aa3084f4..bf20868d 100644 --- a/lib/i18n/locales/en.json +++ b/lib/i18n/locales/en.json @@ -161,5 +161,10 @@ "Cannot upload: {{platform}} node is not running on {{url}}.": "Cannot upload: {{platform}} node is not running on {{url}}.", "Cannot start {{platform}} node on {{url}}.": "Cannot start {{platform}} node on {{url}}.", "Storage process for swarm ended before the end of this process. Code: 0": "Storage process for swarm ended before the end of this process. Code: 0", - "error uploading to swarm": "error uploading to swarm" + "error uploading to swarm": "error uploading to swarm", + "IPFS node detected": "IPFS node detected", + "Ethereum node detected": "Ethereum node detected", + "Starting swarm process": "Starting swarm process", + "Deployment Done": "Deployment Done", + "Name your app (default is %s):": "Name your app (default is %s):" } From 37d54e22dbb58e488dedda8d32a6432228cc9823 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Fri, 1 Jun 2018 11:58:11 -0400 Subject: [PATCH 4/9] refactor services monitor to use events instead of passing addCheck around --- lib/contracts/blockchain.js | 3 +-- lib/core/engine.js | 28 ++++++---------------------- lib/core/services_monitor.js | 11 +++++++++++ lib/index.js | 2 +- lib/modules/ipfs/index.js | 9 ++------- lib/modules/specialconfigs/index.js | 1 - lib/modules/swarm/index.js | 19 +++++++------------ lib/modules/webserver/index.js | 4 +--- lib/modules/whisper/index.js | 3 +-- 9 files changed, 30 insertions(+), 50 deletions(-) diff --git a/lib/contracts/blockchain.js b/lib/contracts/blockchain.js index 999ae142..fee3a22f 100644 --- a/lib/contracts/blockchain.js +++ b/lib/contracts/blockchain.js @@ -18,7 +18,6 @@ class Blockchain { this.web3 = options.web3; this.locale = options.locale; this.isDev = options.isDev; - this.addCheck = options.addCheck; this.web3Endpoint = ''; this.isWeb3Ready = false; this.web3StartedInProcess = false; @@ -111,7 +110,7 @@ class Blockchain { const self = this; const NO_NODE = 'noNode'; - this.addCheck('Ethereum', function (cb) { + this.events.request("services:register", 'Ethereum', function (cb) { async.waterfall([ function checkNodeConnection(next) { self.assertNodeConnection(true, (err) => { diff --git a/lib/core/engine.js b/lib/core/engine.js index f1fb3342..6722c485 100644 --- a/lib/core/engine.js +++ b/lib/core/engine.js @@ -40,11 +40,6 @@ class Engine { this.config.loadConfigFiles({embarkConfig: this.embarkConfig, interceptLogs: this.interceptLogs}); this.plugins = this.config.plugins; - this.servicesMonitor = new ServicesMonitor({events: this.events, logger: this.logger}); - this.servicesMonitor.addCheck('embarkVersion', function (cb) { - return cb({name: 'Embark ' + self.version, status: 'on'}); - }, 0); - if (this.interceptLogs || this.interceptLogs === undefined) { this.doInterceptLogs(); } @@ -77,18 +72,11 @@ class Engine { } startMonitor() { - let self = this; - if (this.plugins) { - // -------- - // TODO: this only works for services done on startup - // -------- - let servicePlugins = this.plugins.getPluginsFor('serviceChecks'); - servicePlugins.forEach(function (plugin) { - plugin.serviceChecks.forEach(function (pluginCheck) { - self.servicesMonitor.addCheck(pluginCheck.checkName, pluginCheck.checkFn, pluginCheck.time); - }); - }); - } + const self = this; + this.servicesMonitor = new ServicesMonitor({events: this.events, logger: this.logger, plugins: this.plugins}); + this.servicesMonitor.addCheck('embarkVersion', function (cb) { + return cb({name: 'Embark ' + self.version, status: 'on'}); + }, 0); this.servicesMonitor.startMonitor(); } @@ -257,9 +245,7 @@ class Engine { } webServerService() { - this.registerModule('webserver', { - addCheck: this.servicesMonitor.addCheck.bind(this.servicesMonitor) - }); + this.registerModule('webserver'); } storageService(_options) { @@ -281,7 +267,6 @@ class Engine { this.blockchain = new Blockchain({ contractsConfig: this.config.contractsConfig, blockchainConfig: this.config.blockchainConfig, - addCheck: this.servicesMonitor.addCheck.bind(this.servicesMonitor), events: this.events, logger: this.logger, isDev: this.isDev, @@ -290,7 +275,6 @@ class Engine { }); this.registerModule('whisper', { - addCheck: this.servicesMonitor.addCheck.bind(this.servicesMonitor), // TODO: this should not be needed and should be deducted from the config instead // the eth provider is not necessary the same as the whisper one web3: this.blockchain.web3 diff --git a/lib/core/services_monitor.js b/lib/core/services_monitor.js index c1342212..7997859c 100644 --- a/lib/core/services_monitor.js +++ b/lib/core/services_monitor.js @@ -2,12 +2,18 @@ let async = require('../utils/async_extend.js'); class ServicesMonitor { constructor(options) { + const self = this; this.events = options.events; this.logger = options.logger; + this.plugins = options.plugins; this.checkList = {}; this.checkTimers = {}; this.checkState = {}; this.working = false; + + self.events.setCommandHandler("services:register", (checkName, checkFn, time) => { + self.addCheck(checkName, checkFn, time); + }); } } @@ -65,6 +71,11 @@ ServicesMonitor.prototype.startMonitor = function () { this.working = true; this.logger.trace('startMonitor'); + let servicePlugins = this.plugins.getPluginsProperty('serviceChecks', 'serviceChecks'); + servicePlugins.forEach(function (pluginCheck) { + self.addCheck(pluginCheck.checkName, pluginCheck.checkFn, pluginCheck.time); + }); + async.eachObject(this.checkList, function (checkName, check, callback) { self.initCheck(checkName); callback(); diff --git a/lib/index.js b/lib/index.js index 0a6af697..48ce9d63 100644 --- a/lib/index.js +++ b/lib/index.js @@ -300,6 +300,7 @@ class Embark { function startServices(callback) { + engine.startMonitor(); engine.startService("libraryManager"); engine.startService("codeRunner"); engine.startService("web3"); @@ -307,7 +308,6 @@ class Embark { engine.startService("deployment"); engine.startService("storage"); engine.startService("codeGenerator"); - engine.startMonitor(); callback(); }, function setupStoragePlugin(callback){ diff --git a/lib/modules/ipfs/index.js b/lib/modules/ipfs/index.js index be0eb7fe..bbeeecf5 100644 --- a/lib/modules/ipfs/index.js +++ b/lib/modules/ipfs/index.js @@ -10,11 +10,10 @@ class IPFS { this.logger = embark.logger; this.events = embark.events; this.buildDir = options.buildDir; - this.storageConfig = options.storageConfig; + this.storageConfig = embark.config.storageConfig; this.host = options.host || this.storageConfig.upload.host; this.port = options.port || this.storageConfig.upload.port; this.protocol = options.protocol || this.storageConfig.upload.protocol; - this.addCheck = options.addCheck; this.embark = embark; } @@ -48,11 +47,7 @@ class IPFS { self.logger.info(__('IPFS node is offline') + '..'); }); - if (!self.addCheck) { - return; - } - - self.addCheck('IPFS', function (cb) { + self.events.request("services:register", 'IPFS', function (cb) { self.logger.trace("Checking IPFS version..."); let url = (self.protocol || 'http') + '://' + self.host + ':' + self.port + '/api/v0/version'; if(self.protocol !== 'https'){ diff --git a/lib/modules/specialconfigs/index.js b/lib/modules/specialconfigs/index.js index b2b00a09..b829f77f 100644 --- a/lib/modules/specialconfigs/index.js +++ b/lib/modules/specialconfigs/index.js @@ -7,7 +7,6 @@ class SpecialConfigs { this.logger = embark.logger; this.events = embark.events; this.buildDir = options.buildDir; - this.addCheck = options.addCheck; this.embark = embark; this.contractsConfig = embark.config.contractsConfig; diff --git a/lib/modules/swarm/index.js b/lib/modules/swarm/index.js index 8d6b35f8..59b3b9d8 100644 --- a/lib/modules/swarm/index.js +++ b/lib/modules/swarm/index.js @@ -10,14 +10,15 @@ class Swarm { this.logger = embark.logger; this.events = embark.events; this.buildDir = options.buildDir; - this.storageConfig = options.storageConfig; - this.addCheck = options.addCheck; + this.storageConfig = embark.config.storageConfig; + this.host = options.host || this.storageConfig.host; + this.port = options.port || this.storageConfig.port; this.embark = embark; - + this.providerUrl = utils.buildUrl(options.protocol || options.storageConfig.upload.protocol, options.host || options.storageConfig.upload.host, options.port || options.storageConfig.upload.port); - + this.getUrl = options.storageConfig.upload.getUrl || this.providerUrl + '/bzz:/'; - + this.bzz = new Web3Bzz(this.providerUrl); } @@ -32,7 +33,6 @@ class Swarm { this.embark.registerUploadCommand('swarm', this.upload_swarm.deploy.bind(this.upload_swarm)); } - setServiceCheck() { let self = this; @@ -53,12 +53,7 @@ class Swarm { self.logger.info(__('Swarm node is offline...')); }); - if (!this.addCheck) { - return; - } - - // add check for console - this.addCheck('Swarm', function(cb){ + self.events.request("services:register", 'Swarm', function(cb){ self.logger.trace("Checking Swarm availability..."); self.bzz.isAvailable().then(result => { return cb({name: "Swarm ", status: result ? 'on':'off'}); diff --git a/lib/modules/webserver/index.js b/lib/modules/webserver/index.js index 63232cc3..a13fb1b7 100644 --- a/lib/modules/webserver/index.js +++ b/lib/modules/webserver/index.js @@ -7,7 +7,6 @@ class WebServer { this.embark = embark; this.logger = embark.logger; this.events = embark.events; - this.addCheck = options.addCheck; this.webServerConfig = embark.config.webServerConfig; if (!this.webServerConfig.enabled) { return; @@ -29,8 +28,7 @@ class WebServer { setServiceCheck() { let url = 'http://' + this.host + ':' + this.port; - //embark.registerServiceCheck('WebserverService', function (cb) { - this.addCheck('Webserver', function (cb) { + this.events.request("services:register", 'Webserver', function (cb) { utils.checkIsAvailable(url, function (available) { let devServer = __('Webserver') + ' (' + url + ')'; let serverStatus = (available ? 'on' : 'off'); diff --git a/lib/modules/whisper/index.js b/lib/modules/whisper/index.js index 53b80871..34552077 100644 --- a/lib/modules/whisper/index.js +++ b/lib/modules/whisper/index.js @@ -8,7 +8,6 @@ class Whisper { this.logger = embark.logger; this.events = embark.events; this.communicationConfig = embark.config.communicationConfig; - this.addCheck = options.addCheck; this.web3 = new Web3(); this.embark = embark; @@ -26,7 +25,7 @@ class Whisper { setServiceCheck() { const self = this; - self.addCheck('Whisper', function (cb) { + self.events.request("services:register", 'Whisper', function (cb) { if (!self.web3.currentProvider || self.web3.currentProvider.connection.readyState !== 1) { return self.connectToProvider(); } From eadbeb0498138e9acc9e172e466312103843f651 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Fri, 1 Jun 2018 12:27:12 -0400 Subject: [PATCH 5/9] use monitor as a service --- lib/core/engine.js | 19 ++++++++++--------- lib/index.js | 6 +++--- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/lib/core/engine.js b/lib/core/engine.js index 6722c485..5224a50a 100644 --- a/lib/core/engine.js +++ b/lib/core/engine.js @@ -71,15 +71,6 @@ class Engine { }; } - startMonitor() { - const self = this; - this.servicesMonitor = new ServicesMonitor({events: this.events, logger: this.logger, plugins: this.plugins}); - this.servicesMonitor.addCheck('embarkVersion', function (cb) { - return cb({name: 'Embark ' + self.version, status: 'on'}); - }, 0); - this.servicesMonitor.startMonitor(); - } - registerModule(moduleName, options) { this.plugins.loadInternalPlugin(moduleName, options || {}); } @@ -88,6 +79,7 @@ class Engine { let options = _options || {}; let services = { + "serviceMonitor": this.serviceMonitor, "pipeline": this.pipelineService, "codeRunner": this.codeRunnerService, "codeGenerator": this.codeGeneratorService, @@ -134,6 +126,15 @@ class Engine { }); } + serviceMonitor() { + const self = this; + this.servicesMonitor = new ServicesMonitor({events: this.events, logger: this.logger, plugins: this.plugins}); + this.servicesMonitor.addCheck('embarkVersion', function (cb) { + return cb({name: 'Embark ' + self.version, status: 'on'}); + }, 0); + this.servicesMonitor.startMonitor(); + } + namingSystem(_options) { this.registerModule('ens'); } diff --git a/lib/index.js b/lib/index.js index 48ce9d63..ca034230 100644 --- a/lib/index.js +++ b/lib/index.js @@ -114,7 +114,7 @@ class Embark { engine.logger.info(__("loaded plugins") + ": " + pluginList.join(", ")); } - engine.startMonitor(); + engine.startService("serviceMonitor"); engine.startService("libraryManager"); engine.startService("codeRunner"); engine.startService("web3"); @@ -238,7 +238,7 @@ class Embark { engine.logger.info(__("loaded plugins") + ": " + pluginList.join(", ")); } - engine.startMonitor(); + engine.startService("serviceMonitor"); engine.startService("libraryManager"); engine.startService("pipeline"); engine.startService("deployment", {onlyCompile: true}); @@ -300,7 +300,7 @@ class Embark { function startServices(callback) { - engine.startMonitor(); + engine.startService("serviceMonitor"); engine.startService("libraryManager"); engine.startService("codeRunner"); engine.startService("web3"); From 60c687aa4172b33138f8bfc1140e198eb1a1465d Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Fri, 1 Jun 2018 12:53:23 -0400 Subject: [PATCH 6/9] refactor storage module --- lib/modules/storage/index.js | 72 +++++++++++--------------- test_apps/test_app/config/storage.json | 2 +- 2 files changed, 30 insertions(+), 44 deletions(-) diff --git a/lib/modules/storage/index.js b/lib/modules/storage/index.js index 3327524f..9f8162a9 100644 --- a/lib/modules/storage/index.js +++ b/lib/modules/storage/index.js @@ -155,59 +155,45 @@ class Storage { this._embark.addProviderInit('storage', code, shouldInit); } + checkStorageService(platform, url, callback) { + const self = this; + const errorObj = {message: __('Cannot upload: {{platform}} node is not running on {{url}}.', {platform: platform, url: url})}; + + // start the upload storage node + self._checkStorageEndpoint(platform, function (err) { + if (!err) { + return callback(); + } + self._startStorageNode(platform, (err) => { + if (err) { + self._logger.error(err); + return callback(errorObj); + } + // Check endpoint again to see if really did start + self._checkStorageEndpoint(platform, (err) => { + if (err) { + return callback(errorObj); + } + callback(); + }); + }); + }); + } + startStorageProcesses(){ let platform = this._storageConfig.upload.provider; let self = this; async.waterfall([ - function checkStorageService(callback){ - const errorObj = {message: __('Cannot upload: {{platform}} node is not running on {{url}}.', {platform: platform, url: utils.buildUrlFromConfig(self._storageConfig.upload)})}; - - // start the upload storage node - self._checkStorageEndpoint(platform, function (err) { - if (!err) { - return callback(); - } - self._startStorageNode(platform, (err) => { - if (err) { - self._logger.error(err); - return callback(errorObj); - } - // Check endpoint again to see if really did start - self._checkStorageEndpoint(platform, (err) => { - if (err) { - return callback(errorObj); - } - callback(); - }); - }); - }); + function _checkStorageService(callback){ + self.checkStorageService(platform, utils.buildUrlFromConfig(self._storageConfig.upload), callback); }, function checkDappConnectionStorageService(callback){ // start any dappConnection storage nodes self._validDappProviders.forEach(dappConn => { if(!dappConn.provider || dappConn.provider === platform) return; // don't start the process we've just started above - - const errorObj = {message: __('Cannot start {{platform}} node on {{url}}.', {platform: dappConn.provider, url: utils.buildUrlFromConfig(dappConn)})}; - - self._checkStorageEndpoint(dappConn.provider, function (err) { - if (!err) { - return callback(); - } - self._startStorageNode(dappConn.provider, (err) => { - if (err) { - self._logger.error(err); - return callback(errorObj); - } - // Check endpoint again to see if really did start - self._checkStorageEndpoint(dappConn.provider, (err) => { - if (err) { - return callback(errorObj); - } - callback(); - }); - }); - }); + + self.checkStorageService(dappConn.provider, utils.buildUrlFromConfig(dappConn), callback); }); } ]); diff --git a/test_apps/test_app/config/storage.json b/test_apps/test_app/config/storage.json index 13912156..2209629d 100644 --- a/test_apps/test_app/config/storage.json +++ b/test_apps/test_app/config/storage.json @@ -36,4 +36,4 @@ "getUrl": "https://ipfs.infura.io/ipfs/" } } -} \ No newline at end of file +} From 07e58bcd040ef97bab7120f2b9b610c1a1f2b8ff Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Fri, 1 Jun 2018 13:19:48 -0400 Subject: [PATCH 7/9] check window size in dashboard instead of index --- lib/dashboard/dashboard.js | 12 ++++++++++++ lib/index.js | 6 ------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/dashboard/dashboard.js b/lib/dashboard/dashboard.js index 029b14e8..641c672b 100644 --- a/lib/dashboard/dashboard.js +++ b/lib/dashboard/dashboard.js @@ -1,16 +1,28 @@ let async = require('async'); +let windowSize = require('window-size'); let Monitor = require('./monitor.js'); let Console = require('./console.js'); class Dashboard { constructor(options) { + const self = this; this.logger = options.logger; this.events = options.events; this.plugins = options.plugins; this.version = options.version; this.env = options.env; this.contractsConfig = options.contractsConfig; + + this.events.on('firstDeploymentDone', this.checkWindowSize.bind(this)); + this.events.on('outputDone', this.checkWindowSize.bind(this)); + } + + checkWindowSize() { + let size = windowSize.get(); + if (size.height < 40 || size.width < 118) { + this.logger.warn(__("tip: you can resize the terminal or disable the dashboard with") + " embark run --nodashboard".bold.underline); + } } start(done) { diff --git a/lib/index.js b/lib/index.js index ca034230..9e3c3c51 100644 --- a/lib/index.js +++ b/lib/index.js @@ -68,7 +68,6 @@ class Embark { let self = this; self.context = options.context || [constants.contexts.run, constants.contexts.build]; let Dashboard = require('./dashboard/dashboard.js'); - let windowSize = require('window-size'); let engine = new Engine({ env: options.env, @@ -153,11 +152,6 @@ class Embark { engine.logger.info(err.stack); } else { engine.events.emit('firstDeploymentDone'); - - let size = windowSize.get(); - if (size.height < 40 || size.width < 118) { - engine.logger.warn(__("tip: you can resize the terminal or disable the dashboard with") + " embark run --nodashboard".bold.underline); - } } }); } From 083961fc21f3b0f18a7994e393412837999626df Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Fri, 1 Jun 2018 19:14:54 -0400 Subject: [PATCH 8/9] remove unneeded assignments --- lib/core/engine.js | 1 - lib/dashboard/dashboard.js | 1 - 2 files changed, 2 deletions(-) diff --git a/lib/core/engine.js b/lib/core/engine.js index 5224a50a..8b463ed4 100644 --- a/lib/core/engine.js +++ b/lib/core/engine.js @@ -32,7 +32,6 @@ class Engine { } init(_options) { - let self = this; let options = _options || {}; this.events = options.events || this.events || new Events(); this.logger = options.logger || new Logger({logLevel: options.logLevel || this.logLevel || 'debug', events: this.events, logFile: this.logFile}); diff --git a/lib/dashboard/dashboard.js b/lib/dashboard/dashboard.js index 641c672b..bc8c0c2a 100644 --- a/lib/dashboard/dashboard.js +++ b/lib/dashboard/dashboard.js @@ -6,7 +6,6 @@ let Console = require('./console.js'); class Dashboard { constructor(options) { - const self = this; this.logger = options.logger; this.events = options.events; this.plugins = options.plugins; From 74df72fc0d99bab08fbd990bab235bf5c50a109d Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Fri, 1 Jun 2018 19:35:41 -0400 Subject: [PATCH 9/9] lint is king --- lib/modules/whisper/index.js | 2 +- test_apps/test_app/package-lock.json | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/modules/whisper/index.js b/lib/modules/whisper/index.js index 34552077..a92fb7c6 100644 --- a/lib/modules/whisper/index.js +++ b/lib/modules/whisper/index.js @@ -4,7 +4,7 @@ let Web3 = require('web3'); class Whisper { - constructor(embark, options) { + constructor(embark, _options) { this.logger = embark.logger; this.events = embark.events; this.communicationConfig = embark.config.communicationConfig; diff --git a/test_apps/test_app/package-lock.json b/test_apps/test_app/package-lock.json index 6a0c2c66..3dba6607 100644 --- a/test_apps/test_app/package-lock.json +++ b/test_apps/test_app/package-lock.json @@ -89,7 +89,7 @@ "dom-helpers": { "version": "3.3.1", "resolved": "https://registry.npmjs.org/dom-helpers/-/dom-helpers-3.3.1.tgz", - "integrity": "sha1-/BpOFf/fYN3eA6SAqcD+zoId1KY=" + "integrity": "sha512-2Sm+JaYn74OiTM2wHvxJOo3roiq/h25Yi69Fqk269cNUwIXsCvATB6CRSFC9Am/20G2b28hGv/+7NiWydIrPvg==" }, "dotenv": { "version": "4.0.0", @@ -229,7 +229,7 @@ "node-fetch": { "version": "1.7.3", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-1.7.3.tgz", - "integrity": "sha1-mA9vcthSEaU0fGsrwYxbhMPrR+8=", + "integrity": "sha512-NhZ4CsKx7cYm2vSrBAr2PvFOe6sWDf0UYLRqA6svUYg7+/TSfVAu49jYC4BvQ4Sms9SZgdqGBgroqfDhJdTyKQ==", "requires": { "encoding": "0.1.12", "is-stream": "1.1.0" @@ -252,7 +252,7 @@ "promise": { "version": "7.3.1", "resolved": "https://registry.npmjs.org/promise/-/promise-7.3.1.tgz", - "integrity": "sha1-BktyYCsY+Q8pGSuLG8QY/9Hr078=", + "integrity": "sha512-nolQXZ/4L+bP/UGlkfaIujX9BKxGwmQ9OT4mOt5yvy8iK1h3wqTEJCijzGANTCCl9nWjY41juyAn2K3Q1hLLTg==", "requires": { "asap": "2.0.6" } @@ -289,7 +289,7 @@ "react-bootstrap": { "version": "0.32.1", "resolved": "https://registry.npmjs.org/react-bootstrap/-/react-bootstrap-0.32.1.tgz", - "integrity": "sha1-YGJMG0ijnXc+9szmQhpPM+zBZrs=", + "integrity": "sha512-RbfzKUbsukWsToWqGHfCCyMFq9QQI0TznutdyxyJw6dih2NvIne25Mrssg8LZsprqtPpyQi8bN0L0Fx3fUsL8Q==", "requires": { "babel-runtime": "6.26.0", "classnames": "2.2.5", @@ -319,7 +319,7 @@ "react-overlays": { "version": "0.8.3", "resolved": "https://registry.npmjs.org/react-overlays/-/react-overlays-0.8.3.tgz", - "integrity": "sha1-+tZe6lskMBzKGSoWn13dsLINOsU=", + "integrity": "sha512-h6GT3jgy90PgctleP39Yu3eK1v9vaJAW73GOA/UbN9dJ7aAN4BTZD6793eI1D5U+ukMk17qiqN/wl3diK1Z5LA==", "requires": { "classnames": "2.2.5", "dom-helpers": "3.3.1", @@ -353,7 +353,7 @@ "regenerator-runtime": { "version": "0.11.1", "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz", - "integrity": "sha1-vgWtf5v30i4Fb5cmzuUBf78Z4uk=" + "integrity": "sha512-MguG95oij0fC3QV3URf4V2SDYGJhJnJGqvIIgdECeODCT98wSWDAJ94SSuVpYQUoTcGUIL6L4yNB7j1DFFHSBg==" }, "setimmediate": { "version": "1.0.5", @@ -412,7 +412,7 @@ "zeppelin-solidity": { "version": "1.8.0", "resolved": "https://registry.npmjs.org/zeppelin-solidity/-/zeppelin-solidity-1.8.0.tgz", - "integrity": "sha1-BJ/N59rqn8hSEPjG25+M0auKhTo=", + "integrity": "sha512-7Mxq6Y7EES0PSLrRF6v0EVYqBVRRo8hFrr7m3jEs69VbbQ5kpANzizeEdbP1/PWKSOmBOg208qP2vSA0FlzFLA==", "requires": { "dotenv": "4.0.0", "ethjs-abi": "0.2.1"