-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathios-entitlements-service.ts
72 lines (60 loc) · 2.74 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
import * as path from "path";
import * as constants from "../constants";
import { PlistSession } from "plist-merge-patch";
export class IOSEntitlementsService {
constructor(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.projectDir,
constants.APP_FOLDER_NAME, constants.APP_RESOURCES_FOLDER_NAME,
this.$mobileHelper.normalizePlatformName(this.$devicePlatformsConstants.iOS),
entitlementsName);
return entitlementsPath;
}
public getPlatformsEntitlementsPath(projectData: IProjectData) : string {
return path.join(projectData.platformsDir, 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> {
let session = new PlistSession({ log: (txt: string) => this.$logger.trace("App.entitlements: " + txt) });
let projectDir = projectData.projectDir;
let 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)
});
};
let allPlugins = await this.getAllInstalledPlugins(projectData);
for (let plugin of allPlugins) {
let pluginInfoPlistPath = path.join(plugin.pluginPlatformsFolderPath(this.$devicePlatformsConstants.iOS),
IOSEntitlementsService.DefaultEntitlementsName);
makePatch(pluginInfoPlistPath);
}
let appEntitlementsPath = this.getDefaultAppEntitlementsPath(projectData);
if (this.$fs.exists(appEntitlementsPath)) {
makePatch(appEntitlementsPath);
}
let plistContent = session.build();
this.$logger.trace("App.entitlements: Write to: " + this.getPlatformsEntitlementsPath(projectData));
this.$fs.writeFile(this.getPlatformsEntitlementsPath(projectData), plistContent);
return;
}
private getAllInstalledPlugins(projectData: IProjectData): Promise<IPluginData[]> {
return this.$pluginsService.getAllInstalledPlugins(projectData);
}
}
$injector.register("iOSEntitlementsService", IOSEntitlementsService);