-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathios-extensions-service.ts
92 lines (81 loc) · 4.02 KB
/
ios-extensions-service.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
import * as path from "path";
export class IOSExtensionsService implements IIOSExtensionsService {
constructor(private $fs: IFileSystem,
private $pbxprojDomXcode: IPbxprojDomXcode,
private $xcode: IXcode) {
}
public async addExtensionsFromPath({extensionsFolderPath, projectData, platformData, pbxProjPath}: IAddExtensionsFromPathOptions): Promise<void> {
const targetUuids: string[] = [];
if (!this.$fs.exists(extensionsFolderPath)) {
return;
}
const project = new this.$xcode.project(pbxProjPath);
project.parseSync();
this.$fs.readDirectory(extensionsFolderPath)
.filter(fileName => {
const filePath = path.join(extensionsFolderPath, fileName);
const stats = this.$fs.getFsStats(filePath);
return stats.isDirectory() && !fileName.startsWith(".");
})
.forEach(extensionFolder => {
const targetUuid = this.addExtensionToProject(extensionsFolderPath, extensionFolder, project, projectData, platformData);
targetUuids.push(targetUuid);
});
this.$fs.writeFile(pbxProjPath, project.writeSync({omitEmptyValues: true}));
this.prepareExtensionSigning(targetUuids, projectData, pbxProjPath);
}
private addExtensionToProject(extensionsFolderPath: string, extensionFolder: string, project: IXcode.project, projectData: IProjectData, platformData: IPlatformData): string {
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, 'app_extension', extensionRelativePath);
project.addBuildPhase([], 'PBXSourcesBuildPhase', 'Sources', target.uuid);
project.addBuildPhase([], 'PBXResourcesBuildPhase', 'Resources', target.uuid);
project.addBuildPhase([], 'PBXFrameworksBuildPhase', 'Frameworks', target.uuid);
const extJsonPath = path.join(extensionsFolderPath, extensionFolder, "extension.json");
if (this.$fs.exists(extJsonPath)) {
const extensionJson = this.$fs.readJson(extJsonPath);
_.forEach(extensionJson.frameworks, framework => {
project.addFramework(
framework,
{ target: target.uuid }
);
});
if (extensionJson.assetcatalogCompilerAppiconName) {
project.addToBuildSettings("ASSETCATALOG_COMPILER_APPICON_NAME", extensionJson.assetcatalogCompilerAppiconName, target.uuid);
}
}
project.addPbxGroup(files, extensionFolder, extensionPath, null, { isMain: true, target: target.uuid, filesRelativeToProject: true });
project.addBuildProperty("PRODUCT_BUNDLE_IDENTIFIER", `${projectData.projectIdentifiers.ios}.${extensionFolder}`, "Debug", extensionFolder);
project.addBuildProperty("PRODUCT_BUNDLE_IDENTIFIER", `${projectData.projectIdentifiers.ios}.${extensionFolder}`, "Release", extensionFolder);
project.addToHeaderSearchPaths(extensionPath, target.pbxNativeTarget.productName);
return target.uuid;
}
private prepareExtensionSigning(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();
}
public removeExtensions({pbxProjPath}: IRemoveExtensionsOptions): void {
const project = new this.$xcode.project(pbxProjPath);
project.parseSync();
project.removeTargetsByProductType("com.apple.product-type.app-extension");
this.$fs.writeFile(pbxProjPath, project.writeSync({omitEmptyValues: true}));
}
}
$injector.register("iOSExtensionsService", IOSExtensionsService);