Skip to content

Commit 9b35c64

Browse files
authored
Merge pull request #3524 from NativeScript/tdermendzhiev/objc-source-support
feat: Add Objective-C source code to .pbxproject
2 parents fff9bbe + 4a9a6c0 commit 9b35c64

File tree

7 files changed

+620
-63
lines changed

7 files changed

+620
-63
lines changed

lib/definitions/xcode.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ declare module "xcode" {
2020

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

23+
removePbxGroup(groupName: string, path: string): void;
24+
2325
addToHeaderSearchPaths(options?: Options): void;
2426
removeFromHeaderSearchPaths(options?: Options): void;
2527
updateBuildProperty(key: string, value: any): void;

lib/node/xcode.ts

+2
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ declare global {
88
}
99
}
1010

11+
export { xcode };
12+
1113
$injector.register("xcode", xcode);

lib/services/ios-project-service.ts

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

20+
interface INativeSourceCodeGroup {
21+
name: string;
22+
path: string;
23+
files: string[];
24+
}
25+
2026
export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServiceBase implements IPlatformProjectService {
2127
private static XCODE_PROJECT_EXT_NAME = ".xcodeproj";
2228
private static XCODE_SCHEME_EXT_NAME = ".xcscheme";
@@ -924,6 +930,12 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
924930
public async preparePluginNativeCode(pluginData: IPluginData, projectData: IProjectData, opts?: any): Promise<void> {
925931
const pluginPlatformsFolderPath = pluginData.pluginPlatformsFolderPath(IOSProjectService.IOS_PLATFORM_NAME);
926932

933+
const sourcePath = path.join(pluginPlatformsFolderPath, "src");
934+
if (this.$fs.exists(pluginPlatformsFolderPath) && this.$fs.exists(sourcePath)) {
935+
await this.prepareNativeSourceCode(pluginData.name, sourcePath, projectData);
936+
}
937+
938+
await this.prepareResources(pluginPlatformsFolderPath, pluginData, projectData);
927939
await this.prepareFrameworks(pluginPlatformsFolderPath, pluginData, projectData);
928940
await this.prepareStaticLibs(pluginPlatformsFolderPath, pluginData, projectData);
929941
await this.prepareCocoapods(pluginPlatformsFolderPath, projectData);
@@ -932,6 +944,7 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
932944
public async removePluginNativeCode(pluginData: IPluginData, projectData: IProjectData): Promise<void> {
933945
const pluginPlatformsFolderPath = pluginData.pluginPlatformsFolderPath(IOSProjectService.IOS_PLATFORM_NAME);
934946

947+
this.removeNativeSourceCode(pluginPlatformsFolderPath, pluginData, projectData);
935948
this.removeFrameworks(pluginPlatformsFolderPath, pluginData, projectData);
936949
this.removeStaticLibs(pluginPlatformsFolderPath, pluginData, projectData);
937950
this.removeCocoapods(pluginPlatformsFolderPath, projectData);
@@ -1103,6 +1116,40 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
11031116
return childProcess;
11041117
}
11051118

1119+
private async prepareNativeSourceCode(pluginName: string, pluginPlatformsFolderPath: string, projectData: IProjectData): Promise<void> {
1120+
const project = this.createPbxProj(projectData);
1121+
const group = this.getRootGroup(pluginName, pluginPlatformsFolderPath);
1122+
project.addPbxGroup(group.files, group.name, group.path, null, {isMain:true});
1123+
project.addToHeaderSearchPaths(group.path);
1124+
this.savePbxProj(project, projectData);
1125+
}
1126+
1127+
private getRootGroup(name: string, rootPath: string) {
1128+
const filePathsArr: string[] = [];
1129+
const rootGroup: INativeSourceCodeGroup = { name: name, files: filePathsArr, path: rootPath };
1130+
1131+
if (this.$fs.exists(rootPath) && !this.$fs.isEmptyDir(rootPath)) {
1132+
this.$fs.readDirectory(rootPath).forEach(fileName => {
1133+
const filePath = path.join(rootGroup.path, fileName);
1134+
filePathsArr.push(filePath);
1135+
});
1136+
}
1137+
1138+
return rootGroup;
1139+
}
1140+
1141+
private async prepareResources(pluginPlatformsFolderPath: string, pluginData: IPluginData, projectData: IProjectData): Promise<void> {
1142+
const project = this.createPbxProj(projectData);
1143+
const resourcesPath = path.join(pluginPlatformsFolderPath, "Resources");
1144+
if (this.$fs.exists(resourcesPath) && !this.$fs.isEmptyDir(resourcesPath)) {
1145+
for (const fileName of this.$fs.readDirectory(resourcesPath)) {
1146+
const filePath = path.join(resourcesPath, fileName);
1147+
1148+
project.addResourceFile(filePath);
1149+
}
1150+
}
1151+
this.savePbxProj(project, projectData);
1152+
}
11061153
private async prepareFrameworks(pluginPlatformsFolderPath: string, pluginData: IPluginData, projectData: IProjectData): Promise<void> {
11071154
for (const fileName of this.getAllLibsForPluginWithFileExtension(pluginData, ".framework")) {
11081155
await this.addFramework(path.join(pluginPlatformsFolderPath, fileName), projectData);
@@ -1147,6 +1194,14 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
11471194
}
11481195
}
11491196

1197+
private removeNativeSourceCode(pluginPlatformsFolderPath: string, pluginData: IPluginData, projectData: IProjectData): void {
1198+
const project = this.createPbxProj(projectData);
1199+
const group = this.getRootGroup(pluginData.name, pluginPlatformsFolderPath);
1200+
project.removePbxGroup(group.name, group.path);
1201+
project.removeFromHeaderSearchPaths(group.path);
1202+
this.savePbxProj(project, projectData);
1203+
}
1204+
11501205
private removeFrameworks(pluginPlatformsFolderPath: string, pluginData: IPluginData, projectData: IProjectData): void {
11511206
const project = this.createPbxProj(projectData);
11521207
_.each(this.getAllLibsForPluginWithFileExtension(pluginData, ".framework"), fileName => {

0 commit comments

Comments
 (0)