@@ -18,6 +18,17 @@ import * as mobileprovision from "ios-mobileprovision-finder";
18
18
import { SpawnOptions } from "child_process" ;
19
19
import { BUILD_XCCONFIG_FILE_NAME } from "../constants" ;
20
20
21
+ interface NativeSourceCodeDescription {
22
+ path : string ;
23
+ name : string ;
24
+ }
25
+
26
+ interface NativeSourceCodeGroup {
27
+ name : string ;
28
+ path : string ;
29
+ files : NativeSourceCodeDescription [ ] ;
30
+ }
31
+
21
32
export class IOSProjectService extends projectServiceBaseLib . PlatformProjectServiceBase implements IPlatformProjectService {
22
33
private static XCODE_PROJECT_EXT_NAME = ".xcodeproj" ;
23
34
private static XCODE_SCHEME_EXT_NAME = ".xcscheme" ;
@@ -924,6 +935,12 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
924
935
public async preparePluginNativeCode ( pluginData : IPluginData , projectData : IProjectData , opts ?: any ) : Promise < void > {
925
936
const pluginPlatformsFolderPath = pluginData . pluginPlatformsFolderPath ( IOSProjectService . IOS_PLATFORM_NAME ) ;
926
937
938
+
939
+ let sourcePath = path . join ( pluginPlatformsFolderPath , "src" ) ;
940
+ if ( this . $fs . exists ( pluginPlatformsFolderPath ) && this . $fs . exists ( sourcePath ) ) {
941
+ await this . prepareNativeSourceCode ( pluginData . name , sourcePath , projectData ) ;
942
+ }
943
+
927
944
await this . prepareFrameworks ( pluginPlatformsFolderPath , pluginData , projectData ) ;
928
945
await this . prepareStaticLibs ( pluginPlatformsFolderPath , pluginData , projectData ) ;
929
946
await this . prepareCocoapods ( pluginPlatformsFolderPath , projectData ) ;
@@ -1103,6 +1120,41 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
1103
1120
return childProcess ;
1104
1121
}
1105
1122
1123
+ private async prepareNativeSourceCode ( pluginName : string , pluginPlatformsFolderPath : string , projectData : IProjectData ) : Promise < void > {
1124
+
1125
+ const project = this . createPbxProj ( projectData ) ;
1126
+
1127
+ let groupsArr :NativeSourceCodeGroup [ ] = [ ] ;
1128
+ let arrObj = { arr : groupsArr } ;
1129
+ this . createSourceArray ( pluginName , pluginPlatformsFolderPath , arrObj ) ;
1130
+ //iterate backwards as the root level directory is added first
1131
+ for ( let i = groupsArr . length - 1 ; i >= 0 ; i -- ) {
1132
+ const el = groupsArr [ i ] ;
1133
+ project . addPbxGroup ( el . files . map ( f => f . path ) , el . name , el . path )
1134
+ project . addToHeaderSearchPaths ( el . path ) ;
1135
+ }
1136
+
1137
+ this . savePbxProj ( project , projectData ) ;
1138
+ }
1139
+
1140
+ private createSourceArray ( name : string , rootPath : string , groupsArr : any ) {
1141
+ let filesArr : NativeSourceCodeDescription [ ] = [ ] ;
1142
+ let rootGroup : NativeSourceCodeGroup = { name : name , files : filesArr , path : rootPath } ;
1143
+
1144
+ if ( this . $fs . exists ( rootPath ) && ! this . $fs . isEmptyDir ( rootPath ) ) {
1145
+ this . $fs . readDirectory ( rootPath ) . forEach ( fileName => {
1146
+ let filePath = path . join ( rootGroup . path , fileName ) ;
1147
+ let file : NativeSourceCodeDescription = { name : fileName , path : filePath } ;
1148
+ filesArr . push ( file ) ;
1149
+ if ( this . $fs . getFsStats ( filePath ) . isDirectory ( ) ) {
1150
+ this . createSourceArray ( file . name , file . path , groupsArr ) ;
1151
+ }
1152
+ } ) ;
1153
+ }
1154
+
1155
+ groupsArr . arr . push ( rootGroup ) ;
1156
+ }
1157
+
1106
1158
private async prepareFrameworks ( pluginPlatformsFolderPath : string , pluginData : IPluginData , projectData : IProjectData ) : Promise < void > {
1107
1159
for ( const fileName of this . getAllLibsForPluginWithFileExtension ( pluginData , ".framework" ) ) {
1108
1160
await this . addFramework ( path . join ( pluginPlatformsFolderPath , fileName ) , projectData ) ;
0 commit comments