1
1
import { Config , Events , fs , TemplateGenerator } from 'embark-core' ;
2
2
import { Engine } from 'embark-engine' ;
3
3
import { __ } from 'embark-i18n' ;
4
- import { dappPath , embarkPath , joinPath , setUpEnv } from 'embark-utils' ;
4
+ import { dappPath , joinPath , setUpEnv } from 'embark-utils' ;
5
5
import { Logger , LogLevels } from 'embark-logger' ;
6
6
let async = require ( 'async' ) ;
7
7
const constants = require ( 'embark-core/constants' ) ;
@@ -297,12 +297,6 @@ class EmbarkController {
297
297
engine . logger . info ( __ ( "loaded plugins" ) + ": " + pluginList . join ( ", " ) ) ;
298
298
}
299
299
300
- engine . events . on ( 'deployment:deployContracts:afterAll' , ( ) => {
301
- engine . events . request ( 'pipeline:generateAll' , ( ) => {
302
- engine . events . emit ( 'outputDone' ) ;
303
- } ) ;
304
- } ) ;
305
-
306
300
let plugin = engine . plugins . createPlugin ( 'cmdcontrollerplugin' , { } ) ;
307
301
plugin . registerActionForEvent ( "embark:engine:started" , async ( _ , cb ) => {
308
302
try {
@@ -319,31 +313,25 @@ class EmbarkController {
319
313
320
314
engine . startEngine ( async ( ) => {
321
315
try {
322
- await compileAndDeploySmartContracts ( engine ) ;
316
+ if ( options . onlyCompile ) {
317
+ await compileSmartContracts ( engine ) ;
318
+ engine . logger . info ( "Finished compiling" . underline ) ;
319
+ } else {
320
+ await compileAndDeploySmartContracts ( engine ) ;
321
+ engine . logger . info ( "Finished deploying" . underline ) ;
322
+ }
323
323
} catch ( e ) {
324
324
return callback ( e ) ;
325
325
}
326
326
callback ( ) ;
327
327
} ) ;
328
- } ,
329
- function waitForWriteFinish ( callback ) {
330
- if ( options . onlyCompile ) {
331
- engine . logger . info ( "Finished compiling" . underline ) ;
332
- return callback ( null , true ) ;
333
- }
334
- engine . logger . info ( "Finished deploying" . underline ) ;
335
- engine . events . on ( 'outputDone' , ( err ) => {
336
- engine . logger . info ( __ ( "Finished building" ) . underline ) ;
337
- callback ( err , true ) ;
338
- } ) ;
339
-
340
328
}
341
- ] , function ( err , canExit ) {
329
+ ] , function ( err ) {
342
330
if ( err ) {
343
331
engine . logger . error ( err . message || err ) ;
344
332
}
345
333
// TODO: this should be moved out and determined somewhere else
346
- if ( canExit || ! engine . config . contractsConfig . afterDeploy || ! engine . config . contractsConfig . afterDeploy . length ) {
334
+ if ( ! engine . config . contractsConfig . afterDeploy || ! engine . config . contractsConfig . afterDeploy . length ) {
347
335
process . exit ( err ? 1 : 0 ) ;
348
336
}
349
337
engine . logger . info ( __ ( 'Waiting for after deploy to finish...' ) ) ;
@@ -630,7 +618,7 @@ class EmbarkController {
630
618
return callback ( e ) ;
631
619
}
632
620
callback ( ) ;
633
- } ) ( )
621
+ } ) ( ) ;
634
622
} ,
635
623
function generateUI ( callback ) {
636
624
if ( engine . config . embarkConfig . app ) {
@@ -838,13 +826,17 @@ class EmbarkController {
838
826
839
827
module . exports = EmbarkController ;
840
828
829
+ async function compileSmartContracts ( engine ) {
830
+ const contractsFiles = await engine . events . request2 ( "config:contractsFiles" ) ;
831
+ const compiledContracts = await engine . events . request2 ( "compiler:contracts:compile" , contractsFiles ) ;
832
+ const _contractsConfig = await engine . events . request2 ( "config:contractsConfig" ) ;
833
+ const contractsConfig = cloneDeep ( _contractsConfig ) ;
834
+ return engine . events . request2 ( "contracts:build" , contractsConfig , compiledContracts ) ;
835
+ }
836
+
841
837
async function compileAndDeploySmartContracts ( engine ) {
842
838
try {
843
- let contractsFiles = await engine . events . request2 ( "config:contractsFiles" ) ;
844
- let compiledContracts = await engine . events . request2 ( "compiler:contracts:compile" , contractsFiles ) ;
845
- let _contractsConfig = await engine . events . request2 ( "config:contractsConfig" ) ;
846
- let contractsConfig = cloneDeep ( _contractsConfig ) ;
847
- let [ contractsList , contractDependencies ] = await engine . events . request2 ( "contracts:build" , contractsConfig , compiledContracts ) ;
839
+ const [ contractsList , contractDependencies ] = await compileSmartContracts ( engine ) ;
848
840
await engine . events . request2 ( "deployment:contracts:deploy" , contractsList , contractDependencies ) ;
849
841
await engine . events . request2 ( 'pipeline:generateAll' ) ;
850
842
engine . events . emit ( 'outputDone' ) ;
0 commit comments