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
40 changes: 40 additions & 0 deletions lib/services/ios-project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ import * as mobileprovision from "ios-mobileprovision-finder";
import { SpawnOptions } from "child_process";
import { BUILD_XCCONFIG_FILE_NAME } from "../constants";

interface INativeSourceCodeDescription {
path: string;
name: string;
}

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

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 +935,11 @@ 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.prepareFrameworks(pluginPlatformsFolderPath, pluginData, projectData);
await this.prepareStaticLibs(pluginPlatformsFolderPath, pluginData, projectData);
await this.prepareCocoapods(pluginPlatformsFolderPath, projectData);
Expand Down Expand Up @@ -1103,6 +1119,30 @@ 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.map(f => f.path), group.name, group.path, null, {isMain:true});
project.addToHeaderSearchPaths(group.path);
this.savePbxProj(project, projectData);
}

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

if (this.$fs.exists(rootPath) && !this.$fs.isEmptyDir(rootPath)) {
this.$fs.readDirectory(rootPath).forEach(fileName => {
const filePath = path.join(rootGroup.path, fileName);
const file: INativeSourceCodeDescription = { name: fileName, path: filePath};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name property doesn't seem to be used and might be removed.

filesArr.push(file);
});
}

return rootGroup;
}

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