@@ -21,6 +21,7 @@ import {
2121} from "../common/declarations" ;
2222import { injector } from "../common/yok" ;
2323import { XcodeSelectService } from "../common/services/xcode-select-service" ;
24+ import * as constants from "../constants" ;
2425
2526export class CocoaPodsService implements ICocoaPodsService {
2627 private static PODFILE_POST_INSTALL_SECTION_NAME = "post_install" ;
@@ -121,9 +122,10 @@ ${versionResolutionHint}`);
121122 ) ;
122123 const podFolder = path . join ( platformData . projectRoot , podFilesRootDirName ) ;
123124 if ( this . $fs . exists ( podFolder ) ) {
124- const pluginsXcconfigFilePaths = this . $xcconfigService . getPluginsXcconfigFilePaths (
125- platformData . projectRoot
126- ) ;
125+ const pluginsXcconfigFilePaths =
126+ this . $xcconfigService . getPluginsXcconfigFilePaths (
127+ platformData . projectRoot
128+ ) ;
127129 for ( const configuration in pluginsXcconfigFilePaths ) {
128130 const pluginsXcconfigFilePath = pluginsXcconfigFilePaths [ configuration ] ;
129131 const podXcconfigFilePath = path . join (
@@ -199,6 +201,71 @@ end`.trim();
199201 this . $fs . deleteFile ( exclusionsPodfile ) ;
200202 }
201203
204+ public async applyPodfileFromExtensions (
205+ projectData : IProjectData ,
206+ platformData : IPlatformData
207+ ) {
208+ const extensionFolderPath = path . join (
209+ projectData . getAppResourcesDirectoryPath ( ) ,
210+ constants . iOSAppResourcesFolderName ,
211+ constants . NATIVE_EXTENSION_FOLDER
212+ ) ;
213+ const projectPodfilePath = this . getProjectPodfilePath (
214+ platformData . projectRoot
215+ ) ;
216+
217+ if (
218+ ! this . $fs . exists ( extensionFolderPath ) ||
219+ ! this . $fs . exists ( projectPodfilePath )
220+ ) {
221+ return ;
222+ }
223+
224+ let projectPodFileContent = this . $fs . readText ( projectPodfilePath ) ;
225+
226+ const extensionsPodfile = this . $fs
227+ . readDirectory ( extensionFolderPath )
228+ . filter ( ( name ) => {
229+ const extensionPath = path . join ( extensionFolderPath , name ) ;
230+ const stats = this . $fs . getFsStats ( extensionPath ) ;
231+ return stats . isDirectory ( ) && ! name . startsWith ( "." ) ;
232+ } )
233+ . map ( ( name ) => ( {
234+ targetName : name ,
235+ podfilePath : path . join (
236+ extensionFolderPath ,
237+ name ,
238+ constants . PODFILE_NAME
239+ ) ,
240+ } ) ) ;
241+
242+ extensionsPodfile . forEach ( ( { targetName, podfilePath } ) => {
243+ // Remove the data between #Begin Podfile and #EndPodfile
244+ const regExpToRemove = new RegExp (
245+ `${ this . getExtensionPodfileHeader (
246+ podfilePath ,
247+ targetName
248+ ) } [\\s\\S]*?${ this . getExtensionPodfileEnd ( ) } `,
249+ "mg"
250+ ) ;
251+ projectPodFileContent = projectPodFileContent . replace ( regExpToRemove , "" ) ;
252+
253+ if ( this . $fs . exists ( podfilePath ) ) {
254+ const podfileContentWithoutTarget = this . $fs . readText ( podfilePath ) ;
255+ const podFileContent =
256+ this . getExtensionPodfileHeader ( podfilePath , targetName ) +
257+ EOL +
258+ podfileContentWithoutTarget +
259+ EOL +
260+ this . getExtensionPodfileEnd ( ) ;
261+
262+ projectPodFileContent += EOL + podFileContent ;
263+ }
264+ } ) ;
265+
266+ this . $fs . writeFile ( projectPodfilePath , projectPodFileContent ) ;
267+ }
268+
202269 public async applyPodfileToProject (
203270 moduleName : string ,
204271 podfilePath : string ,
@@ -216,16 +283,13 @@ end`.trim();
216283 return ;
217284 }
218285
219- const {
220- podfileContent,
221- replacedFunctions,
222- podfilePlatformData,
223- } = this . buildPodfileContent (
224- podfilePath ,
225- moduleName ,
226- projectData ,
227- platformData
228- ) ;
286+ const { podfileContent, replacedFunctions, podfilePlatformData } =
287+ this . buildPodfileContent (
288+ podfilePath ,
289+ moduleName ,
290+ projectData ,
291+ platformData
292+ ) ;
229293 const pathToProjectPodfile = this . getProjectPodfilePath ( nativeProjectPath ) ;
230294 const projectPodfileContent = this . $fs . exists ( pathToProjectPodfile )
231295 ? this . $fs . readText ( pathToProjectPodfile ) . trim ( )
@@ -297,11 +361,12 @@ end`.trim();
297361 moduleName ,
298362 projectPodFileContent
299363 ) ;
300- projectPodFileContent = this . $cocoaPodsPlatformManager . removePlatformSection (
301- moduleName ,
302- projectPodFileContent ,
303- podfilePath
304- ) ;
364+ projectPodFileContent =
365+ this . $cocoaPodsPlatformManager . removePlatformSection (
366+ moduleName ,
367+ projectPodFileContent ,
368+ podfilePath
369+ ) ;
305370
306371 const defaultPodfileBeginning = this . getPodfileHeader (
307372 projectData . projectName
@@ -496,6 +561,20 @@ end`.trim();
496561 return `# End Podfile${ EOL } ` ;
497562 }
498563
564+ private getExtensionPodfileHeader (
565+ extensionPodFilePath : string ,
566+ targetName : string
567+ ) : string {
568+ const targetHeader = `target "${ targetName . trim ( ) } " do` ;
569+ return `${ this . getPluginPodfileHeader (
570+ extensionPodFilePath
571+ ) } ${ EOL } ${ targetHeader } `;
572+ }
573+
574+ private getExtensionPodfileEnd ( ) : string {
575+ return `end${ EOL } ${ this . getPluginPodfileEnd ( ) } ` ;
576+ }
577+
499578 private getPostInstallHookHeader ( ) {
500579 return `${ CocoaPodsService . PODFILE_POST_INSTALL_SECTION_NAME } do |${ CocoaPodsService . INSTALLER_BLOCK_PARAMETER_NAME } |${ EOL } ` ;
501580 }
0 commit comments