@@ -52,39 +52,40 @@ export class CocoaPodsService implements ICocoaPodsService {
5252 return podInstallResult ;
5353 }
5454
55- public async applyPluginPodfileToProject ( pluginData : IPluginData , projectData : IProjectData , nativeProjectPath : string ) : Promise < void > {
56- const pluginPodFilePath = this . getPluginPodfilePath ( pluginData ) ;
57- if ( ! this . $fs . exists ( pluginPodFilePath ) ) {
55+ public async applyPodfileToProject ( moduleName : string , podfilePath : string , projectData : IProjectData , nativeProjectPath : string ) : Promise < void > {
56+ if ( ! this . $fs . exists ( podfilePath ) ) {
57+ if ( podfilePath === projectData . podfilePath ) {
58+ this . removePodfileFromProject ( moduleName , podfilePath , projectData , nativeProjectPath ) ;
59+ }
5860 return ;
5961 }
6062
61- const { pluginPodfileContent , replacedFunctions } = this . buildPodfileContent ( pluginPodFilePath , pluginData . name ) ;
63+ const { podfileContent , replacedFunctions } = this . buildPodfileContent ( podfilePath , moduleName ) ;
6264 const pathToProjectPodfile = this . getProjectPodfilePath ( nativeProjectPath ) ;
6365 const projectPodfileContent = this . $fs . exists ( pathToProjectPodfile ) ? this . $fs . readText ( pathToProjectPodfile ) . trim ( ) : "" ;
6466
65- if ( projectPodfileContent . indexOf ( pluginPodfileContent ) === - 1 ) {
67+ if ( projectPodfileContent . indexOf ( podfileContent ) === - 1 ) {
6668 // Remove old occurences of the plugin from the project's Podfile.
67- this . removePluginPodfileFromProject ( pluginData , projectData , nativeProjectPath ) ;
69+ this . removePodfileFromProject ( moduleName , podfilePath , projectData , nativeProjectPath ) ;
6870 let finalPodfileContent = this . $fs . exists ( pathToProjectPodfile ) ? this . getPodfileContentWithoutTarget ( projectData , this . $fs . readText ( pathToProjectPodfile ) ) : "" ;
6971
70- if ( pluginPodfileContent . indexOf ( CocoaPodsService . PODFILE_POST_INSTALL_SECTION_NAME ) !== - 1 ) {
71- finalPodfileContent = this . addPostInstallHook ( replacedFunctions , finalPodfileContent , pluginPodfileContent ) ;
72+ if ( podfileContent . indexOf ( CocoaPodsService . PODFILE_POST_INSTALL_SECTION_NAME ) !== - 1 ) {
73+ finalPodfileContent = this . addPostInstallHook ( replacedFunctions , finalPodfileContent , podfileContent ) ;
7274 }
7375
74- finalPodfileContent = `${ pluginPodfileContent } ${ EOL } ${ finalPodfileContent } ` ;
76+ finalPodfileContent = `${ podfileContent } ${ EOL } ${ finalPodfileContent } ` ;
7577 this . saveProjectPodfile ( projectData , finalPodfileContent , nativeProjectPath ) ;
7678 }
7779 }
7880
79- public removePluginPodfileFromProject ( pluginData : IPluginData , projectData : IProjectData , projectRoot : string ) : void {
80- const pluginPodfilePath = this . getPluginPodfilePath ( pluginData ) ;
81+ public removePodfileFromProject ( moduleName : string , podfilePath : string , projectData : IProjectData , projectRoot : string ) : void {
8182
82- if ( this . $fs . exists ( pluginPodfilePath ) && this . $fs . exists ( this . getProjectPodfilePath ( projectRoot ) ) ) {
83+ if ( ( this . $fs . exists ( podfilePath ) || podfilePath == projectData . podfilePath ) && this . $fs . exists ( this . getProjectPodfilePath ( projectRoot ) ) ) {
8384 let projectPodFileContent = this . $fs . readText ( this . getProjectPodfilePath ( projectRoot ) ) ;
8485 // Remove the data between #Begin Podfile and #EndPodfile
85- const regExpToRemove = new RegExp ( `${ this . getPluginPodfileHeader ( pluginPodfilePath ) } [\\s\\S]*?${ this . getPluginPodfileEnd ( ) } ` , "mg" ) ;
86+ const regExpToRemove = new RegExp ( `${ this . getPluginPodfileHeader ( podfilePath ) } [\\s\\S]*?${ this . getPluginPodfileEnd ( ) } ` , "mg" ) ;
8687 projectPodFileContent = projectPodFileContent . replace ( regExpToRemove , "" ) ;
87- projectPodFileContent = this . removePostInstallHook ( pluginData , projectPodFileContent ) ;
88+ projectPodFileContent = this . removePostInstallHook ( moduleName , projectPodFileContent ) ;
8889
8990 const defaultPodfileBeginning = this . getPodfileHeader ( projectData . projectName ) ;
9091 const defaultContentWithPostInstallHook = `${ defaultPodfileBeginning } ${ EOL } ${ this . getPostInstallHookHeader ( ) } end${ EOL } end` ;
@@ -98,7 +99,7 @@ export class CocoaPodsService implements ICocoaPodsService {
9899 }
99100 }
100101
101- private getPluginPodfilePath ( pluginData : IPluginData ) : string {
102+ public getPluginPodfilePath ( pluginData : IPluginData ) : string {
102103 const pluginPlatformsFolderPath = pluginData . pluginPlatformsFolderPath ( PluginNativeDirNames . iOS ) ;
103104 const pluginPodFilePath = path . join ( pluginPlatformsFolderPath , PODFILE_NAME ) ;
104105 return pluginPodFilePath ;
@@ -157,8 +158,8 @@ export class CocoaPodsService implements ICocoaPodsService {
157158 this . $fs . writeFile ( projectPodfilePath , contentToWrite ) ;
158159 }
159160
160- private removePostInstallHook ( pluginData : IPluginData , projectPodFileContent : string ) : string {
161- const regExp = new RegExp ( `^.*?${ this . getHookBasicFuncNameForPlugin ( CocoaPodsService . PODFILE_POST_INSTALL_SECTION_NAME , pluginData . name ) } .*?$\\r?\\n` , "gm" ) ;
161+ private removePostInstallHook ( moduleName : string , projectPodFileContent : string ) : string {
162+ const regExp = new RegExp ( `^.*?${ this . getHookBasicFuncNameForPlugin ( CocoaPodsService . PODFILE_POST_INSTALL_SECTION_NAME , moduleName ) } .*?$\\r?\\n` , "gm" ) ;
162163 projectPodFileContent = projectPodFileContent . replace ( regExp , "" ) ;
163164 return projectPodFileContent ;
164165 }
@@ -206,12 +207,12 @@ export class CocoaPodsService implements ICocoaPodsService {
206207 return `${ CocoaPodsService . PODFILE_POST_INSTALL_SECTION_NAME } do |${ CocoaPodsService . INSTALLER_BLOCK_PARAMETER_NAME } |${ EOL } ` ;
207208 }
208209
209- private buildPodfileContent ( pluginPodFilePath : string , pluginName : string ) : { pluginPodfileContent : string , replacedFunctions : IRubyFunction [ ] } {
210+ private buildPodfileContent ( pluginPodFilePath : string , pluginName : string ) : { podfileContent : string , replacedFunctions : IRubyFunction [ ] } {
210211 const pluginPodfileContent = this . $fs . readText ( pluginPodFilePath ) ;
211212 const { replacedContent, newFunctions : replacedFunctions } = this . replaceHookContent ( CocoaPodsService . PODFILE_POST_INSTALL_SECTION_NAME , pluginPodfileContent , pluginName ) ;
212213
213214 return {
214- pluginPodfileContent : `${ this . getPluginPodfileHeader ( pluginPodFilePath ) } ${ EOL } ${ replacedContent } ${ EOL } ${ this . getPluginPodfileEnd ( ) } ` ,
215+ podfileContent : `${ this . getPluginPodfileHeader ( pluginPodFilePath ) } ${ EOL } ${ replacedContent } ${ EOL } ${ this . getPluginPodfileEnd ( ) } ` ,
215216 replacedFunctions
216217 } ;
217218 }
0 commit comments