@@ -15,12 +15,6 @@ import { IOSEntitlementsService } from "./ios-entitlements-service";
1515import * as mobileprovision from "ios-mobileprovision-finder" ;
1616import { BUILD_XCCONFIG_FILE_NAME , IosProjectConstants } from "../constants" ;
1717
18- interface INativeSourceCodeGroup {
19- name : string ;
20- path : string ;
21- files : string [ ] ;
22- }
23-
2418const DevicePlatformSdkName = "iphoneos" ;
2519const SimulatorPlatformSdkName = "iphonesimulator" ;
2620
@@ -52,7 +46,8 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
5246 private $platformEnvironmentRequirements : IPlatformEnvironmentRequirements ,
5347 private $plistParser : IPlistParser ,
5448 private $sysInfo : ISysInfo ,
55- private $xcconfigService : IXcconfigService ) {
49+ private $xcconfigService : IXcconfigService ,
50+ private $iOSExtensionsService : IIOSExtensionsService ) {
5651 super ( $fs , $projectDataService ) ;
5752 }
5853
@@ -982,7 +977,9 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
982977 await this . $cocoapodsService . mergePodXcconfigFile ( projectData , platformData , opts ) ;
983978 }
984979
985- this . removeExtensions ( projectData ) ;
980+ const pbxprojPath = this . getPbxProjPath ( projectData ) ;
981+ const project = this . createPbxProj ( projectData ) ;
982+ this . $iOSExtensionsService . removeExtensions ( project , pbxprojPath ) ;
986983 await this . addExtensions ( projectData ) ;
987984 }
988985 public beforePrepareAllPlugins ( ) : Promise < void > {
@@ -1100,90 +1097,24 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
11001097 }
11011098
11021099 private async addExtensions ( projectData : IProjectData ) : Promise < void > {
1103- await this . prepareExtensionsCode ( path . join ( projectData . getAppResourcesDirectoryPath ( ) , this . getPlatformData ( projectData ) . normalizedPlatformName , constants . NATIVE_EXTENSION_FOLDER ) , projectData ) ;
1100+ const resorcesExtensionsPath = path . join (
1101+ projectData . getAppResourcesDirectoryPath ( ) ,
1102+ this . getPlatformData ( projectData ) . normalizedPlatformName , constants . NATIVE_EXTENSION_FOLDER
1103+ ) ;
1104+ const platformData = this . getPlatformData ( projectData ) ;
1105+ const pbxProjectPath = this . getPbxProjPath ( projectData ) ;
1106+ const project = this . createPbxProj ( projectData ) ;
1107+ await this . $iOSExtensionsService . addExtensionsFromPath ( resorcesExtensionsPath , projectData , platformData , pbxProjectPath , project ) ;
11041108 const plugins = await this . getAllInstalledPlugins ( projectData ) ;
11051109 for ( const pluginIndex in plugins ) {
11061110 const pluginData = plugins [ pluginIndex ] ;
11071111 const pluginPlatformsFolderPath = pluginData . pluginPlatformsFolderPath ( IOSProjectService . IOS_PLATFORM_NAME ) ;
11081112
11091113 const extensionPath = path . join ( pluginPlatformsFolderPath , constants . NATIVE_EXTENSION_FOLDER ) ;
1110- await this . prepareExtensionsCode ( extensionPath , projectData ) ;
1114+ await this . $iOSExtensionsService . addExtensionsFromPath ( extensionPath , projectData , platformData , pbxProjectPath , project ) ;
11111115 }
11121116 }
11131117
1114- private async prepareExtensionsCode ( extensionsFolderPath : string , projectData : IProjectData ) : Promise < void > {
1115- const targetUuids : string [ ] = [ ] ;
1116- if ( ! this . $fs . exists ( extensionsFolderPath ) ) {
1117- return ;
1118- }
1119-
1120- const project = this . createPbxProj ( projectData ) ;
1121-
1122- this . $fs . readDirectory ( extensionsFolderPath )
1123- . filter ( fileName => {
1124- const filePath = path . join ( extensionsFolderPath , fileName ) ;
1125- const stats = this . $fs . getFsStats ( filePath ) ;
1126- return stats . isDirectory ( ) && ! fileName . startsWith ( "." ) ;
1127- } )
1128- . forEach ( extensionFolder => {
1129- const targetUuid = this . addExtensionToProject ( extensionsFolderPath , extensionFolder , project , projectData ) ;
1130- targetUuids . push ( targetUuid ) ;
1131- } ) ;
1132-
1133- this . savePbxProj ( project , projectData , true ) ;
1134- this . prepareExtensionSigning ( targetUuids , projectData ) ;
1135- }
1136-
1137- private addExtensionToProject ( extensionsFolderPath : string , extensionFolder : string , project : IXcode . project , projectData : IProjectData ) : string {
1138- const extensionPath = path . join ( extensionsFolderPath , extensionFolder ) ;
1139- const extensionRelativePath = path . relative ( this . getPlatformData ( projectData ) . projectRoot , extensionPath ) ;
1140- const group = this . getRootGroup ( extensionFolder , extensionPath ) ;
1141- const target = project . addTarget ( extensionFolder , 'app_extension' , extensionRelativePath ) ;
1142- project . addBuildPhase ( [ ] , 'PBXSourcesBuildPhase' , 'Sources' , target . uuid ) ;
1143- project . addBuildPhase ( [ ] , 'PBXResourcesBuildPhase' , 'Resources' , target . uuid ) ;
1144- project . addBuildPhase ( [ ] , 'PBXFrameworksBuildPhase' , 'Frameworks' , target . uuid ) ;
1145-
1146- const extJsonPath = path . join ( extensionsFolderPath , extensionFolder , "extension.json" ) ;
1147- if ( this . $fs . exists ( extJsonPath ) ) {
1148- const extensionJson = this . $fs . readJson ( extJsonPath ) ;
1149- _ . forEach ( extensionJson . frameworks , framework => {
1150- project . addFramework (
1151- framework ,
1152- { target : target . uuid }
1153- ) ;
1154- } ) ;
1155- if ( extensionJson . assetcatalogCompilerAppiconName ) {
1156- project . addToBuildSettings ( "ASSETCATALOG_COMPILER_APPICON_NAME" , extensionJson . assetcatalogCompilerAppiconName , target . uuid ) ;
1157- }
1158- }
1159-
1160- project . addPbxGroup ( group . files , group . name , group . path , null , { isMain : true , target : target . uuid , filesRelativeToProject : true } ) ;
1161- project . addBuildProperty ( "PRODUCT_BUNDLE_IDENTIFIER" , `${ projectData . projectIdentifiers . ios } .${ extensionFolder } ` , "Debug" , extensionFolder ) ;
1162- project . addBuildProperty ( "PRODUCT_BUNDLE_IDENTIFIER" , `${ projectData . projectIdentifiers . ios } .${ extensionFolder } ` , "Release" , extensionFolder ) ;
1163- project . addToHeaderSearchPaths ( group . path , target . pbxNativeTarget . productName ) ;
1164-
1165- return target . uuid ;
1166- }
1167-
1168- private prepareExtensionSigning ( targetUuids : string [ ] , projectData :IProjectData ) {
1169- const xcode = this . $pbxprojDomXcode . Xcode . open ( this . getPbxProjPath ( projectData ) ) ;
1170- const signing = xcode . getSigning ( projectData . projectName ) ;
1171- if ( signing !== undefined ) {
1172- _ . forEach ( targetUuids , targetUuid => {
1173- if ( signing . style === "Automatic" ) {
1174- xcode . setAutomaticSigningStyleByTargetKey ( targetUuid , signing . team ) ;
1175- } else {
1176- for ( const config in signing . configurations ) {
1177- const signingConfiguration = signing . configurations [ config ] ;
1178- xcode . setManualSigningStyleByTargetKey ( targetUuid , signingConfiguration ) ;
1179- break ;
1180- }
1181- }
1182- } ) ;
1183- }
1184- xcode . save ( ) ;
1185- }
1186-
11871118 private getRootGroup ( name : string , rootPath : string ) {
11881119 const filePathsArr : string [ ] = [ ] ;
11891120 const rootGroup : INativeSourceCodeGroup = { name : name , files : filePathsArr , path : rootPath } ;
@@ -1233,12 +1164,6 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
12331164 this . savePbxProj ( project , projectData ) ;
12341165 }
12351166
1236- private removeExtensions ( projectData : IProjectData ) : void {
1237- const project = this . createPbxProj ( projectData ) ;
1238- project . removeTargetsByProductType ( "com.apple.product-type.app-extension" ) ;
1239- this . savePbxProj ( project , projectData ) ;
1240- }
1241-
12421167 private removeFrameworks ( pluginPlatformsFolderPath : string , pluginData : IPluginData , projectData : IProjectData ) : void {
12431168 const project = this . createPbxProj ( projectData ) ;
12441169 _ . each ( this . getAllLibsForPluginWithFileExtension ( pluginData , ".framework" ) , fileName => {
0 commit comments