diff --git a/lib/index.js b/lib/index.js index 032287e13..0e0eefefd 100644 --- a/lib/index.js +++ b/lib/index.js @@ -327,34 +327,16 @@ class Embark { engine.startService("codeGenerator"); callback(); }, - function setupStoragePlugin(callback) { + function listLoadedPlugin(callback) { let pluginList = engine.plugins.listPlugins(); if (pluginList.length > 0) { engine.logger.info(__("loaded plugins") + ": " + pluginList.join(", ")); } - - // check use has input existing storage plugin - let cmdPlugins = engine.plugins.getPluginsFor('uploadCmds'); - - if (cmdPlugins.length > 0) { - cmdPlugin = cmdPlugins.find((pluginCmd) => { - return pluginCmd.uploadCmds.some(uploadCmd => { - return uploadCmd.cmd === platform; - }); - }); - } - if (!cmdPlugin) { - return callback({message: __('platform "{{platform}}" is specified as the upload provider, however no plugins have registered an upload command for "{{platform}}".', {platform: platform})}); - } callback(); }, function deploy(callback) { engine.events.on('outputDone', function () { - cmdPlugin.uploadCmds[0].cb() - .then((success) => { - callback(null, success); - }) - .catch(callback); + embark.events.request("storage:upload", callback); }); engine.events.on('check:backOnline:Ethereum', function () { engine.logger.info(__('Ethereum node detected') + '..'); diff --git a/lib/modules/ipfs/index.js b/lib/modules/ipfs/index.js index ee8829de9..24eb1d485 100644 --- a/lib/modules/ipfs/index.js +++ b/lib/modules/ipfs/index.js @@ -24,7 +24,7 @@ class IPFS { configIpfsBin: this.storageConfig.ipfs_bin || "ipfs" }); - this.embark.registerUploadCommand('ipfs', upload_ipfs.deploy.bind(upload_ipfs)); + this.events.setCommandHandler('storage:upload:ipfs', upload_ipfs.deploy.bind(upload_ipfs)); } setServiceCheck() { diff --git a/lib/modules/storage/index.js b/lib/modules/storage/index.js index c63bce60f..0f9a2f320 100644 --- a/lib/modules/storage/index.js +++ b/lib/modules/storage/index.js @@ -8,6 +8,7 @@ const constants = require('../../constants'); class Storage { constructor(embark, options){ + const self = this; this._embark = embark; this._options = options; this._storageConfig = options.storageConfig; @@ -33,6 +34,14 @@ class Storage { if(_.contains(options.context, constants.contexts.upload) || _.contains(options.context, constants.contexts.run)){ this.startStorageProcesses(); } + + embark.events.setCommandHandler('storage:upload', (cb) => { + let platform = options.storageConfig.upload.provider; + + if (['swarm', 'ipfs'].indexOf(platform) === -1) { + return cb({message: __('platform "{{platform}}" is specified as the upload provider, however no plugins have registered an upload command for "{{platform}}".', {platform: platform})}); + } + }); } _checkStorageEndpoint(platform, callback) { diff --git a/lib/modules/swarm/index.js b/lib/modules/swarm/index.js index fce7bad2e..fb62b9ad7 100644 --- a/lib/modules/swarm/index.js +++ b/lib/modules/swarm/index.js @@ -30,7 +30,7 @@ class Swarm { bzz: this.bzz }); - this.embark.registerUploadCommand('swarm', this.upload_swarm.deploy.bind(this.upload_swarm)); + this.events.setCommandHandler('storage:upload:swarm', this.upload_swarm.deploy.bind(this.upload_swarm)); } setServiceCheck() {