-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathios-native-target-service-base.ts
96 lines (83 loc) · 3.74 KB
/
ios-native-target-service-base.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import * as path from "path";
export enum BuildNames {
debug = "Debug",
release = "Release"
}
export interface IXcodeTargetBuildConfigurationProperty {
name: string;
value: any;
buildNames?: BuildNames[];
}
export abstract class NativeTargetServiceBase {
constructor(protected $fs: IFileSystem,
protected $pbxprojDomXcode: IPbxprojDomXcode,
protected $xcode: IXcode) {
}
protected addTargetToProject(extensionsFolderPath: string, extensionFolder: string, targetType: string, project: IXcode.project, platformData: IPlatformData, parentTarget?: string): IXcode.target {
const extensionPath = path.join(extensionsFolderPath, extensionFolder);
const extensionRelativePath = path.relative(platformData.projectRoot, extensionPath);
const files = this.$fs.readDirectory(extensionPath)
.filter(filePath => !filePath.startsWith("."))
.map(filePath => path.join(extensionPath, filePath));
const target = project.addTarget(extensionFolder, targetType, extensionRelativePath, parentTarget);
project.addBuildPhase([], 'PBXSourcesBuildPhase', 'Sources', target.uuid);
project.addBuildPhase([], 'PBXResourcesBuildPhase', 'Resources', target.uuid);
project.addBuildPhase([], 'PBXFrameworksBuildPhase', 'Frameworks', target.uuid);
project.addPbxGroup(files, extensionFolder, extensionPath, null, { isMain: true, target: target.uuid, filesRelativeToProject: true });
project.addToHeaderSearchPaths(extensionPath, target.pbxNativeTarget.productName);
return target;
}
protected prepareSigning(targetUuids: string[], projectData:IProjectData, projectPath: string) {
const xcode = this.$pbxprojDomXcode.Xcode.open(projectPath);
const signing = xcode.getSigning(projectData.projectName);
if (signing !== undefined) {
_.forEach(targetUuids, targetUuid => {
if (signing.style === "Automatic") {
xcode.setAutomaticSigningStyleByTargetKey(targetUuid, signing.team);
} else {
for (const config in signing.configurations) {
const signingConfiguration = signing.configurations[config];
xcode.setManualSigningStyleByTargetKey(targetUuid, signingConfiguration);
break;
}
}
});
}
xcode.save();
}
protected getTargetDirectories(folderPath: string): string[] {
return this.$fs.readDirectory(folderPath)
.filter(fileName => {
const filePath = path.join(folderPath, fileName);
const stats = this.$fs.getFsStats(filePath);
return stats.isDirectory() && !fileName.startsWith(".");
});
}
protected setXcodeTargetBuildConfigurationProperties(properties: IXcodeTargetBuildConfigurationProperty[], targetName: string, project: IXcode.project): void {
properties.forEach(property => {
const buildNames = property.buildNames || [BuildNames.debug, BuildNames.release];
buildNames.forEach((buildName) => {
project.addBuildProperty(property.name, property.value, buildName, targetName);
});
});
}
protected setConfigurationsFromJsonFile(jsonPath: string, targetUuid: string, targetName: string, project: IXcode.project) {
if (this.$fs.exists(jsonPath)) {
const configurationJson = this.$fs.readJson(jsonPath) || {};
_.forEach(configurationJson.frameworks, framework => {
project.addFramework(
framework,
{ target: targetUuid }
);
});
if (configurationJson.assetcatalogCompilerAppiconName) {
project.addToBuildSettings("ASSETCATALOG_COMPILER_APPICON_NAME", configurationJson.assetcatalogCompilerAppiconName, targetUuid);
}
if (configurationJson.targetBuildConfigurationProperties) {
const properties: IXcodeTargetBuildConfigurationProperty[] = [];
_.forEach(configurationJson.targetBuildConfigurationProperties, (value, name: string) => properties.push({value, name}));
this.setXcodeTargetBuildConfigurationProperties(properties, targetName, project);
}
}
}
}