11///<reference path="../.d.ts"/>
22
3+ import Future = require( "fibers/future" ) ;
34import path = require( "path" ) ;
45import shell = require( "shelljs" ) ;
56import util = require( "util" ) ;
@@ -86,9 +87,16 @@ class IOSProjectService implements IPlatformProjectService {
8687 return ( ( ) => {
8788 var appSourceDirectory = path . join ( this . $projectData . projectDir , constants . APP_FOLDER_NAME ) ;
8889 var appDestinationDirectory = path . join ( platformData . projectRoot , this . $projectData . projectName ) ;
90+ var resDirectory = path . join ( platformData . projectRoot , this . $projectData . projectName , "Resources" , "icons" ) ;
8991
9092 shell . cp ( "-r" , path . join ( appSourceDirectory , "*" ) , appDestinationDirectory ) ;
9193
94+ var appResourcesDirectoryPath = path . join ( appDestinationDirectory , constants . APP_RESOURCES_FOLDER_NAME ) ;
95+ if ( this . $fs . exists ( appResourcesDirectoryPath ) . wait ( ) ) {
96+ shell . cp ( "-r" , path . join ( appResourcesDirectoryPath , platformData . normalizedPlatformName , "*" ) , resDirectory ) ;
97+ this . $fs . deleteDirectory ( appResourcesDirectoryPath ) . wait ( ) ;
98+ }
99+
92100 return appDestinationDirectory ;
93101 } ) . future < string > ( ) ( ) ;
94102 }
@@ -120,8 +128,7 @@ class IOSProjectService implements IPlatformProjectService {
120128 ] ) ;
121129 }
122130
123- var childProcess = this . $childProcess . spawn ( "xcodebuild" , args , { cwd : options , stdio : 'inherit' } ) ;
124- this . $fs . futureFromEvent ( childProcess , "exit" ) . wait ( ) ;
131+ this . spawn ( "xcodebuild" , args , "exit" , { cwd : options , stdio : 'inherit' } ) . wait ( ) ;
125132
126133 if ( options . device ) {
127134 var buildOutputPath = path . join ( projectRoot , "build" , options . device ? "device" : "emulator" ) ;
@@ -134,12 +141,29 @@ class IOSProjectService implements IPlatformProjectService {
134141 "-o" , path . join ( buildOutputPath , this . $projectData . projectName + ".ipa" )
135142 ] ;
136143
137- var childProcess = this . $childProcess . spawn ( "xcrun" , xcrunArgs , { cwd : options , stdio : 'inherit' } ) ;
138- this . $fs . futureFromEvent ( childProcess , "exit" ) . wait ( ) ;
144+ this . spawn ( "xcrun" , xcrunArgs , "exit" , { cwd : options , stdio : 'inherit' } ) . wait ( ) ;
139145 }
140146 } ) . future < void > ( ) ( ) ;
141147 }
142148
149+ private spawn ( command : string , args : string [ ] , event : string , options ?: any ) : IFuture < void > { // event should be exit or close
150+ var future = new Future < void > ( ) ;
151+ var childProcess = this . $childProcess . spawn ( command , args , options ) ;
152+ childProcess . once ( event , ( ) => {
153+ var args = _ . toArray ( arguments ) ;
154+ var statusCode = args [ 0 ] ;
155+ var signal = args [ 1 ] ;
156+
157+ if ( statusCode !== 0 ) {
158+ future . throw ( util . format ( "Command %s exited with code %s" , command , statusCode ) ) ;
159+ } else {
160+ future . return ( ) ;
161+ }
162+ } ) ;
163+
164+ return future ;
165+ }
166+
143167 private replaceFileContent ( file : string ) : IFuture < void > {
144168 return ( ( ) => {
145169 var fileContent = this . $fs . readText ( file ) . wait ( ) ;
0 commit comments