@@ -17,6 +17,12 @@ import * as mobileprovision from "ios-mobileprovision-finder";
17
17
import { SpawnOptions } from "child_process" ;
18
18
import { BUILD_XCCONFIG_FILE_NAME } from "../constants" ;
19
19
20
+ interface INativeSourceCodeGroup {
21
+ name : string ;
22
+ path : string ;
23
+ files : string [ ] ;
24
+ }
25
+
20
26
export class IOSProjectService extends projectServiceBaseLib . PlatformProjectServiceBase implements IPlatformProjectService {
21
27
private static XCODE_PROJECT_EXT_NAME = ".xcodeproj" ;
22
28
private static XCODE_SCHEME_EXT_NAME = ".xcscheme" ;
@@ -924,6 +930,12 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
924
930
public async preparePluginNativeCode ( pluginData : IPluginData , projectData : IProjectData , opts ?: any ) : Promise < void > {
925
931
const pluginPlatformsFolderPath = pluginData . pluginPlatformsFolderPath ( IOSProjectService . IOS_PLATFORM_NAME ) ;
926
932
933
+ const sourcePath = path . join ( pluginPlatformsFolderPath , "src" ) ;
934
+ if ( this . $fs . exists ( pluginPlatformsFolderPath ) && this . $fs . exists ( sourcePath ) ) {
935
+ await this . prepareNativeSourceCode ( pluginData . name , sourcePath , projectData ) ;
936
+ }
937
+
938
+ await this . prepareResources ( pluginPlatformsFolderPath , pluginData , projectData ) ;
927
939
await this . prepareFrameworks ( pluginPlatformsFolderPath , pluginData , projectData ) ;
928
940
await this . prepareStaticLibs ( pluginPlatformsFolderPath , pluginData , projectData ) ;
929
941
await this . prepareCocoapods ( pluginPlatformsFolderPath , projectData ) ;
@@ -932,6 +944,7 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
932
944
public async removePluginNativeCode ( pluginData : IPluginData , projectData : IProjectData ) : Promise < void > {
933
945
const pluginPlatformsFolderPath = pluginData . pluginPlatformsFolderPath ( IOSProjectService . IOS_PLATFORM_NAME ) ;
934
946
947
+ this . removeNativeSourceCode ( pluginPlatformsFolderPath , pluginData , projectData ) ;
935
948
this . removeFrameworks ( pluginPlatformsFolderPath , pluginData , projectData ) ;
936
949
this . removeStaticLibs ( pluginPlatformsFolderPath , pluginData , projectData ) ;
937
950
this . removeCocoapods ( pluginPlatformsFolderPath , projectData ) ;
@@ -1103,6 +1116,40 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
1103
1116
return childProcess ;
1104
1117
}
1105
1118
1119
+ private async prepareNativeSourceCode ( pluginName : string , pluginPlatformsFolderPath : string , projectData : IProjectData ) : Promise < void > {
1120
+ const project = this . createPbxProj ( projectData ) ;
1121
+ const group = this . getRootGroup ( pluginName , pluginPlatformsFolderPath ) ;
1122
+ project . addPbxGroup ( group . files , group . name , group . path , null , { isMain :true } ) ;
1123
+ project . addToHeaderSearchPaths ( group . path ) ;
1124
+ this . savePbxProj ( project , projectData ) ;
1125
+ }
1126
+
1127
+ private getRootGroup ( name : string , rootPath : string ) {
1128
+ const filePathsArr : string [ ] = [ ] ;
1129
+ const rootGroup : INativeSourceCodeGroup = { name : name , files : filePathsArr , path : rootPath } ;
1130
+
1131
+ if ( this . $fs . exists ( rootPath ) && ! this . $fs . isEmptyDir ( rootPath ) ) {
1132
+ this . $fs . readDirectory ( rootPath ) . forEach ( fileName => {
1133
+ const filePath = path . join ( rootGroup . path , fileName ) ;
1134
+ filePathsArr . push ( filePath ) ;
1135
+ } ) ;
1136
+ }
1137
+
1138
+ return rootGroup ;
1139
+ }
1140
+
1141
+ private async prepareResources ( pluginPlatformsFolderPath : string , pluginData : IPluginData , projectData : IProjectData ) : Promise < void > {
1142
+ const project = this . createPbxProj ( projectData ) ;
1143
+ const resourcesPath = path . join ( pluginPlatformsFolderPath , "Resources" ) ;
1144
+ if ( this . $fs . exists ( resourcesPath ) && ! this . $fs . isEmptyDir ( resourcesPath ) ) {
1145
+ for ( const fileName of this . $fs . readDirectory ( resourcesPath ) ) {
1146
+ const filePath = path . join ( resourcesPath , fileName ) ;
1147
+
1148
+ project . addResourceFile ( filePath ) ;
1149
+ }
1150
+ }
1151
+ this . savePbxProj ( project , projectData ) ;
1152
+ }
1106
1153
private async prepareFrameworks ( pluginPlatformsFolderPath : string , pluginData : IPluginData , projectData : IProjectData ) : Promise < void > {
1107
1154
for ( const fileName of this . getAllLibsForPluginWithFileExtension ( pluginData , ".framework" ) ) {
1108
1155
await this . addFramework ( path . join ( pluginPlatformsFolderPath , fileName ) , projectData ) ;
@@ -1147,6 +1194,14 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
1147
1194
}
1148
1195
}
1149
1196
1197
+ private removeNativeSourceCode ( pluginPlatformsFolderPath : string , pluginData : IPluginData , projectData : IProjectData ) : void {
1198
+ const project = this . createPbxProj ( projectData ) ;
1199
+ const group = this . getRootGroup ( pluginData . name , pluginPlatformsFolderPath ) ;
1200
+ project . removePbxGroup ( group . name , group . path ) ;
1201
+ project . removeFromHeaderSearchPaths ( group . path ) ;
1202
+ this . savePbxProj ( project , projectData ) ;
1203
+ }
1204
+
1150
1205
private removeFrameworks ( pluginPlatformsFolderPath : string , pluginData : IPluginData , projectData : IProjectData ) : void {
1151
1206
const project = this . createPbxProj ( projectData ) ;
1152
1207
_ . each ( this . getAllLibsForPluginWithFileExtension ( pluginData , ".framework" ) , fileName => {
0 commit comments