Skip to content

Commit 6062bae

Browse files
Merge pull request #1683 from NativeScript/kerezov/merge-cocoapods-correctly
Do not truncate `platform/ios/Podfile` upon each plugin prepare
2 parents ab8a1b4 + 87a5081 commit 6062bae

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

lib/services/ios-project-service.ts

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -688,16 +688,31 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
688688
private prepareCocoapods(pluginPlatformsFolderPath: string, opts?: any): IFuture<void> {
689689
return (() => {
690690
let pluginPodFilePath = path.join(pluginPlatformsFolderPath, "Podfile");
691-
692691
if(this.$fs.exists(pluginPodFilePath).wait()) {
693-
let pluginPodFileContent = this.$fs.readText(pluginPodFilePath).wait();
694-
let contentToWrite = `use_frameworks!${os.EOL}${os.EOL}target "${this.$projectData.projectName}" do${os.EOL}${this.buildPodfileContent(pluginPodFilePath, pluginPodFileContent)}${os.EOL}end`;
695-
this.$fs.writeFile(this.projectPodFilePath, contentToWrite).wait();
692+
let pluginPodFileContent = this.$fs.readText(pluginPodFilePath).wait(),
693+
pluginPodFilePreparedContent = this.buildPodfileContent(pluginPodFilePath, pluginPodFileContent),
694+
projectPodFileContent = this.$fs.exists(this.projectPodFilePath).wait() ? this.$fs.readText(this.projectPodFilePath).wait() : "";
696695

697-
let project = this.createPbxProj();
698-
project.updateBuildProperty("IPHONEOS_DEPLOYMENT_TARGET", "8.0");
699-
this.$logger.info("The iOS Deployment Target is now 8.0 in order to support Cocoa Touch Frameworks in CocoaPods.");
700-
this.savePbxProj(project).wait();
696+
if (!~projectPodFileContent.indexOf(pluginPodFilePreparedContent)) {
697+
let podFileHeader = `use_frameworks!${os.EOL}${os.EOL}target "${this.$projectData.projectName}" do${os.EOL}`,
698+
podFileFooter = `${os.EOL}end`;
699+
700+
if (_.startsWith(projectPodFileContent, podFileHeader)) {
701+
projectPodFileContent = projectPodFileContent.substr(podFileHeader.length);
702+
}
703+
704+
if (_.endsWith(projectPodFileContent, podFileFooter)) {
705+
projectPodFileContent = projectPodFileContent.substr(0, projectPodFileContent.length - podFileFooter.length);
706+
}
707+
708+
let contentToWrite = `${podFileHeader}${projectPodFileContent}${pluginPodFilePreparedContent}${podFileFooter}`;
709+
this.$fs.writeFile(this.projectPodFilePath, contentToWrite).wait();
710+
711+
let project = this.createPbxProj();
712+
project.updateBuildProperty("IPHONEOS_DEPLOYMENT_TARGET", "8.0");
713+
this.$logger.info("The iOS Deployment Target is now 8.0 in order to support Cocoa Touch Frameworks in CocoaPods.");
714+
this.savePbxProj(project).wait();
715+
}
701716
}
702717

703718
if(opts && opts.executePodInstall && this.$fs.exists(pluginPodFilePath).wait()) {

0 commit comments

Comments
 (0)