1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 | const path_1 = __importDefault(require("path"));
|
7 | const glob_1 = require("glob");
|
8 | const fs_extra_1 = __importDefault(require("fs-extra"));
|
9 | const WarningAggregator_1 = require("../WarningAggregator");
|
10 | const Xcodeproj_1 = require("./utils/Xcodeproj");
|
11 |
|
12 | function setICloudEntitlement(config, _appleTeamId, entitlementsPlist) {
|
13 | var _a;
|
14 | if ((_a = config.ios) === null || _a === void 0 ? void 0 : _a.usesIcloudStorage) {
|
15 |
|
16 | WarningAggregator_1.addWarningIOS('ios.usesIcloudStorage', 'Enable the iCloud Storage Entitlement from the Capabilities tab in your Xcode project.'
|
17 |
|
18 | );
|
19 | }
|
20 | return entitlementsPlist;
|
21 | }
|
22 | exports.setICloudEntitlement = setICloudEntitlement;
|
23 | function setAppleSignInEntitlement(config, entitlementsPlist) {
|
24 | var _a;
|
25 | if ((_a = config.ios) === null || _a === void 0 ? void 0 : _a.usesAppleSignIn) {
|
26 | return Object.assign(Object.assign({}, entitlementsPlist), { 'com.apple.developer.applesignin': ['Default'] });
|
27 | }
|
28 | return entitlementsPlist;
|
29 | }
|
30 | exports.setAppleSignInEntitlement = setAppleSignInEntitlement;
|
31 | function setAccessesContactNotes(config, entitlementsPlist) {
|
32 | var _a;
|
33 | if ((_a = config.ios) === null || _a === void 0 ? void 0 : _a.accessesContactNotes) {
|
34 | return Object.assign(Object.assign({}, entitlementsPlist), { 'com.apple.developer.contacts.notes': config.ios.accessesContactNotes });
|
35 | }
|
36 | return entitlementsPlist;
|
37 | }
|
38 | exports.setAccessesContactNotes = setAccessesContactNotes;
|
39 | function setAssociatedDomains(config, entitlementsPlist) {
|
40 | var _a;
|
41 | if ((_a = config.ios) === null || _a === void 0 ? void 0 : _a.associatedDomains) {
|
42 | return Object.assign(Object.assign({}, entitlementsPlist), { 'com.apple.developer.associated-domains': config.ios.associatedDomains });
|
43 | }
|
44 | return entitlementsPlist;
|
45 | }
|
46 | exports.setAssociatedDomains = setAssociatedDomains;
|
47 | function getEntitlementsPath(projectRoot) {
|
48 | var _a;
|
49 | return _a = getExistingEntitlementsPath(projectRoot), (_a !== null && _a !== void 0 ? _a : createEntitlementsFile(projectRoot));
|
50 | }
|
51 | exports.getEntitlementsPath = getEntitlementsPath;
|
52 | function createEntitlementsFile(projectRoot) {
|
53 | |
54 |
|
55 |
|
56 | const entitlementsPath = getDefaultEntitlementsPath(projectRoot);
|
57 | if (!fs_extra_1.default.pathExistsSync(path_1.default.dirname(entitlementsPath))) {
|
58 | fs_extra_1.default.mkdirSync(path_1.default.dirname(entitlementsPath));
|
59 | }
|
60 | fs_extra_1.default.writeFileSync(entitlementsPath, ENTITLEMENTS_TEMPLATE);
|
61 | const entitlementsRelativePath = entitlementsPath.replace(`${projectRoot}/ios/`, '');
|
62 | |
63 |
|
64 |
|
65 | const project = Xcodeproj_1.getPbxproj(projectRoot);
|
66 | Object.entries(project.pbxXCBuildConfigurationSection())
|
67 | .filter(Xcodeproj_1.removeComments)
|
68 | .filter(Xcodeproj_1.isBuildConfig)
|
69 | .filter(Xcodeproj_1.removeTestHosts)
|
70 | .forEach(({ 1: { buildSettings } }) => {
|
71 | buildSettings.CODE_SIGN_ENTITLEMENTS = entitlementsRelativePath;
|
72 | });
|
73 | fs_extra_1.default.writeFileSync(project.filepath, project.writeSync());
|
74 | return entitlementsPath;
|
75 | }
|
76 | function getDefaultEntitlementsPath(projectRoot) {
|
77 | const projectName = Xcodeproj_1.getProjectName(projectRoot);
|
78 | const project = Xcodeproj_1.getPbxproj(projectRoot);
|
79 | const productName = project.productName;
|
80 | return path_1.default.join(projectRoot, 'ios', projectName, `${productName}.entitlements`);
|
81 | }
|
82 | const ENTITLEMENTS_TEMPLATE = `
|
83 | <?xml version="1.0" encoding="UTF-8"?>
|
84 | <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
85 | <plist version="1.0">
|
86 | <dict>
|
87 | </dict>
|
88 | </plist>
|
89 | `;
|
90 |
|
91 |
|
92 |
|
93 | function getExistingEntitlementsPath(projectRoot) {
|
94 | const entitlementsPaths = glob_1.sync(path_1.default.join(projectRoot, 'ios', '*', '.entitlements'));
|
95 | if (entitlementsPaths.length === 0) {
|
96 | return null;
|
97 | }
|
98 | let [entitlementsPath, ...otherEntitlementsPaths] = entitlementsPaths[0];
|
99 | if (entitlementsPaths.length > 1) {
|
100 | console.warn(`Found multiple entitlements paths, using ${entitlementsPath}. Other paths ${JSON.stringify(otherEntitlementsPaths)} ignored.`);
|
101 | }
|
102 | return entitlementsPath;
|
103 | }
|
104 |
|
\ | No newline at end of file |