-
-
Notifications
You must be signed in to change notification settings - Fork 195
/
ios-entitlements-service.ts
104 lines (92 loc) · 3.18 KB
/
ios-entitlements-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
93
94
95
96
97
98
99
100
101
102
103
104
import * as path from "path";
import { PlistSession } from "plist-merge-patch";
import { IPluginsService, IPluginData } from "../definitions/plugins";
import { IProjectData } from "../definitions/project";
import { IFileSystem } from "../common/declarations";
import { IOptions } from "../declarations";
import { injector } from "../common/yok";
export class IOSEntitlementsService {
constructor(
private $options: IOptions,
private $fs: IFileSystem,
private $logger: ILogger,
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
private $mobileHelper: Mobile.IMobileHelper,
private $pluginsService: IPluginsService
) {}
public static readonly DefaultEntitlementsName: string = "app.entitlements";
private getDefaultAppEntitlementsPath(projectData: IProjectData): string {
const entitlementsName = IOSEntitlementsService.DefaultEntitlementsName;
const entitlementsPath = path.join(
projectData.appResourcesDirectoryPath,
this.$mobileHelper.normalizePlatformName(
this.$options.platformOverride ?? this.$devicePlatformsConstants.iOS
),
entitlementsName
);
return entitlementsPath;
}
public getPlatformsEntitlementsPath(projectData: IProjectData): string {
return path.join(
projectData.platformsDir,
this.$options.platformOverride ??
this.$devicePlatformsConstants.iOS.toLowerCase(),
projectData.projectName,
projectData.projectName + ".entitlements"
);
}
public getPlatformsEntitlementsRelativePath(
projectData: IProjectData
): string {
return path.join(
projectData.projectName,
projectData.projectName + ".entitlements"
);
}
public async merge(projectData: IProjectData): Promise<void> {
const session = new PlistSession({
log: (txt: string) => this.$logger.trace("App.entitlements: " + txt),
});
const projectDir = projectData.projectDir;
const makePatch = (plistPath: string) => {
if (!this.$fs.exists(plistPath)) {
this.$logger.trace("No plist found at: " + plistPath);
return;
}
this.$logger.trace("Schedule merge plist at: " + plistPath);
session.patch({
name: path.relative(projectDir, plistPath),
read: () => this.$fs.readText(plistPath),
});
};
const allPlugins = await this.getAllInstalledPlugins(projectData);
for (const plugin of allPlugins) {
const pluginInfoPlistPath = path.join(
plugin.pluginPlatformsFolderPath(this.$devicePlatformsConstants.iOS),
IOSEntitlementsService.DefaultEntitlementsName
);
makePatch(pluginInfoPlistPath);
}
const appEntitlementsPath = this.getDefaultAppEntitlementsPath(projectData);
if (this.$fs.exists(appEntitlementsPath)) {
makePatch(appEntitlementsPath);
}
if ((<any>session).patches && (<any>session).patches.length > 0) {
const plistContent = session.build();
this.$logger.trace(
"App.entitlements: Write to: " +
this.getPlatformsEntitlementsPath(projectData)
);
this.$fs.writeFile(
this.getPlatformsEntitlementsPath(projectData),
plistContent
);
}
}
private getAllInstalledPlugins(
projectData: IProjectData
): Promise<IPluginData[]> {
return this.$pluginsService.getAllInstalledPlugins(projectData);
}
}
injector.register("iOSEntitlementsService", IOSEntitlementsService);