@@ -75,10 +75,12 @@ function createTestInjector(projectPath: string, projectName: string, xcode?: IX
75
75
projectId : "" ,
76
76
projectIdentifiers : { android : "" , ios : "" } ,
77
77
projectDir : "" ,
78
- appDirectoryPath : ""
78
+ appDirectoryPath : "" ,
79
+ appResourcesDirectoryPath : ""
79
80
} ) ;
80
81
projectData . projectDir = temp . mkdirSync ( "projectDir" ) ;
81
82
projectData . appDirectoryPath = path . join ( projectData . projectDir , "app" ) ;
83
+ projectData . appResourcesDirectoryPath = path . join ( projectData . appDirectoryPath , "App_Resources" ) ;
82
84
testInjector . register ( "projectData" , projectData ) ;
83
85
testInjector . register ( "projectHelper" , { } ) ;
84
86
testInjector . register ( "xcodeSelectService" , { } ) ;
@@ -339,6 +341,69 @@ describe("Cocoapods support", () => {
339
341
if ( require ( "os" ) . platform ( ) !== "darwin" ) {
340
342
console . log ( "Skipping Cocoapods tests. They cannot work on windows" ) ;
341
343
} else {
344
+ it ( "adds а base Podfile" , async ( ) => {
345
+ const projectName = "projectDirectory" ;
346
+ const projectPath = temp . mkdirSync ( projectName ) ;
347
+
348
+ const testInjector = createTestInjector ( projectPath , projectName ) ;
349
+ const fs : IFileSystem = testInjector . resolve ( "fs" ) ;
350
+ const cocoapodsService = testInjector . resolve ( "cocoapodsService" )
351
+
352
+ const packageJsonData = {
353
+ "name" : "myProject" ,
354
+ "version" : "0.1.0" ,
355
+ "nativescript" : {
356
+ "id" : "org.nativescript.myProject" ,
357
+ "tns-ios" : {
358
+ "version" : "1.0.0"
359
+ }
360
+ }
361
+ } ;
362
+ fs . writeJson ( path . join ( projectPath , "package.json" ) , packageJsonData ) ;
363
+
364
+ const platformsFolderPath = path . join ( projectPath , "platforms" , "ios" ) ;
365
+ fs . createDirectory ( platformsFolderPath ) ;
366
+
367
+ const iOSProjectService = testInjector . resolve ( "iOSProjectService" ) ;
368
+ iOSProjectService . createPbxProj = ( ) => {
369
+ return {
370
+ updateBuildProperty : ( ) => { return { } ; } ,
371
+ pbxXCBuildConfigurationSection : ( ) => { return { } ; } ,
372
+ } ;
373
+ } ;
374
+ iOSProjectService . savePbxProj = ( ) : Promise < void > => Promise . resolve ( ) ;
375
+
376
+ const projectData : IProjectData = testInjector . resolve ( "projectData" ) ;
377
+ const basePodfileModuleName = "BasePodfile" ;
378
+
379
+ const basePodfilePath = path . join ( projectData . appDirectoryPath , "App_Resources" , "iOS" , "Podfile" ) ;
380
+ const pluginPodfileContent = [ "source 'https://github.com/CocoaPods/Specs.git'" , "platform :ios, '8.1'" , "pod 'GoogleMaps'" ] . join ( "\n" ) ;
381
+ fs . writeFile ( basePodfilePath , pluginPodfileContent ) ;
382
+
383
+ projectData . podfilePath = basePodfilePath ;
384
+
385
+ cocoapodsService . applyPodfileToProject ( basePodfileModuleName , basePodfilePath , projectData , iOSProjectService . getPlatformData ( projectData ) . projectRoot ) ;
386
+
387
+ const projectPodfilePath = path . join ( platformsFolderPath , "Podfile" ) ;
388
+ assert . isTrue ( fs . exists ( projectPodfilePath ) ) ;
389
+
390
+ let actualProjectPodfileContent = fs . readText ( projectPodfilePath ) ;
391
+ let expectedProjectPodfileContent = [ "use_frameworks!\n" ,
392
+ `target "${ projectName } " do` ,
393
+ `# Begin Podfile - ${ basePodfilePath } ` ,
394
+ `${ pluginPodfileContent } ` ,
395
+ "# End Podfile" ,
396
+ "end" ]
397
+ . join ( "\n" ) ;
398
+ assert . equal ( actualProjectPodfileContent , expectedProjectPodfileContent ) ;
399
+
400
+ fs . deleteFile ( basePodfilePath ) ;
401
+
402
+ cocoapodsService . applyPodfileToProject ( basePodfileModuleName , basePodfilePath , projectData , iOSProjectService . getPlatformData ( projectData ) . projectRoot ) ;
403
+ assert . isFalse ( fs . exists ( projectPodfilePath ) ) ;
404
+
405
+ } ) ;
406
+
342
407
it ( "adds plugin with Podfile" , async ( ) => {
343
408
const projectName = "projectDirectory" ;
344
409
const projectPath = temp . mkdirSync ( projectName ) ;
@@ -486,11 +551,59 @@ describe("Cocoapods support", () => {
486
551
}
487
552
} ) ;
488
553
489
- describe ( "Source code in plugin support" , ( ) => {
554
+ describe ( "Source code support" , ( ) => {
490
555
if ( require ( "os" ) . platform ( ) !== "darwin" ) {
491
556
console . log ( "Skipping Source code in plugin tests. They cannot work on windows" ) ;
492
557
} else {
493
558
559
+ const getProjectWithoutPlugins = async ( files : string [ ] ) => {
560
+ // Arrange
561
+ const projectName = "projectDirectory" ;
562
+ const projectPath = temp . mkdirSync ( projectName ) ;
563
+ const testInjector = createTestInjector ( projectPath , projectName , xcode ) ;
564
+ const fs : IFileSystem = testInjector . resolve ( "fs" ) ;
565
+
566
+ const packageJsonData = {
567
+ "name" : "myProject" ,
568
+ "version" : "0.1.0" ,
569
+ "nativescript" : {
570
+ "id" : "org.nativescript.myProject" ,
571
+ "tns-ios" : {
572
+ "version" : "1.0.0"
573
+ }
574
+ }
575
+ } ;
576
+ fs . writeJson ( path . join ( projectPath , "package.json" ) , packageJsonData ) ;
577
+
578
+ const platformsFolderPath = path . join ( projectPath , "platforms" , "ios" ) ;
579
+ fs . createDirectory ( platformsFolderPath ) ;
580
+
581
+ const iOSProjectService = testInjector . resolve ( "iOSProjectService" ) ;
582
+
583
+ iOSProjectService . getXcodeprojPath = ( ) => {
584
+ return path . join ( __dirname , "files" ) ;
585
+ } ;
586
+ let pbxProj : any ;
587
+ iOSProjectService . savePbxProj = ( project : any ) : Promise < void > => {
588
+ pbxProj = project ;
589
+ return Promise . resolve ( ) ;
590
+ } ;
591
+
592
+ const projectData : IProjectData = testInjector . resolve ( "projectData" ) ;
593
+
594
+ const platformSpecificAppResourcesPath = path . join ( projectData . appResourcesDirectoryPath , iOSProjectService . getPlatformData ( projectData ) . normalizedPlatformName ) ;
595
+
596
+ files . forEach ( file => {
597
+ const fullPath = path . join ( platformSpecificAppResourcesPath , file ) ;
598
+ fs . createDirectory ( path . dirname ( fullPath ) ) ;
599
+ fs . writeFile ( fullPath , "" ) ;
600
+ } ) ;
601
+
602
+ await iOSProjectService . prepareNativeSourceCode ( "src" , platformSpecificAppResourcesPath , projectData ) ;
603
+
604
+ return pbxProj ;
605
+ }
606
+
494
607
const preparePluginWithFiles = async ( files : string [ ] , prepareMethodToCall : string ) => {
495
608
// Arrange
496
609
const projectName = "projectDirectory" ;
@@ -555,6 +668,45 @@ describe("Source code in plugin support", () => {
555
668
return pbxProj ;
556
669
} ;
557
670
671
+ it ( "adds source files as resources" , async ( ) => {
672
+ const sourceFileNames = [
673
+ "src/Header.h" , "src/ObjC.m" ,
674
+ "src/nested/Header.hpp" , "src/nested/Source.cpp" , "src/nested/ObjCpp.mm" ,
675
+ "src/nested/level2/Header2.hxx" , "src/nested/level2/Source2.cxx" , "src/nested/level2/Source3.c" ,
676
+ "src/SomeOtherExtension.donotadd" ,
677
+ ] ;
678
+
679
+ const projectName = "projectDirectory" ;
680
+ const projectPath = temp . mkdirSync ( projectName ) ;
681
+ const testInjector = createTestInjector ( projectPath , projectName , xcode ) ;
682
+ const fs : IFileSystem = testInjector . resolve ( "fs" ) ;
683
+
684
+ const platformsFolderPath = path . join ( projectPath , "platforms" , "ios" ) ;
685
+ fs . createDirectory ( platformsFolderPath ) ;
686
+
687
+ const pbxProj = await await getProjectWithoutPlugins ( sourceFileNames ) ;
688
+
689
+ const pbxFileReference = pbxProj . hash . project . objects . PBXFileReference ;
690
+ const pbxFileReferenceValues = Object . keys ( pbxFileReference ) . map ( key => pbxFileReference [ key ] ) ;
691
+ const buildPhaseFiles = pbxProj . hash . project . objects . PBXSourcesBuildPhase [ "858B83F218CA22B800AB12DE" ] . files ;
692
+
693
+ sourceFileNames . map ( file => path . basename ( file ) ) . forEach ( basename => {
694
+ const ext = path . extname ( basename ) ;
695
+ const shouldBeAdded = ext !== ".donotadd" ;
696
+ if ( shouldBeAdded ) {
697
+ assert . notEqual ( pbxFileReferenceValues . indexOf ( basename ) , - 1 , `${ basename } not added to PBXFileRefereces` ) ;
698
+
699
+ if ( shouldBeAdded && ! path . extname ( basename ) . startsWith ( ".h" ) ) {
700
+ const buildPhaseFile = buildPhaseFiles . find ( ( fileObject : any ) => fileObject . comment . startsWith ( basename ) ) ;
701
+ assert . isDefined ( buildPhaseFile , `${ basename } not added to PBXSourcesBuildPhase` ) ;
702
+ assert . include ( buildPhaseFile . comment , "in Sources" , `${ basename } must be added to Sources group` ) ;
703
+ }
704
+ } else {
705
+ assert . equal ( pbxFileReferenceValues . indexOf ( basename ) , - 1 , `${ basename } was added to PBXFileRefereces, but it shouldn't have been` ) ;
706
+ }
707
+ } ) ;
708
+ } ) ;
709
+
558
710
it ( "adds plugin with Source files" , async ( ) => {
559
711
const sourceFileNames = [
560
712
"src/Header.h" , "src/ObjC.m" ,
0 commit comments