@@ -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,53 @@ 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
+ if ( imageNames . length !== currentImageNames . length ) {
241
+ let imagesToAdd = _ . difference ( currentImageNames , imageNames ) ;
242
+ this . $logger . trace ( `New images to add into xcode project: ${ imagesToAdd . length !== 0 ? imagesToAdd . join ( ", " ) : "" } ` ) ;
243
+ _ . each ( imagesToAdd , image => project . addResourceFile ( path . join ( this . platformData . appResourcesDestinationDirectoryPath , image ) ) ) ;
244
+
245
+ let imagesToRemove = _ . difference ( imageNames , currentImageNames ) ;
246
+ this . $logger . trace ( `Images to remove from xcode project: ${ imagesToRemove . length !== 0 ? imagesToRemove . join ( ", " ) : "" } ` ) ;
247
+ _ . each ( imagesToRemove , image => project . removeResourceFile ( path . join ( this . platformData . appResourcesDestinationDirectoryPath , image ) ) ) ;
248
+
249
+ this . saveXcodeproj ( project ) . wait ( ) ;
250
+ }
251
+
252
+ } ) . future < void > ( ) ( ) ;
253
+ }
254
+
255
+ private get pbxProjPath ( ) : string {
256
+ return path . join ( this . platformData . projectRoot , this . $projectData . projectName + ".xcodeproj" , "project.pbxproj" ) ;
257
+ }
258
+
259
+ private get xcodeproj ( ) : any {
260
+ let project = new xcode . project ( this . pbxProjPath ) ;
261
+ project . parseSync ( ) ;
262
+
263
+ return project ;
264
+ }
265
+
266
+ private saveXcodeproj ( project : any ) : IFuture < void > {
267
+ return this . $fs . writeFile ( this . pbxProjPath , project . writeSync ( ) ) ;
268
+ }
229
269
230
270
private buildPathToXcodeProjectFile ( version : string ) : string {
231
271
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