@@ -147,15 +147,16 @@ class Embark {
147147 } ) ;
148148 }
149149
150- build ( options ) {
151-
152- let engine = new Engine ( {
153- env : options . env ,
154- version : this . version ,
155- embarkConfig : 'embark.json' ,
156- interceptLogs : false
157- } ) ;
158- engine . init ( ) ;
150+ build ( options , engine , continueProcessing ) {
151+ if ( ! engine ) {
152+ engine = new Engine ( {
153+ env : options . env ,
154+ version : this . version ,
155+ embarkConfig : 'embark.json' ,
156+ interceptLogs : false
157+ } ) ;
158+ engine . init ( ) ;
159+ }
159160
160161 async . waterfall ( [
161162 function startServices ( callback ) {
@@ -185,7 +186,9 @@ class Embark {
185186 engine . logger . info ( "finished building" . underline ) ;
186187 }
187188 // needed due to child processes
188- process . exit ( ) ;
189+ if ( err || ! continueProcessing ) {
190+ process . exit ( ) ;
191+ }
189192 } ) ;
190193 }
191194
@@ -247,29 +250,68 @@ class Embark {
247250 }
248251
249252 // TODO: should deploy if it hasn't already
250- upload ( platform ) {
251- let options = {
252- buildDir : 'dist/' ,
253- storageConfig : this . config . storageConfig
254- } ;
253+ upload ( platform , options ) {
254+
255+ options . buildDir = 'dist/' ;
256+ options . storageConfig = this . config . storageConfig ;
257+
258+ // initialise embark engine
259+ let engine = new Engine ( {
260+ env : options . env ,
261+ version : this . version ,
262+ embarkConfig : options . embarkConfig || 'embark.json' ,
263+ logfile : options . logfile
264+ } ) ;
265+ engine . init ( ) ;
255266
267+ // load plugins
256268 this . plugins . loadInternalPlugin ( 'ipfs' , options ) ;
257269 this . plugins . loadInternalPlugin ( 'swarm' , options ) ;
258270
259- let cmdPlugins = this . plugins . getPluginsFor ( 'uploadCmds' ) ;
271+ let plugins = this . plugins ;
260272 let cmdPlugin ;
261- if ( cmdPlugins . length > 0 ) {
262- cmdPlugin = cmdPlugins . find ( ( pluginCmd ) => {
263- return pluginCmd . name == platform ;
264- } ) ;
265- }
273+ let self = this ;
274+ async . waterfall ( [
275+ function setupStoragePlugin ( callback ) {
276+ // check use has input existing storage plugin
277+ let cmdPlugins = plugins . getPluginsFor ( 'uploadCmds' ) ;
278+
279+ if ( cmdPlugins . length > 0 ) {
280+ cmdPlugin = cmdPlugins . find ( ( pluginCmd ) => {
281+ return pluginCmd . name == platform ;
282+ } ) ;
283+ }
284+ if ( ! cmdPlugin ) {
285+ engine . logger . info ( 'try "embark upload ipfs" or "embark upload swarm"' . green ) ;
286+ callback ( { message : 'unknown platform: ' + platform } ) ;
287+ } else {
288+ callback ( ) ;
289+ }
290+ } ,
291+ function buildAndDeployContracts ( callback ) {
292+ // 2. upload to storage (outputDone event triggered after webpack finished)
293+ engine . events . on ( 'outputDone' , function ( ) {
294+ engine . logger . info ( 'deploying to ' + platform + '...' ) ;
295+ cmdPlugin . uploadCmds [ 0 ] . cb ( )
296+ . then ( ( success ) => {
297+ callback ( null , success ) ;
298+ } )
299+ . catch ( callback ) ;
300+ } ) ;
301+ // 1. build the contracts and dapp webpack
302+ self . build ( options , engine , true ) ;
303+ }
304+ ] , function ( err , _result ) {
305+ if ( err ) {
306+ engine . logger . error ( err . message ) ;
307+ engine . logger . debug ( err . stack ) ;
308+ } else {
309+ engine . logger . info ( "finished building dapp and deploying to " + platform . underline ) ;
310+ }
266311
267- if ( cmdPlugin ) {
268- cmdPlugin . uploadCmds [ 0 ] . cb ( ) ;
269- } else {
270- console . log ( ( "unknown platform: " + platform ) . red ) ;
271- console . log ( 'try "embark upload ipfs" or "embark upload swarm"' . green ) ;
272- }
312+ // needed due to child processes
313+ process . exit ( ) ;
314+ } ) ;
273315 }
274316
275317 runTests ( file ) {
0 commit comments