@@ -52,39 +52,40 @@ export class CocoaPodsService implements ICocoaPodsService {
52
52
return podInstallResult ;
53
53
}
54
54
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
+ }
58
60
return ;
59
61
}
60
62
61
- const { pluginPodfileContent , replacedFunctions } = this . buildPodfileContent ( pluginPodFilePath , pluginData . name ) ;
63
+ const { podfileContent , replacedFunctions } = this . buildPodfileContent ( podfilePath , moduleName ) ;
62
64
const pathToProjectPodfile = this . getProjectPodfilePath ( nativeProjectPath ) ;
63
65
const projectPodfileContent = this . $fs . exists ( pathToProjectPodfile ) ? this . $fs . readText ( pathToProjectPodfile ) . trim ( ) : "" ;
64
66
65
- if ( projectPodfileContent . indexOf ( pluginPodfileContent ) === - 1 ) {
67
+ if ( projectPodfileContent . indexOf ( podfileContent ) === - 1 ) {
66
68
// Remove old occurences of the plugin from the project's Podfile.
67
- this . removePluginPodfileFromProject ( pluginData , projectData , nativeProjectPath ) ;
69
+ this . removePodfileFromProject ( moduleName , podfilePath , projectData , nativeProjectPath ) ;
68
70
let finalPodfileContent = this . $fs . exists ( pathToProjectPodfile ) ? this . getPodfileContentWithoutTarget ( projectData , this . $fs . readText ( pathToProjectPodfile ) ) : "" ;
69
71
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 ) ;
72
74
}
73
75
74
- finalPodfileContent = `${ pluginPodfileContent } ${ EOL } ${ finalPodfileContent } ` ;
76
+ finalPodfileContent = `${ podfileContent } ${ EOL } ${ finalPodfileContent } ` ;
75
77
this . saveProjectPodfile ( projectData , finalPodfileContent , nativeProjectPath ) ;
76
78
}
77
79
}
78
80
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 {
81
82
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 ) ) ) {
83
84
let projectPodFileContent = this . $fs . readText ( this . getProjectPodfilePath ( projectRoot ) ) ;
84
85
// 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" ) ;
86
87
projectPodFileContent = projectPodFileContent . replace ( regExpToRemove , "" ) ;
87
- projectPodFileContent = this . removePostInstallHook ( pluginData , projectPodFileContent ) ;
88
+ projectPodFileContent = this . removePostInstallHook ( moduleName , projectPodFileContent ) ;
88
89
89
90
const defaultPodfileBeginning = this . getPodfileHeader ( projectData . projectName ) ;
90
91
const defaultContentWithPostInstallHook = `${ defaultPodfileBeginning } ${ EOL } ${ this . getPostInstallHookHeader ( ) } end${ EOL } end` ;
@@ -98,7 +99,7 @@ export class CocoaPodsService implements ICocoaPodsService {
98
99
}
99
100
}
100
101
101
- private getPluginPodfilePath ( pluginData : IPluginData ) : string {
102
+ public getPluginPodfilePath ( pluginData : IPluginData ) : string {
102
103
const pluginPlatformsFolderPath = pluginData . pluginPlatformsFolderPath ( PluginNativeDirNames . iOS ) ;
103
104
const pluginPodFilePath = path . join ( pluginPlatformsFolderPath , PODFILE_NAME ) ;
104
105
return pluginPodFilePath ;
@@ -157,8 +158,8 @@ export class CocoaPodsService implements ICocoaPodsService {
157
158
this . $fs . writeFile ( projectPodfilePath , contentToWrite ) ;
158
159
}
159
160
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" ) ;
162
163
projectPodFileContent = projectPodFileContent . replace ( regExp , "" ) ;
163
164
return projectPodFileContent ;
164
165
}
@@ -206,12 +207,12 @@ export class CocoaPodsService implements ICocoaPodsService {
206
207
return `${ CocoaPodsService . PODFILE_POST_INSTALL_SECTION_NAME } do |${ CocoaPodsService . INSTALLER_BLOCK_PARAMETER_NAME } |${ EOL } ` ;
207
208
}
208
209
209
- private buildPodfileContent ( pluginPodFilePath : string , pluginName : string ) : { pluginPodfileContent : string , replacedFunctions : IRubyFunction [ ] } {
210
+ private buildPodfileContent ( pluginPodFilePath : string , pluginName : string ) : { podfileContent : string , replacedFunctions : IRubyFunction [ ] } {
210
211
const pluginPodfileContent = this . $fs . readText ( pluginPodFilePath ) ;
211
212
const { replacedContent, newFunctions : replacedFunctions } = this . replaceHookContent ( CocoaPodsService . PODFILE_POST_INSTALL_SECTION_NAME , pluginPodfileContent , pluginName ) ;
212
213
213
214
return {
214
- pluginPodfileContent : `${ this . getPluginPodfileHeader ( pluginPodFilePath ) } ${ EOL } ${ replacedContent } ${ EOL } ${ this . getPluginPodfileEnd ( ) } ` ,
215
+ podfileContent : `${ this . getPluginPodfileHeader ( pluginPodFilePath ) } ${ EOL } ${ replacedContent } ${ EOL } ${ this . getPluginPodfileEnd ( ) } ` ,
215
216
replacedFunctions
216
217
} ;
217
218
}
0 commit comments