-
-
Notifications
You must be signed in to change notification settings - Fork 197
Native source code and a Podfile without a plugin #4282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
cf37f1c
229769f
60b1366
48a552e
be516bb
4a75638
3284ed5
b8b031e
fa3546d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,39 +52,40 @@ export class CocoaPodsService implements ICocoaPodsService { | |
return podInstallResult; | ||
} | ||
|
||
public async applyPluginPodfileToProject(pluginData: IPluginData, projectData: IProjectData, nativeProjectPath: string): Promise<void> { | ||
const pluginPodFilePath = this.getPluginPodfilePath(pluginData); | ||
if (!this.$fs.exists(pluginPodFilePath)) { | ||
public async applyPodfileToProject(moduleName: string, podfilePath: string, projectData: IProjectData, nativeProjectPath: string): Promise<void> { | ||
if (!this.$fs.exists(podfilePath)) { | ||
if (podfilePath === projectData.podfilePath) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need this check? |
||
this.removePodfileFromProject(moduleName, podfilePath, projectData, nativeProjectPath); | ||
} | ||
return; | ||
} | ||
|
||
const { pluginPodfileContent, replacedFunctions } = this.buildPodfileContent(pluginPodFilePath, pluginData.name); | ||
const { podfileContent, replacedFunctions } = this.buildPodfileContent(podfilePath, moduleName); | ||
const pathToProjectPodfile = this.getProjectPodfilePath(nativeProjectPath); | ||
const projectPodfileContent = this.$fs.exists(pathToProjectPodfile) ? this.$fs.readText(pathToProjectPodfile).trim() : ""; | ||
|
||
if (projectPodfileContent.indexOf(pluginPodfileContent) === -1) { | ||
if (projectPodfileContent.indexOf(podfileContent) === -1) { | ||
// Remove old occurences of the plugin from the project's Podfile. | ||
this.removePluginPodfileFromProject(pluginData, projectData, nativeProjectPath); | ||
this.removePodfileFromProject(moduleName, podfilePath, projectData, nativeProjectPath); | ||
let finalPodfileContent = this.$fs.exists(pathToProjectPodfile) ? this.getPodfileContentWithoutTarget(projectData, this.$fs.readText(pathToProjectPodfile)) : ""; | ||
|
||
if (pluginPodfileContent.indexOf(CocoaPodsService.PODFILE_POST_INSTALL_SECTION_NAME) !== -1) { | ||
finalPodfileContent = this.addPostInstallHook(replacedFunctions, finalPodfileContent, pluginPodfileContent); | ||
if (podfileContent.indexOf(CocoaPodsService.PODFILE_POST_INSTALL_SECTION_NAME) !== -1) { | ||
finalPodfileContent = this.addPostInstallHook(replacedFunctions, finalPodfileContent, podfileContent); | ||
} | ||
|
||
finalPodfileContent = `${pluginPodfileContent}${EOL}${finalPodfileContent}`; | ||
finalPodfileContent = `${podfileContent}${EOL}${finalPodfileContent}`; | ||
this.saveProjectPodfile(projectData, finalPodfileContent, nativeProjectPath); | ||
} | ||
} | ||
|
||
public removePluginPodfileFromProject(pluginData: IPluginData, projectData: IProjectData, projectRoot: string): void { | ||
const pluginPodfilePath = this.getPluginPodfilePath(pluginData); | ||
public removePodfileFromProject(moduleName: string, podfilePath: string, projectData: IProjectData, projectRoot: string): void { | ||
|
||
if (this.$fs.exists(pluginPodfilePath) && this.$fs.exists(this.getProjectPodfilePath(projectRoot))) { | ||
if ((this.$fs.exists(podfilePath) || podfilePath === projectData.podfilePath) && this.$fs.exists(this.getProjectPodfilePath(projectRoot))) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should'n we unify the behavior for plugin's pod file and pod file from |
||
let projectPodFileContent = this.$fs.readText(this.getProjectPodfilePath(projectRoot)); | ||
// Remove the data between #Begin Podfile and #EndPodfile | ||
const regExpToRemove = new RegExp(`${this.getPluginPodfileHeader(pluginPodfilePath)}[\\s\\S]*?${this.getPluginPodfileEnd()}`, "mg"); | ||
const regExpToRemove = new RegExp(`${this.getPluginPodfileHeader(podfilePath)}[\\s\\S]*?${this.getPluginPodfileEnd()}`, "mg"); | ||
projectPodFileContent = projectPodFileContent.replace(regExpToRemove, ""); | ||
projectPodFileContent = this.removePostInstallHook(pluginData, projectPodFileContent); | ||
projectPodFileContent = this.removePostInstallHook(moduleName, projectPodFileContent); | ||
|
||
const defaultPodfileBeginning = this.getPodfileHeader(projectData.projectName); | ||
const defaultContentWithPostInstallHook = `${defaultPodfileBeginning}${EOL}${this.getPostInstallHookHeader()}end${EOL}end`; | ||
|
@@ -98,7 +99,7 @@ export class CocoaPodsService implements ICocoaPodsService { | |
} | ||
} | ||
|
||
private getPluginPodfilePath(pluginData: IPluginData): string { | ||
public getPluginPodfilePath(pluginData: IPluginData): string { | ||
const pluginPlatformsFolderPath = pluginData.pluginPlatformsFolderPath(PluginNativeDirNames.iOS); | ||
const pluginPodFilePath = path.join(pluginPlatformsFolderPath, PODFILE_NAME); | ||
return pluginPodFilePath; | ||
|
@@ -157,8 +158,8 @@ export class CocoaPodsService implements ICocoaPodsService { | |
this.$fs.writeFile(projectPodfilePath, contentToWrite); | ||
} | ||
|
||
private removePostInstallHook(pluginData: IPluginData, projectPodFileContent: string): string { | ||
const regExp = new RegExp(`^.*?${this.getHookBasicFuncNameForPlugin(CocoaPodsService.PODFILE_POST_INSTALL_SECTION_NAME, pluginData.name)}.*?$\\r?\\n`, "gm"); | ||
private removePostInstallHook(moduleName: string, projectPodFileContent: string): string { | ||
const regExp = new RegExp(`^.*?${this.getHookBasicFuncNameForPlugin(CocoaPodsService.PODFILE_POST_INSTALL_SECTION_NAME, moduleName)}.*?$\\r?\\n`, "gm"); | ||
projectPodFileContent = projectPodFileContent.replace(regExp, ""); | ||
return projectPodFileContent; | ||
} | ||
|
@@ -206,12 +207,12 @@ export class CocoaPodsService implements ICocoaPodsService { | |
return `${CocoaPodsService.PODFILE_POST_INSTALL_SECTION_NAME} do |${CocoaPodsService.INSTALLER_BLOCK_PARAMETER_NAME}|${EOL}`; | ||
} | ||
|
||
private buildPodfileContent(pluginPodFilePath: string, pluginName: string): { pluginPodfileContent: string, replacedFunctions: IRubyFunction[] } { | ||
private buildPodfileContent(pluginPodFilePath: string, pluginName: string): { podfileContent: string, replacedFunctions: IRubyFunction[] } { | ||
const pluginPodfileContent = this.$fs.readText(pluginPodFilePath); | ||
const { replacedContent, newFunctions: replacedFunctions } = this.replaceHookContent(CocoaPodsService.PODFILE_POST_INSTALL_SECTION_NAME, pluginPodfileContent, pluginName); | ||
|
||
return { | ||
pluginPodfileContent: `${this.getPluginPodfileHeader(pluginPodFilePath)}${EOL}${replacedContent}${EOL}${this.getPluginPodfileEnd()}`, | ||
podfileContent: `${this.getPluginPodfileHeader(pluginPodFilePath)}${EOL}${replacedContent}${EOL}${this.getPluginPodfileEnd()}`, | ||
replacedFunctions | ||
}; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -771,20 +771,27 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f | |
this.$logger.trace(`Images to remove from xcode project: ${imagesToRemove.join(", ")}`); | ||
_.each(imagesToRemove, image => project.removeResourceFile(path.join(this.getAppResourcesDestinationDirectoryPath(projectData), image))); | ||
|
||
await this.prepareNativeSourceCode("src", path.join(projectData.appDirectoryPath, constants.APP_RESOURCES_FOLDER_NAME, this.getPlatformData(projectData).normalizedPlatformName, "src"), projectData); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could extract some "src" constants. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In case when the project has
You should use |
||
|
||
this.savePbxProj(project, projectData); | ||
} | ||
|
||
} | ||
|
||
public prepareAppResources(appResourcesDirectoryPath: string, projectData: IProjectData): void { | ||
const platformFolder = path.join(appResourcesDirectoryPath, this.getPlatformData(projectData).normalizedPlatformName); | ||
const filterFile = (filename: string) => this.$fs.deleteFile(path.join(platformFolder, filename)); | ||
|
||
filterFile(this.getPlatformData(projectData).configurationFileName); | ||
filterFile(constants.PODFILE_NAME); | ||
|
||
// src folder should not be copied as the pbxproject will have references to its files | ||
this.$fs.deleteDirectory(path.join(appResourcesDirectoryPath, this.getPlatformData(projectData).normalizedPlatformName, "src")); | ||
|
||
this.$fs.deleteDirectory(this.getAppResourcesDestinationDirectoryPath(projectData)); | ||
} | ||
|
||
public async processConfigurationFilesFromAppResources(release: boolean, projectData: IProjectData): Promise<void> { | ||
public async processConfigurationFilesFromAppResources(release: boolean, projectData: IProjectData, installPods: boolean): Promise<void> { | ||
await this.mergeInfoPlists({ release }, projectData); | ||
await this.$iOSEntitlementsService.merge(projectData); | ||
await this.mergeProjectXcconfigFiles(release, projectData); | ||
|
@@ -793,6 +800,10 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f | |
} | ||
|
||
this.$pluginVariablesService.interpolateAppIdentifier(this.getPlatformData(projectData).configurationFilePath, projectData.projectIdentifiers.ios); | ||
|
||
if (installPods) { | ||
await this.installPodsIfAny(projectData); | ||
} | ||
} | ||
|
||
private getInfoPlistPath(projectData: IProjectData): string { | ||
|
@@ -955,7 +966,7 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f | |
await this.prepareStaticLibs(pluginPlatformsFolderPath, pluginData, projectData); | ||
|
||
const projectRoot = this.getPlatformData(projectData).projectRoot; | ||
await this.$cocoapodsService.applyPluginPodfileToProject(pluginData, projectData, projectRoot); | ||
await this.$cocoapodsService.applyPodfileToProject(pluginData.name, this.$cocoapodsService.getPluginPodfilePath(pluginData), projectData, projectRoot); | ||
} | ||
|
||
public async removePluginNativeCode(pluginData: IPluginData, projectData: IProjectData): Promise<void> { | ||
|
@@ -966,12 +977,17 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f | |
this.removeStaticLibs(pluginPlatformsFolderPath, pluginData, projectData); | ||
const projectRoot = this.getPlatformData(projectData).projectRoot; | ||
|
||
this.$cocoapodsService.removePluginPodfileFromProject(pluginData, projectData, projectRoot); | ||
this.$cocoapodsService.removePodfileFromProject(pluginData.name, this.$cocoapodsService.getPluginPodfilePath(pluginData), projectData, projectRoot); | ||
} | ||
|
||
public async afterPrepareAllPlugins(projectData: IProjectData): Promise<void> { | ||
await this.installPodsIfAny(projectData); | ||
} | ||
|
||
public async installPodsIfAny(projectData: IProjectData): Promise<void> { | ||
const projectRoot = this.getPlatformData(projectData).projectRoot; | ||
if (this.$fs.exists(this.$cocoapodsService.getProjectPodfilePath(projectRoot))) { | ||
const mainPodfilePath = path.join(projectData.appResourcesDirectoryPath, this.getPlatformData(projectData).normalizedPlatformName, constants.PODFILE_NAME); | ||
if (this.$fs.exists(this.$cocoapodsService.getProjectPodfilePath(projectRoot)) || this.$fs.exists(mainPodfilePath)) { | ||
const xcodeProjPath = this.getXcodeprojPath(projectData); | ||
const xcuserDataPath = path.join(xcodeProjPath, "xcuserdata"); | ||
const sharedDataPath = path.join(xcodeProjPath, "xcshareddata"); | ||
|
@@ -984,6 +1000,8 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f | |
await this.$childProcess.exec(createSchemeRubyScript, { cwd: this.getPlatformData(projectData).projectRoot }); | ||
} | ||
|
||
await this.$cocoapodsService.applyPodfileToProject(constants.NS_BASE_PODFILE, mainPodfilePath, projectData, this.getPlatformData(projectData).projectRoot); | ||
|
||
await this.$cocoapodsService.executePodInstall(projectRoot, xcodeProjPath); | ||
} | ||
} | ||
|
@@ -1094,9 +1112,9 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f | |
this.$fs.rename(path.join(fileRootLocation, oldFileName), path.join(fileRootLocation, newFileName)); | ||
} | ||
|
||
private async prepareNativeSourceCode(pluginName: string, pluginPlatformsFolderPath: string, projectData: IProjectData): Promise<void> { | ||
private async prepareNativeSourceCode(groupName: string, sourceFolderPath: string, projectData: IProjectData): Promise<void> { | ||
const project = this.createPbxProj(projectData); | ||
const group = this.getRootGroup(pluginName, pluginPlatformsFolderPath); | ||
const group = this.getRootGroup(groupName, sourceFolderPath); | ||
project.addPbxGroup(group.files, group.name, group.path, null, { isMain: true }); | ||
project.addToHeaderSearchPaths(group.path); | ||
this.savePbxProj(project, projectData); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.