@@ -182,13 +182,11 @@ class IOSProjectService implements IPlatformProjectService {
182
182
this . $fs . ensureDirectoryExists ( targetPath ) . wait ( ) ;
183
183
shell . cp ( "-R" , libraryPath , targetPath ) ;
184
184
185
- var pbxProjPath = path . join ( platformData . projectRoot , this . $projectData . projectName + ".xcodeproj" , "project.pbxproj" ) ;
186
- var project = new xcode . project ( pbxProjPath ) ;
187
- project . parseSync ( ) ;
185
+ let project = this . xcodeproj ;
188
186
189
187
project . addFramework ( path . join ( targetPath , frameworkName + ".framework" ) , { customFramework : true , embed : true } ) ;
190
188
project . updateBuildProperty ( "IPHONEOS_DEPLOYMENT_TARGET" , "8.0" ) ;
191
- this . $fs . writeFile ( pbxProjPath , project . writeSync ( ) ) . wait ( ) ;
189
+ this . saveXcodeproj ( project ) . wait ( ) ;
192
190
this . $logger . info ( "The iOS Deployment Target is now 8.0 in order to support Cocoa Touch Frameworks." ) ;
193
191
} ) . future < void > ( ) ( ) ;
194
192
}
@@ -221,11 +219,58 @@ class IOSProjectService implements IPlatformProjectService {
221
219
shell . cp ( "-R" , path . join ( cachedPackagePath , "*" ) , path . join ( this . platformData . projectRoot , util . format ( "%s.xcodeproj" , this . $projectData . projectName ) ) ) ;
222
220
this . $logger . info ( "Copied from %s at %s." , cachedPackagePath , this . platformData . projectRoot ) ;
223
221
224
-
225
222
var pbxprojFilePath = path . join ( this . platformData . projectRoot , this . $projectData . projectName + IOSProjectService . XCODE_PROJECT_EXT_NAME , "project.pbxproj" ) ;
226
223
this . replaceFileContent ( pbxprojFilePath ) . wait ( ) ;
227
224
} ) . future < void > ( ) ( ) ;
228
225
}
226
+
227
+ public prepareProject ( ) : IFuture < void > {
228
+ return ( ( ) => {
229
+ let project = this . xcodeproj ;
230
+ let resources = project . pbxGroupByName ( "Resources" ) ;
231
+ let references = project . pbxFileReferenceSection ( ) ;
232
+
233
+ let images = _ ( < any [ ] > resources . children )
234
+ . map ( resource => references [ resource . value ] )
235
+ . value ( ) ;
236
+
237
+ let imageNames = _ . map ( images , image => image . name . replace ( / \" / g, "" ) ) ;
238
+ let currentImageNames = this . $fs . readDirectory ( this . platformData . appResourcesDestinationDirectoryPath ) . wait ( ) ;
239
+
240
+ this . $logger . trace ( "Images from xcode project" ) ;
241
+ this . $logger . trace ( imageNames ) ;
242
+ this . $logger . trace ( "Current images from App_Resources" ) ;
243
+ this . $logger . trace ( currentImageNames ) ;
244
+
245
+ if ( imageNames . length !== currentImageNames . length ) {
246
+ let imagesToAdd = _ . difference ( currentImageNames , imageNames ) ;
247
+ this . $logger . trace ( `New images to add into xcode project: ${ imagesToAdd . length !== 0 ? imagesToAdd . join ( ", " ) : "" } ` ) ;
248
+ _ . each ( imagesToAdd , image => project . addResourceFile ( path . join ( this . platformData . appResourcesDestinationDirectoryPath , image ) ) ) ;
249
+
250
+ let imagesToRemove = _ . difference ( imageNames , currentImageNames ) ;
251
+ this . $logger . trace ( `Images to remove from xcode project: ${ imagesToRemove . length !== 0 ? imagesToRemove . join ( ", " ) : "" } ` ) ;
252
+ _ . each ( imagesToRemove , image => project . removeResourceFile ( path . join ( this . platformData . appResourcesDestinationDirectoryPath , image ) ) ) ;
253
+
254
+ this . saveXcodeproj ( project ) . wait ( ) ;
255
+ }
256
+
257
+ } ) . future < void > ( ) ( ) ;
258
+ }
259
+
260
+ private get pbxProjPath ( ) : string {
261
+ return path . join ( this . platformData . projectRoot , this . $projectData . projectName + ".xcodeproj" , "project.pbxproj" ) ;
262
+ }
263
+
264
+ private get xcodeproj ( ) : any {
265
+ let project = new xcode . project ( this . pbxProjPath ) ;
266
+ project . parseSync ( ) ;
267
+
268
+ return project ;
269
+ }
270
+
271
+ private saveXcodeproj ( project : any ) : IFuture < void > {
272
+ return this . $fs . writeFile ( this . pbxProjPath , project . writeSync ( ) ) ;
273
+ }
229
274
230
275
private buildPathToXcodeProjectFile ( version : string ) : string {
231
276
return path . join ( this . $npmInstallationManager . getCachedPackagePath ( this . platformData . frameworkPackageName , version ) , constants . PROJECT_FRAMEWORK_FOLDER_NAME , util . format ( "%s.xcodeproj" , IOSProjectService . IOS_PROJECT_NAME_PLACEHOLDER ) , "project.pbxproj" ) ;
0 commit comments