diff --git a/packages/embark-core/src/processes/processWrapper.js b/packages/embark-core/src/processes/processWrapper.js index c21216373..592020b5d 100644 --- a/packages/embark-core/src/processes/processWrapper.js +++ b/packages/embark-core/src/processes/processWrapper.js @@ -46,6 +46,7 @@ export class ProcessWrapper { }, 500); } + // TODO: find better way - andre interceptLogs() { const context = {}; context.console = console; diff --git a/packages/embark/src/cmd/cmd.js b/packages/embark/src/cmd/cmd.js index a96078d1e..609191142 100644 --- a/packages/embark/src/cmd/cmd.js +++ b/packages/embark/src/cmd/cmd.js @@ -15,6 +15,7 @@ class Cmd { this.demo(); this.build(); this.run(); + this.run2(); this.console(); this.blockchain(); this.simulator(); @@ -169,6 +170,42 @@ class Cmd { }); } + run2() { + program + .command('run2 [environment]') + .option('-p, --port [port]', __('port to run the dev webserver (default: %s)', '8000')) + .option('-c, --client [client]', __('Use a specific ethereum client [%s] (default: %s)', 'geth, parity', 'geth')) + .option('-b, --host [host]', __('host to run the dev webserver (default: %s)', 'localhost')) + .option('--noserver', __('disable the development webserver')) + .option('--nodashboard', __('simple mode, disables the dashboard')) + .option('--nobrowser', __('prevent the development webserver from automatically opening a web browser')) + .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)')) + .option('--pipeline [pipeline]', __('webpack config to use (default: development)')) + .option('--no-single-use-auth-token', __('disable the single use of token in cockpit')) + .description(__('run dapp (default: %s)', 'development')) + .action(function(env, options) { + setOrDetectLocale(options.locale); + embark.run2({ + env: env || 'development', + serverPort: options.port, + serverHost: options.host, + client: options.client, + locale: options.locale, + runWebserver: !options.noserver ? null : false, + useDashboard: !options.nodashboard, + logFile: options.logfile, + logLevel: options.loglevel, + webpackConfigName: options.pipeline || 'development', + openBrowser: !options.nobrowser ? null : false, + singleUseAuthToken: options.singleUseAuthToken + }); + }); + } + + console() { program .command('console [environment]') diff --git a/packages/embark/src/cmd/cmd_controller.js b/packages/embark/src/cmd/cmd_controller.js index 8e76bc71e..19906187d 100644 --- a/packages/embark/src/cmd/cmd_controller.js +++ b/packages/embark/src/cmd/cmd_controller.js @@ -101,6 +101,139 @@ class EmbarkController { templateGenerator.generate(destinationFolder, name); } + run2(options) { + let self = this; + self.context = options.context || [constants.contexts.run, constants.contexts.build]; + let Dashboard = require('./dashboard/dashboard.js'); + + const webServerConfig = {}; + + if (options.runWebserver !== null && options.runWebserver !== undefined) { + webServerConfig.enabled = options.runWebserver; + } + + if (options.serverHost !== null && options.serverHost !== undefined) { + webServerConfig.host = options.serverHost; + } + + if (options.serverPort !== null && options.serverPort !== undefined) { + webServerConfig.port = options.serverPort; + } + + if (options.openBrowser !== null && options.openBrowser !== undefined) { + webServerConfig.openBrowser = options.openBrowser; + } + + const Engine = require('../lib/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: self.context, + useDashboard: options.useDashboard, + webServerConfig: webServerConfig, + webpackConfigName: options.webpackConfigName, + singleUseAuthToken: options.singleUseAuthToken, + ipcRole: 'server' + }); + + async.waterfall([ + function initEngine(callback) { + engine.init({}, () => { + // TODO: we can hook up this module to the action engine:start instead + // TODO: embark-listener & embark-process-logs-api can probably be merged + // engine.startService("embarkListener"); + if (!options.useDashboard) { + engine.logger.info('========================'.bold.green); + engine.logger.info((__('Welcome to Embark') + ' ' + engine.version).yellow.bold); + engine.logger.info('========================'.bold.green); + } + callback(); + }); + }, + function (callback) { + let pluginList = engine.plugins.listPlugins(); + if (pluginList.length > 0) { + engine.logger.info(__("loaded plugins") + ": " + pluginList.join(", ")); + } + + engine.registerModuleGroup("coreComponents"); + + engine.registerModuleGroup("blockchain"); + + // engine.startService("processManager"); + // engine.startService("web3"); + // engine.startService("coreProcess"); + // engine.startService("blockchainListener"); + // engine.startService("serviceMonitor"); + // engine.startService("libraryManager"); + // engine.startService("codeRunner"); + // engine.startService("pipeline"); + // engine.startService("deployment"); + // engine.startService("storage"); + // engine.startService("codeGenerator"); + // engine.startService("console"); + // engine.startService("cockpit"); + // engine.startService("pluginCommand"); + + // 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.error(err.message || err); + // } + // 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); + // }); + + // if (webServerConfig.enabled !== false) { + // engine.startService("webServer"); + // } + // engine.startService("fileWatcher"); + + engine.startEngine(() => { + callback(); + }); + }, + function startDashboard(callback) { + if (!options.useDashboard) { + return callback(); + } + + let dashboard = new Dashboard({ + events: engine.events, + logger: engine.logger, + plugins: engine.plugins, + version: self.version, + env: engine.env, + ipc: engine.ipc + }); + dashboard.start(function () { + engine.logger.info(__('dashboard start')); + callback(); + }); + } + ], function (err, _result) { + if (err) { + engine.logger.error(err.message); + engine.logger.info(err.stack); + } else { + // engine.events.emit('firstDeploymentDone'); + } + }); + } + run(options) { let self = this; self.context = options.context || [constants.contexts.run, constants.contexts.build]; @@ -173,6 +306,7 @@ class EmbarkController { engine.startService("console"); engine.startService("cockpit"); engine.startService("pluginCommand"); + engine.startService("blockchain"); engine.events.on('check:backOnline:Ethereum', function () { engine.logger.info(__('Ethereum node detected') + '..'); diff --git a/packages/embark/src/lib/core/engine.js b/packages/embark/src/lib/core/engine.js index 7d224ae67..9551dd9a4 100644 --- a/packages/embark/src/lib/core/engine.js +++ b/packages/embark/src/lib/core/engine.js @@ -72,6 +72,62 @@ class Engine { this.plugins.loadInternalPlugin(moduleName, options || {}, true); } + registerModuleGroup(groupName, _options) { + let options = _options || {}; + + let groups = { + "blockchain": this.blockchainComponents, + "coreComponents": this.coreComponents + }; + + let group = groups[groupName]; + + if (!group) { + throw new Error("unknown service: " + groupName); + } + + // need to be careful with circular references due to passing the web3 object + //this.logger.trace("calling: " + serviceName + "(" + JSON.stringify(options) + ")"); + return group.apply(this, [options]); + } + + coreComponents() { + // TODO: should be made into a component + this.processManager = new ProcessManager({ + events: this.events, + logger: this.logger, + plugins: this.plugins + }); + + const ServicesMonitor = require('./services_monitor.js'); + this.servicesMonitor = new ServicesMonitor({events: this.events, logger: this.logger, plugins: this.plugins}); + this.servicesMonitor.addCheck('Embark', function (cb) { + return cb({name: 'Embark ' + this.version, status: 'on'}); + }, 0); + + let plugin = this.plugins.createPlugin('coreservicesplugin', {}); + plugin.registerActionForEvent("embark:engine:started", (_params, cb) => { + console.dir("----- startMonitor") + this.servicesMonitor.startMonitor(); + cb(); + }); + this.registerModulePackage('embark-code-runner', {ipc: this.ipc}); + } + + blockchainComponents() { + // stack component + this.registerModule('blockchain', { plugins: this.plugins }); + + // plugins + this.registerModule('geth', { + client: this.client, + locale: this.locale, + isDev: this.isDev, + plugins: this.plugins, + ipc: this.ipc + }) + } + startService(serviceName, _options) { let options = _options || {}; @@ -113,17 +169,6 @@ class Engine { return service.apply(this, [options]); } - blockchainComponents() { - this.registerModule('blockchain', { plugins: this.plugins }); - this.registerModule('geth', { - client: this.client, - locale: this.locale, - isDev: this.isDev, - plugins: this.plugins, - ipc: this.ipc - }) - } - embarkListenerService(_options){ this.registerModulePackage('embark-listener'); } @@ -182,7 +227,6 @@ class Engine { } serviceMonitor() { - const self = this; const ServicesMonitor = require('./services_monitor.js'); this.servicesMonitor = new ServicesMonitor({events: this.events, logger: this.logger, plugins: this.plugins}); this.servicesMonitor.addCheck('Embark', function (cb) { diff --git a/packages/embark/src/lib/core/events.js b/packages/embark/src/lib/core/events.js index ab7738002..cbaf8518e 100644 --- a/packages/embark/src/lib/core/events.js +++ b/packages/embark/src/lib/core/events.js @@ -57,7 +57,7 @@ EventEmitter.prototype.request = function() { warnIfLegacy(requestName); if (this._events && !this._events['request:' + requestName]) { console.log("made request without listener: " + requestName) - // console.trace(); + console.trace(); } const listenerName = 'request:' + requestName; diff --git a/packages/embark/src/lib/core/plugins.js b/packages/embark/src/lib/core/plugins.js index a0fd934d4..c03103608 100644 --- a/packages/embark/src/lib/core/plugins.js +++ b/packages/embark/src/lib/core/plugins.js @@ -169,7 +169,7 @@ Plugins.prototype.runActionsForEvent = function(eventName, args, cb) { let actionPlugins = this.getPluginsProperty('eventActions', 'eventActions', eventName); if (actionPlugins.length === 0) { - return cb(args); + return cb(null, args); } async.reduce(actionPlugins, args, function(current_args, plugin, nextEach) { diff --git a/packages/embark/src/lib/core/services_monitor.js b/packages/embark/src/lib/core/services_monitor.js index f711a737c..437de5bfa 100644 --- a/packages/embark/src/lib/core/services_monitor.js +++ b/packages/embark/src/lib/core/services_monitor.js @@ -14,6 +14,7 @@ class ServicesMonitor { this.working = false; self.events.setCommandHandler("services:register", (checkName, checkFn, time, initialStatus) => { + console.dir("check added for "+ checkName) self.addCheck(checkName, checkFn, time, initialStatus); }); } @@ -59,6 +60,8 @@ ServicesMonitor.prototype.addCheck = function (checkName, checkFn, time, initial this.logger.trace('add check: ' + checkName); this.checkList[checkName] = {fn: checkFn, interval: time || 5000, status: initialState}; + console.dir("this.working") + console.dir(this.working) if (this.working) { this.initCheck(checkName); } @@ -75,6 +78,7 @@ ServicesMonitor.prototype.startMonitor = function () { let self = this; this.working = true; this.logger.trace('startMonitor'); + console.log('--> monitor started'); let servicePlugins = this.plugins.getPluginsProperty('serviceChecks', 'serviceChecks'); servicePlugins.forEach(function (pluginCheck) { diff --git a/packages/embark/src/lib/modules/geth/index.js b/packages/embark/src/lib/modules/geth/index.js index edff3b268..650f4a75c 100644 --- a/packages/embark/src/lib/modules/geth/index.js +++ b/packages/embark/src/lib/modules/geth/index.js @@ -28,9 +28,51 @@ class Geth { this.events.request("processes:launch", "blockchain", (err) => { readyCb() }); + this.registerServiceCheck() }) } + registerServiceCheck() { + console.dir("registerServiceCheck") + this.events.request("services:register", 'Ethereum', function (cb) { + cb({ name: "go-ethereum 1.1", status: 'on' }) + // async.waterfall([ + // function checkNodeConnection(next) { + // if (!self.provider || !self.provider.connected()) { + // return next(NO_NODE, { name: "No Blockchain node found", status: 'off' }); + // } + // next(); + // }, + // function checkVersion(next) { + // // TODO: web3_clientVersion method is currently not implemented in web3.js 1.0 + // self.web3._requestManager.send({ method: 'web3_clientVersion', params: [] }, (err, version) => { + // if (err || !version) { + // self.isWeb3Ready = false; + // return next(null, { name: "Ethereum node not found", status: 'off' }); + // } + // if (version.indexOf("/") < 0) { + // self.events.emit(WEB3_READY); + // self.isWeb3Ready = true; + // return next(null, { name: version, status: 'on' }); + // } + // let nodeName = version.split("/")[0]; + // let versionNumber = version.split("/")[1].split("-")[0]; + // let name = nodeName + " " + versionNumber + " (Ethereum)"; + + // self.events.emit(WEB3_READY); + // self.isWeb3Ready = true; + // return next(null, { name: name, status: 'on' }); + // }); + // } + // ], (err, statusObj) => { + // if (err && err !== NO_NODE) { + // return cb(err); + // } + // cb(statusObj); + // }); + }, 5000, 'off'); + } + startBlockchainNode(callback) { this.blockchainProcess = new BlockchainProcessLauncher({ events: this.events,