diff --git a/lib/cmd.js b/lib/cmd.js index e6e17848..12cd67b8 100644 --- a/lib/cmd.js +++ b/lib/cmd.js @@ -170,13 +170,15 @@ class Cmd { upload() { program .command('upload [platform] [environment]') + .option('--logfile [logfile]', 'filename to output logs (default: none)') .description('upload your dapp to a decentralized storage (e.g embark upload ipfs)') .action(function (platform, env, _options) { - // TODO: get env in cmd line as well - embark.initConfig(env || 'development', { + let environment = env || 'development'; + embark.initConfig(environment, { embarkConfig: 'embark.json', interceptLogs: false }); - embark.upload(platform); + _options.env = environment; + embark.upload(platform, _options); }); } diff --git a/lib/index.js b/lib/index.js index dcb5ac66..abf2f222 100644 --- a/lib/index.js +++ b/lib/index.js @@ -247,11 +247,18 @@ class Embark { } // TODO: should deploy if it hasn't already - upload(platform) { - let options = { - buildDir: 'dist/', - storageConfig: this.config.storageConfig - }; + upload(platform, options) { + + options.buildDir = 'dist/'; + options.storageConfig = this.config.storageConfig; + + let engine = new Engine({ + env: options.env, + version: this.version, + embarkConfig: options.embarkConfig || 'embark.json', + logfile: options.logfile + }); + engine.init(); this.plugins.loadInternalPlugin('ipfs', options); this.plugins.loadInternalPlugin('swarm', options); @@ -265,11 +272,54 @@ class Embark { } if (cmdPlugin) { - cmdPlugin.uploadCmds[0].cb(); + async.waterfall([ + + function buildDapp(callback){ + engine.logger.debug('building dapp...'); + engine.startMonitor(); + engine.startService("libraryManager"); + engine.startService("web3"); + engine.startService("pipeline"); + engine.startService("codeGenerator"); + engine.startService("deployment"); + engine.startService("ipfs"); + + engine.events.on('outputDone', function () { + engine.logger.debug('deploying...'); + cmdPlugin.uploadCmds[0].cb(); + callback(); + }); + + // build the contracts + engine.contractsManager.build(function(){ + // trigger code generation and dapp webpack + engine.events.emit('asset-changed', engine.contractsManager); + }); + + + }, + function upload(callback){ + + callback(); + } + ], function (err, _result) { + if (err) { + engine.logger.error(err.message); + engine.logger.debug(err.stack); + } else { + engine.logger.info("finished building dapp and deploying to " + platform.underline); + } + + // needed due to child processes + process.exit(); + }); + } else { - console.log(("unknown platform: " + platform).red); - console.log('try "embark upload ipfs" or "embark upload swarm"'.green); + engine.logger.error(("unknown platform: " + platform)); + engine.logger.info('try "embark upload ipfs" or "embark upload swarm"'.green); } + + } runTests(file) {