11import { Config , Events , fs , TemplateGenerator } from 'embark-core' ;
22import { Engine } from 'embark-engine' ;
33import { __ } from 'embark-i18n' ;
4- import { dappPath , embarkPath , joinPath , setUpEnv } from 'embark-utils' ;
4+ import { dappPath , joinPath , setUpEnv } from 'embark-utils' ;
55import { Logger , LogLevels } from 'embark-logger' ;
66let async = require ( 'async' ) ;
77const constants = require ( 'embark-core/constants' ) ;
@@ -297,12 +297,6 @@ class EmbarkController {
297297 engine . logger . info ( __ ( "loaded plugins" ) + ": " + pluginList . join ( ", " ) ) ;
298298 }
299299
300- engine . events . on ( 'deployment:deployContracts:afterAll' , ( ) => {
301- engine . events . request ( 'pipeline:generateAll' , ( ) => {
302- engine . events . emit ( 'outputDone' ) ;
303- } ) ;
304- } ) ;
305-
306300 let plugin = engine . plugins . createPlugin ( 'cmdcontrollerplugin' , { } ) ;
307301 plugin . registerActionForEvent ( "embark:engine:started" , async ( _ , cb ) => {
308302 try {
@@ -319,31 +313,25 @@ class EmbarkController {
319313
320314 engine . startEngine ( async ( ) => {
321315 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+ }
323323 } catch ( e ) {
324324 return callback ( e ) ;
325325 }
326326 callback ( ) ;
327327 } ) ;
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-
340328 }
341- ] , function ( err , canExit ) {
329+ ] , function ( err ) {
342330 if ( err ) {
343331 engine . logger . error ( err . message || err ) ;
344332 }
345333 // 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 ) {
347335 process . exit ( err ? 1 : 0 ) ;
348336 }
349337 engine . logger . info ( __ ( 'Waiting for after deploy to finish...' ) ) ;
@@ -630,7 +618,7 @@ class EmbarkController {
630618 return callback ( e ) ;
631619 }
632620 callback ( ) ;
633- } ) ( )
621+ } ) ( ) ;
634622 } ,
635623 function generateUI ( callback ) {
636624 if ( engine . config . embarkConfig . app ) {
@@ -838,13 +826,17 @@ class EmbarkController {
838826
839827module . exports = EmbarkController ;
840828
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+
841837async function compileAndDeploySmartContracts ( engine ) {
842838 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 ) ;
848840 await engine . events . request2 ( "deployment:contracts:deploy" , contractsList , contractDependencies ) ;
849841 await engine . events . request2 ( 'pipeline:generateAll' ) ;
850842 engine . events . emit ( 'outputDone' ) ;
0 commit comments