Skip to content

Commit de78502

Browse files
committed
feat: Add Objective-C source code to .pbxproject
Search for plugin's platforms/ios/src folder and add it and it's content (.h and .m files) to the native iOS project.
1 parent 073fa50 commit de78502

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

lib/services/ios-project-service.ts

+40
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@ import * as mobileprovision from "ios-mobileprovision-finder";
1818
import { SpawnOptions } from "child_process";
1919
import { BUILD_XCCONFIG_FILE_NAME } from "../constants";
2020

21+
interface INativeSourceCodeDescription {
22+
path: string;
23+
name: string;
24+
}
25+
26+
interface INativeSourceCodeGroup {
27+
name: string;
28+
path: string;
29+
files: INativeSourceCodeDescription[];
30+
}
31+
2132
export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServiceBase implements IPlatformProjectService {
2233
private static XCODE_PROJECT_EXT_NAME = ".xcodeproj";
2334
private static XCODE_SCHEME_EXT_NAME = ".xcscheme";
@@ -924,6 +935,11 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
924935
public async preparePluginNativeCode(pluginData: IPluginData, projectData: IProjectData, opts?: any): Promise<void> {
925936
const pluginPlatformsFolderPath = pluginData.pluginPlatformsFolderPath(IOSProjectService.IOS_PLATFORM_NAME);
926937

938+
const sourcePath = path.join(pluginPlatformsFolderPath, "src");
939+
if (this.$fs.exists(pluginPlatformsFolderPath) && this.$fs.exists(sourcePath)) {
940+
await this.prepareNativeSourceCode(pluginData.name, sourcePath, projectData);
941+
}
942+
927943
await this.prepareFrameworks(pluginPlatformsFolderPath, pluginData, projectData);
928944
await this.prepareStaticLibs(pluginPlatformsFolderPath, pluginData, projectData);
929945
await this.prepareCocoapods(pluginPlatformsFolderPath, projectData);
@@ -1103,6 +1119,30 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
11031119
return childProcess;
11041120
}
11051121

1122+
private async prepareNativeSourceCode(pluginName: string, pluginPlatformsFolderPath: string, projectData: IProjectData): Promise<void> {
1123+
1124+
const project = this.createPbxProj(projectData);
1125+
const group = this.getRootGroup(pluginName, pluginPlatformsFolderPath);
1126+
project.addPbxGroup(group.files.map(f => f.path), group.name, group.path, null, {isMain:true});
1127+
project.addToHeaderSearchPaths(group.path);
1128+
this.savePbxProj(project, projectData);
1129+
}
1130+
1131+
private getRootGroup(name: string, rootPath: string) {
1132+
const filesArr: INativeSourceCodeDescription[] = [];
1133+
const rootGroup: INativeSourceCodeGroup = { name: name, files: filesArr, path: rootPath };
1134+
1135+
if (this.$fs.exists(rootPath) && !this.$fs.isEmptyDir(rootPath)) {
1136+
this.$fs.readDirectory(rootPath).forEach(fileName => {
1137+
const filePath = path.join(rootGroup.path, fileName);
1138+
const file: INativeSourceCodeDescription = { name: fileName, path: filePath};
1139+
filesArr.push(file);
1140+
});
1141+
}
1142+
1143+
return rootGroup;
1144+
}
1145+
11061146
private async prepareFrameworks(pluginPlatformsFolderPath: string, pluginData: IPluginData, projectData: IProjectData): Promise<void> {
11071147
for (const fileName of this.getAllLibsForPluginWithFileExtension(pluginData, ".framework")) {
11081148
await this.addFramework(path.join(pluginPlatformsFolderPath, fileName), projectData);

0 commit comments

Comments
 (0)