diff --git a/lib/i18n/locales/en.json b/lib/i18n/locales/en.json index 9562751d2..16d2aa460 100644 --- a/lib/i18n/locales/en.json +++ b/lib/i18n/locales/en.json @@ -138,6 +138,7 @@ "Starting ipfs process": "Starting ipfs process", "Storage process for ipfs ended before the end of this process. Code: 0": "Storage process for ipfs ended before the end of this process. Code: 0", "successfully uploaded to swarm": "successfully uploaded to swarm", + "ipfs process started": "ipfs process started", "WARNING! DApp path length is too long: ": "WARNING! DApp path length is too long: ", "This is known to cause issues with starting geth, please consider reducing your DApp path's length to 66 characters or less.": "This is known to cause issues with starting geth, please consider reducing your DApp path's length to 66 characters or less.", "Installing packages...": "Installing packages...", diff --git a/lib/index.js b/lib/index.js index bd28acb53..43594413c 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,6 +1,7 @@ let async = require('async'); const constants = require('./constants'); const _ = require('underscore'); +const StorageProcessesLauncher = require('./processes/storageProcesses/storageProcessesLauncher'); // require("./utils/debug_util.js")(__filename, async); require('colors'); @@ -66,6 +67,41 @@ class Embark { templateGenerator.generate(destinationFolder, name); } + _checkStorageEndpoint(engine, platform, callback) { + let checkFn; + _.find(engine.servicesMonitor.checkList, (value, key) => { + if(key.toLowerCase() === platform.toLowerCase()){ + checkFn = value; + return true; + } + }); + if (!checkFn || typeof checkFn.fn !== 'function') { + return callback(); + } + + checkFn.fn(function (serviceCheckResult) { + if (!serviceCheckResult.status || serviceCheckResult.status === 'off') { + return callback('No node'); + } + callback(); + }); + } + + _startStorageNode(engine, platform, callback) { + const storageProcessesLauncher = new StorageProcessesLauncher({ + logger: engine.logger, + events: engine.events, + storageConfig: engine.config.storageConfig + }); + return storageProcessesLauncher.launchProcess(platform.toLowerCase(), (err) => { + if (err) { + engine.logger.error(err); + return callback(err); + } + callback(); + }); + } + run(options) { let self = this; self.context = options.context || [constants.contexts.run, constants.contexts.build]; @@ -135,6 +171,19 @@ class Embark { }); }); + // Check storage + const platform = engine.config.storageConfig.provider; + self._checkStorageEndpoint(engine, platform, (err) => { + if (err) { + return self._startStorageNode(engine, platform, (err) => { + if (err) { + engine.logger.error('Error while starting a storage process for ' + platform); + engine.logger.error(err); + } + }); + } + }); + 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); @@ -285,8 +334,7 @@ class Embark { } upload(options) { - const StorageProcessesLauncher = require('./processes/storageProcesses/storageProcessesLauncher'); - + const self = this; this.context = options.context || [constants.contexts.upload, constants.contexts.build]; let engine = new Engine({ @@ -325,43 +373,20 @@ class Embark { callback(); }, function checkStorageService(callback){ - let checkFn; - _.find(engine.servicesMonitor.checkList, (value, key) => { - if(key.toLowerCase() === platform.toLowerCase()){ - checkFn = value; - return true; - } - }); - if (!checkFn || typeof checkFn.fn !== 'function') { - return callback(); - } - const erroObj = {message: __('Cannot upload: {{platform}} node is not running on {{protocol}}://{{host}}:{{port}}.', {platform: platform, protocol: engine.config.storageConfig.protocol, host: engine.config.storageConfig.host, port: engine.config.storageConfig.port})}; - function checkEndpoint(cb) { - checkFn.fn(function (serviceCheckResult) { - if (!serviceCheckResult.status || serviceCheckResult.status === 'off') { - return cb(erroObj); - } - cb(); - }); - } + const errorObj = {message: __('Cannot upload: {{platform}} node is not running on {{protocol}}://{{host}}:{{port}}.', {platform: platform, protocol: engine.config.storageConfig.protocol, host: engine.config.storageConfig.host, port: engine.config.storageConfig.port})}; - checkEndpoint(function (err) { + self._checkStorageEndpoint(engine, platform, function (err) { if (err) { - const storageProcessesLauncher = new StorageProcessesLauncher({ - logger: engine.logger, - events: engine.events, - storageConfig: engine.config.storageConfig - }); - return storageProcessesLauncher.launchProcess(platform.toLowerCase(), (err) => { + return self._startStorageNode(engine, platform, (err) => { if (err) { engine.logger.error(err); - return callback(erroObj); + return callback(errorObj); } // Check endpoint again to see if really did start - checkEndpoint((err) => { + self._checkStorageEndpoint(engine, platform, (err) => { if (err) { - return callback(err); + return callback(errorObj); } callback(); });