@@ -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 . createPbxProj ( ) ;
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 . savePbxProj ( 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,63 @@ 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 . createPbxProj ( ) ;
230
+ let resources = project . pbxGroupByName ( "Resources" ) ;
231
+
232
+ if ( resources ) {
233
+ let references = project . pbxFileReferenceSection ( ) ;
234
+
235
+ let xcodeProjectImages = _ . map ( < any [ ] > resources . children , resource => this . replace ( references [ resource . value ] . name ) ) ;
236
+ this . $logger . trace ( "Images from Xcode project" ) ;
237
+ this . $logger . trace ( xcodeProjectImages ) ;
238
+
239
+ let appResourcesImages = this . $fs . readDirectory ( this . platformData . appResourcesDestinationDirectoryPath ) . wait ( ) ;
240
+ this . $logger . trace ( "Current images from App_Resources" ) ;
241
+ this . $logger . trace ( appResourcesImages ) ;
242
+
243
+ let imagesToAdd = _ . difference ( appResourcesImages , xcodeProjectImages ) ;
244
+ this . $logger . trace ( `New images to add into xcode project: ${ imagesToAdd . join ( ", " ) } ` ) ;
245
+ _ . each ( imagesToAdd , image => project . addResourceFile ( path . relative ( this . platformData . projectRoot , path . join ( this . platformData . appResourcesDestinationDirectoryPath , image ) ) ) ) ;
246
+
247
+ let imagesToRemove = _ . difference ( xcodeProjectImages , appResourcesImages ) ;
248
+ this . $logger . trace ( `Images to remove from xcode project: ${ imagesToRemove . join ( ", " ) } ` ) ;
249
+ _ . each ( imagesToRemove , image => project . removeResourceFile ( path . join ( this . platformData . appResourcesDestinationDirectoryPath , image ) ) ) ;
250
+
251
+ this . savePbxProj ( project ) . wait ( ) ;
252
+ }
253
+
254
+ } ) . future < void > ( ) ( ) ;
255
+ }
256
+
257
+ private replace ( name : string ) : string {
258
+ if ( _ . startsWith ( name , '"' ) ) {
259
+ name = name . substr ( 1 , name . length - 2 ) ;
260
+ }
261
+
262
+ return name . replace ( / \\ \" / g, "\"" ) ;
263
+ }
264
+
265
+ private get pbxProjPath ( ) : string {
266
+ return path . join ( this . platformData . projectRoot , this . $projectData . projectName + ".xcodeproj" , "project.pbxproj" ) ;
267
+ }
268
+
269
+ private createPbxProj ( ) : any {
270
+ let project = new xcode . project ( this . pbxProjPath ) ;
271
+ project . parseSync ( ) ;
272
+
273
+ return project ;
274
+ }
275
+
276
+ private savePbxProj ( project : any ) : IFuture < void > {
277
+ return this . $fs . writeFile ( this . pbxProjPath , project . writeSync ( ) ) ;
278
+ }
229
279
230
280
private buildPathToXcodeProjectFile ( version : string ) : string {
231
281
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