Skip to content

Commit 9c796ac

Browse files
committed
feat: Add plugin src folder to pbx groups
1 parent 073fa50 commit 9c796ac

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

lib/services/ios-project-service.ts

Lines changed: 52 additions & 0 deletions
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 NativeSourceCodeDescription {
22+
path: string;
23+
name: string;
24+
}
25+
26+
interface NativeSourceCodeGroup {
27+
name: string;
28+
path: string;
29+
files: NativeSourceCodeDescription[];
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,12 @@ 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+
939+
let sourcePath = path.join(pluginPlatformsFolderPath, "src");
940+
if (this.$fs.exists(pluginPlatformsFolderPath) && this.$fs.exists(sourcePath)) {
941+
await this.prepareNativeSourceCode(pluginData.name, sourcePath, projectData);
942+
}
943+
927944
await this.prepareFrameworks(pluginPlatformsFolderPath, pluginData, projectData);
928945
await this.prepareStaticLibs(pluginPlatformsFolderPath, pluginData, projectData);
929946
await this.prepareCocoapods(pluginPlatformsFolderPath, projectData);
@@ -1103,6 +1120,41 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
11031120
return childProcess;
11041121
}
11051122

1123+
private async prepareNativeSourceCode(pluginName: string, pluginPlatformsFolderPath: string, projectData: IProjectData): Promise<void> {
1124+
1125+
const project = this.createPbxProj(projectData);
1126+
1127+
let groupsArr:NativeSourceCodeGroup[] = [];
1128+
let arrObj = {arr: groupsArr};
1129+
this.createSourceArray(pluginName, pluginPlatformsFolderPath, arrObj);
1130+
//iterate backwards as the root level directory is added first
1131+
for (let i = groupsArr.length-1; i >= 0; i--) {
1132+
const el = groupsArr[i];
1133+
project.addPbxGroup(el.files.map(f => f.path), el.name, el.path)
1134+
project.addToHeaderSearchPaths(el.path);
1135+
}
1136+
1137+
this.savePbxProj(project, projectData);
1138+
}
1139+
1140+
private createSourceArray(name: string,rootPath: string, groupsArr: any) {
1141+
let filesArr: NativeSourceCodeDescription[] = [];
1142+
let rootGroup: NativeSourceCodeGroup = { name: name, files: filesArr, path: rootPath };
1143+
1144+
if (this.$fs.exists(rootPath) && !this.$fs.isEmptyDir(rootPath)) {
1145+
this.$fs.readDirectory(rootPath).forEach(fileName => {
1146+
let filePath = path.join(rootGroup.path, fileName);
1147+
let file: NativeSourceCodeDescription = { name: fileName, path: filePath};
1148+
filesArr.push(file);
1149+
if (this.$fs.getFsStats(filePath).isDirectory()) {
1150+
this.createSourceArray(file.name, file.path, groupsArr);
1151+
}
1152+
});
1153+
}
1154+
1155+
groupsArr.arr.push(rootGroup);
1156+
}
1157+
11061158
private async prepareFrameworks(pluginPlatformsFolderPath: string, pluginData: IPluginData, projectData: IProjectData): Promise<void> {
11071159
for (const fileName of this.getAllLibsForPluginWithFileExtension(pluginData, ".framework")) {
11081160
await this.addFramework(path.join(pluginPlatformsFolderPath, fileName), projectData);

0 commit comments

Comments
 (0)