@@ -197,22 +197,22 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
197
197
public isPlatformPrepared ( projectRoot : string ) : IFuture < boolean > {
198
198
return this . $fs . exists ( path . join ( projectRoot , this . $projectData . projectName , constants . APP_FOLDER_NAME ) ) ;
199
199
}
200
-
200
+
201
201
public addLibrary ( libraryPath : string ) : IFuture < void > {
202
202
return ( ( ) => {
203
203
let extension = path . extname ( libraryPath ) ;
204
204
if ( extension === ".framework" ) {
205
205
this . addDynamicFramework ( libraryPath ) ;
206
206
} else {
207
- this . $errors . failWithoutHelp ( " The bundle at %s does not appear to be a dynamic framework package." , libraryPath ) ;
207
+ this . $errors . failWithoutHelp ( ` The bundle at ${ libraryPath } does not appear to be a dynamic framework package.` ) ;
208
208
}
209
209
} ) . future < void > ( ) ( ) ;
210
210
}
211
-
211
+
212
212
private addDynamicFramework ( frameworkPath : string ) : IFuture < void > {
213
213
return ( ( ) => {
214
214
this . validateFramework ( frameworkPath ) . wait ( ) ;
215
-
215
+
216
216
let targetPath = path . join ( "lib" , this . platformData . normalizedPlatformName ) ;
217
217
let fullTargetPath = path . join ( this . $projectData . projectDir , targetPath ) ;
218
218
this . $fs . ensureDirectoryExists ( fullTargetPath ) . wait ( ) ;
@@ -232,33 +232,34 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
232
232
}
233
233
234
234
let frameworkRelativePath = this . getLibSubpathRelativeToProjectPath ( path . basename ( frameworkPath ) ) ;
235
- project . addFramework ( frameworkRelativePath , { customFramework : true , embed : true } ) ;
235
+ project . addFramework ( frameworkRelativePath , frameworkAddOptions ) ;
236
236
this . savePbxProj ( project ) . wait ( ) ;
237
237
} ) . future < void > ( ) ( ) ;
238
238
}
239
-
239
+
240
240
private addStaticLibrary ( staticLibPath : string ) : IFuture < void > {
241
241
return ( ( ) => {
242
- this . validateStaticLibrary ( staticLibPath ) . wait ( ) ;
242
+ this . validateStaticLibrary ( staticLibPath ) . wait ( ) ;
243
243
// Copy files to lib folder.
244
+ let libraryName = path . basename ( staticLibPath , ".a" ) ;
244
245
let libDestinationPath = path . join ( this . $projectData . projectDir , path . join ( "lib" , this . platformData . normalizedPlatformName ) ) ;
245
- let headersSubpath = path . join ( "include" , path . basename ( staticLibPath , ".a" ) ) ;
246
+ let headersSubpath = path . join ( "include" , libraryName ) ;
246
247
this . $fs . ensureDirectoryExists ( path . join ( libDestinationPath , headersSubpath ) ) . wait ( ) ;
247
248
shell . cp ( "-Rf" , staticLibPath , libDestinationPath ) ;
248
249
shell . cp ( "-Rf" , path . join ( path . dirname ( staticLibPath ) , headersSubpath ) , path . join ( libDestinationPath , "include" ) ) ;
249
-
250
+
250
251
// Add static library to project file and setup header search paths
251
252
let project = this . createPbxProj ( ) ;
252
253
let relativeStaticLibPath = this . getLibSubpathRelativeToProjectPath ( path . basename ( staticLibPath ) ) ;
253
254
project . addFramework ( relativeStaticLibPath ) ;
254
-
255
+
255
256
let relativeHeaderSearchPath = path . join ( this . getLibSubpathRelativeToProjectPath ( headersSubpath ) ) ;
256
257
project . addToHeaderSearchPaths ( { relativePath : relativeHeaderSearchPath } ) ;
257
-
258
- this . generateMobulemap ( path . join ( libDestinationPath , headersSubpath ) , path . basename ( staticLibPath , ".a" ) ) ;
258
+
259
+ this . generateMobulemap ( path . join ( libDestinationPath , headersSubpath ) , libraryName ) ;
259
260
this . savePbxProj ( project ) . wait ( ) ;
260
- } ) . future < void > ( ) ( ) ;
261
- }
261
+ } ) . future < void > ( ) ( ) ;
262
+ }
262
263
263
264
public canUpdatePlatform ( currentVersion : string , newVersion : string ) : IFuture < boolean > {
264
265
return ( ( ) => {
@@ -364,7 +365,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
364
365
public preparePluginNativeCode ( pluginData : IPluginData , opts ?: any ) : IFuture < void > {
365
366
return ( ( ) => {
366
367
let pluginPlatformsFolderPath = pluginData . pluginPlatformsFolderPath ( IOSProjectService . IOS_PLATFORM_NAME ) ;
367
-
368
+
368
369
this . prepareFrameworks ( pluginPlatformsFolderPath , pluginData ) . wait ( ) ;
369
370
this . prepareStaticLibs ( pluginPlatformsFolderPath , pluginData ) . wait ( ) ;
370
371
this . prepareCocoapods ( pluginPlatformsFolderPath ) . wait ( ) ;
@@ -374,7 +375,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
374
375
public removePluginNativeCode ( pluginData : IPluginData ) : IFuture < void > {
375
376
return ( ( ) => {
376
377
let pluginPlatformsFolderPath = pluginData . pluginPlatformsFolderPath ( IOSProjectService . IOS_PLATFORM_NAME ) ;
377
-
378
+
378
379
this . removeFrameworks ( pluginPlatformsFolderPath , pluginData ) . wait ( ) ;
379
380
this . removeStaticLibs ( pluginPlatformsFolderPath , pluginData ) . wait ( ) ;
380
381
this . removeCocoapods ( pluginPlatformsFolderPath ) . wait ( ) ;
@@ -417,7 +418,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
417
418
let filterCallback = ( fileName : string , pluginPlatformsFolderPath : string ) => path . extname ( fileName ) === fileExtension ;
418
419
return this . getAllNativeLibrariesForPlugin ( pluginData , IOSProjectService . IOS_PLATFORM_NAME , filterCallback ) ;
419
420
} ;
420
-
421
+
421
422
private buildPathToXcodeProjectFile ( version : string ) : string {
422
423
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" ) ;
423
424
}
@@ -435,19 +436,20 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
435
436
}
436
437
} ) . future < void > ( ) ( ) ;
437
438
}
438
-
439
+
439
440
private validateStaticLibrary ( libraryPath : string ) : IFuture < void > {
440
441
return ( ( ) => {
441
442
if ( path . extname ( libraryPath ) !== ".a" ) {
442
- this . $errors . failWithoutHelp ( " The bundle at %s does not contain valid '.a' extension." , libraryPath ) ;
443
+ this . $errors . failWithoutHelp ( ` The bundle at ${ libraryPath } does not contain a valid static library in the '.a' file format.` ) ;
443
444
}
444
-
445
- let expectedArchs = [ "armv7" , "arm64" , "x86_64" , " i386"] ;
445
+
446
+ let expectedArchs = [ "armv7" , "arm64" , "i386" ] ;
446
447
let archsInTheFatFile = this . $childProcess . exec ( "lipo -i " + libraryPath ) . wait ( ) ;
447
-
448
- expectedArchs . forEach ( expectedArch => {
448
+
449
+ expectedArchs . forEach ( expectedArch => {
449
450
if ( archsInTheFatFile . indexOf ( expectedArch ) < 0 ) {
450
- this . $errors . failWithoutHelp ( "The static library at %s is not build for all required architectures - %s." , libraryPath , expectedArchs ) ;
451
+ this . $errors . failWithoutHelp ( `The static library at ${ libraryPath } is not built for one or more of the following required architectures:
452
+ ${ expectedArchs . join ( ", " ) } . The static library must be built for all required architectures.` ) ;
451
453
}
452
454
} ) ;
453
455
} ) . future < void > ( ) ( ) ;
@@ -480,7 +482,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
480
482
_ . each ( this . getAllLibsForPluginWithFileExtension ( pluginData , ".framework" ) . wait ( ) , fileName => this . addDynamicFramework ( path . join ( pluginPlatformsFolderPath , fileName ) ) . wait ( ) ) ;
481
483
} ) . future < void > ( ) ( ) ;
482
484
}
483
-
485
+
484
486
private prepareStaticLibs ( pluginPlatformsFolderPath : string , pluginData : IPluginData ) : IFuture < void > {
485
487
return ( ( ) => {
486
488
_ . each ( this . getAllLibsForPluginWithFileExtension ( pluginData , ".a" ) . wait ( ) , fileName => this . addStaticLibrary ( path . join ( pluginPlatformsFolderPath , fileName ) ) . wait ( ) ) ;
@@ -490,7 +492,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
490
492
private prepareCocoapods ( pluginPlatformsFolderPath : string , opts ?: any ) : IFuture < void > {
491
493
return ( ( ) => {
492
494
let pluginPodFilePath = path . join ( pluginPlatformsFolderPath , "Podfile" ) ;
493
-
495
+
494
496
if ( this . $fs . exists ( pluginPodFilePath ) . wait ( ) ) {
495
497
if ( ! this . $fs . exists ( this . projectPodFilePath ) . wait ( ) ) {
496
498
this . $fs . writeFile ( this . projectPodFilePath , "use_frameworks!\n" ) . wait ( ) ;
@@ -518,16 +520,16 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
518
520
this . savePbxProj ( project ) . wait ( ) ;
519
521
} ) . future < void > ( ) ( ) ;
520
522
}
521
-
523
+
522
524
private removeStaticLibs ( pluginPlatformsFolderPath : string , pluginData : IPluginData ) : IFuture < void > {
523
525
return ( ( ) => {
524
526
let project = this . createPbxProj ( ) ;
525
-
527
+
526
528
_ . each ( this . getAllLibsForPluginWithFileExtension ( pluginData , ".a" ) . wait ( ) , fileName => {
527
529
let staticLibPath = path . join ( pluginPlatformsFolderPath , fileName ) ;
528
530
let relativeStaticLibPath = this . getLibSubpathRelativeToProjectPath ( path . basename ( staticLibPath ) ) ;
529
- project . removeFramework ( relativeStaticLibPath ) ;
530
-
531
+ project . removeFramework ( relativeStaticLibPath ) ;
532
+
531
533
let headersSubpath = path . join ( "include" , path . basename ( staticLibPath , ".a" ) ) ;
532
534
let relativeHeaderSearchPath = path . join ( this . getLibSubpathRelativeToProjectPath ( headersSubpath ) ) ;
533
535
project . removeFromHeaderSearchPaths ( { relativePath : relativeHeaderSearchPath } ) ;
@@ -557,23 +559,21 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
557
559
private buildPodfileContent ( pluginPodFilePath : string , pluginPodFileContent : string ) : string {
558
560
return `# Begin Podfile - ${ pluginPodFilePath } ${ os . EOL } ${ pluginPodFileContent } ${ os . EOL } # End Podfile ${ os . EOL } ` ;
559
561
}
560
-
562
+
561
563
private generateMobulemap ( headersFolderPath : string , libraryName : string ) : void {
562
564
let headersFilter = ( fileName : string , containingFolderPath : string ) => ( path . extname ( fileName ) === ".h" && this . $fs . getFsStats ( path . join ( containingFolderPath , fileName ) ) . wait ( ) . isFile ( ) ) ;
563
565
let headersFolderContents = this . $fs . readDirectory ( headersFolderPath ) . wait ( ) ;
564
566
let headers = _ ( headersFolderContents ) . filter ( item => headersFilter ( item , headersFolderPath ) ) . value ( ) ;
565
-
567
+
566
568
if ( ! headers . length ) {
567
569
this . $fs . deleteFile ( path . join ( headersFolderPath , "module.modulemap" ) ) . wait ( ) ;
568
570
return ;
569
571
}
570
-
571
- headers . forEach ( function ( currentValue , index , array ) {
572
- array [ index ] = "header \"" + currentValue + "\"" ;
573
- } ) ;
574
-
572
+
573
+ headers = _ . map ( headers , value => `header "${ value } "` ) ;
574
+
575
575
let modulemap = `module ${ libraryName } { explicit module ${ libraryName } { ${ headers . join ( " " ) } } }` ;
576
- this . $fs . writeFile ( path . join ( headersFolderPath , "module.modulemap" ) , modulemap , "utf8" ) . wait ( ) ;
576
+ this . $fs . writeFile ( path . join ( headersFolderPath , "module.modulemap" ) , modulemap ) . wait ( ) ;
577
577
}
578
578
}
579
579
0 commit comments