Skip to content

feat: Add Objective-C source code to .pbxproject #3524

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

Merged
merged 13 commits into from
May 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/definitions/xcode.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ declare module "xcode" {

addPbxGroup(filePathsArray: any[], name: string, path: string, sourceTree: string): void;

removePbxGroup(groupName: string, path: string): void;

addToHeaderSearchPaths(options?: Options): void;
removeFromHeaderSearchPaths(options?: Options): void;
updateBuildProperty(key: string, value: any): void;
Expand Down
2 changes: 2 additions & 0 deletions lib/node/xcode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ declare global {
}
}

export { xcode };

$injector.register("xcode", xcode);
55 changes: 55 additions & 0 deletions lib/services/ios-project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ import * as mobileprovision from "ios-mobileprovision-finder";
import { SpawnOptions } from "child_process";
import { BUILD_XCCONFIG_FILE_NAME } from "../constants";

interface INativeSourceCodeGroup {
name: string;
path: string;
files: string[];
}

export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServiceBase implements IPlatformProjectService {
private static XCODE_PROJECT_EXT_NAME = ".xcodeproj";
private static XCODE_SCHEME_EXT_NAME = ".xcscheme";
Expand Down Expand Up @@ -924,6 +930,12 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
public async preparePluginNativeCode(pluginData: IPluginData, projectData: IProjectData, opts?: any): Promise<void> {
const pluginPlatformsFolderPath = pluginData.pluginPlatformsFolderPath(IOSProjectService.IOS_PLATFORM_NAME);

const sourcePath = path.join(pluginPlatformsFolderPath, "src");
if (this.$fs.exists(pluginPlatformsFolderPath) && this.$fs.exists(sourcePath)) {
await this.prepareNativeSourceCode(pluginData.name, sourcePath, projectData);
}

await this.prepareResources(pluginPlatformsFolderPath, pluginData, projectData);
await this.prepareFrameworks(pluginPlatformsFolderPath, pluginData, projectData);
await this.prepareStaticLibs(pluginPlatformsFolderPath, pluginData, projectData);
await this.prepareCocoapods(pluginPlatformsFolderPath, projectData);
Expand All @@ -932,6 +944,7 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
public async removePluginNativeCode(pluginData: IPluginData, projectData: IProjectData): Promise<void> {
const pluginPlatformsFolderPath = pluginData.pluginPlatformsFolderPath(IOSProjectService.IOS_PLATFORM_NAME);

this.removeNativeSourceCode(pluginPlatformsFolderPath, pluginData, projectData);
this.removeFrameworks(pluginPlatformsFolderPath, pluginData, projectData);
this.removeStaticLibs(pluginPlatformsFolderPath, pluginData, projectData);
this.removeCocoapods(pluginPlatformsFolderPath, projectData);
Expand Down Expand Up @@ -1103,6 +1116,40 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
return childProcess;
}

private async prepareNativeSourceCode(pluginName: string, pluginPlatformsFolderPath: string, projectData: IProjectData): Promise<void> {
const project = this.createPbxProj(projectData);
const group = this.getRootGroup(pluginName, pluginPlatformsFolderPath);
project.addPbxGroup(group.files, group.name, group.path, null, {isMain:true});
project.addToHeaderSearchPaths(group.path);
this.savePbxProj(project, projectData);
}

private getRootGroup(name: string, rootPath: string) {
const filePathsArr: string[] = [];
const rootGroup: INativeSourceCodeGroup = { name: name, files: filePathsArr, path: rootPath };

if (this.$fs.exists(rootPath) && !this.$fs.isEmptyDir(rootPath)) {
this.$fs.readDirectory(rootPath).forEach(fileName => {
const filePath = path.join(rootGroup.path, fileName);
filePathsArr.push(filePath);
});
}

return rootGroup;
}

private async prepareResources(pluginPlatformsFolderPath: string, pluginData: IPluginData, projectData: IProjectData): Promise<void> {
const project = this.createPbxProj(projectData);
const resourcesPath = path.join(pluginPlatformsFolderPath, "Resources");
if (this.$fs.exists(resourcesPath) && !this.$fs.isEmptyDir(resourcesPath)) {
for (const fileName of this.$fs.readDirectory(resourcesPath)) {
const filePath = path.join(resourcesPath, fileName);

project.addResourceFile(filePath);
}
}
this.savePbxProj(project, projectData);
}
private async prepareFrameworks(pluginPlatformsFolderPath: string, pluginData: IPluginData, projectData: IProjectData): Promise<void> {
for (const fileName of this.getAllLibsForPluginWithFileExtension(pluginData, ".framework")) {
await this.addFramework(path.join(pluginPlatformsFolderPath, fileName), projectData);
Expand Down Expand Up @@ -1147,6 +1194,14 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
}
}

private removeNativeSourceCode(pluginPlatformsFolderPath: string, pluginData: IPluginData, projectData: IProjectData): void {
const project = this.createPbxProj(projectData);
const group = this.getRootGroup(pluginData.name, pluginPlatformsFolderPath);
project.removePbxGroup(group.name, group.path);
project.removeFromHeaderSearchPaths(group.path);
this.savePbxProj(project, projectData);
}

private removeFrameworks(pluginPlatformsFolderPath: string, pluginData: IPluginData, projectData: IProjectData): void {
const project = this.createPbxProj(projectData);
_.each(this.getAllLibsForPluginWithFileExtension(pluginData, ".framework"), fileName => {
Expand Down
Loading