UNPKG

4.83 kBJavaScriptView Raw
1"use strict";
2var __importDefault = (this && this.__importDefault) || function (mod) {
3 return (mod && mod.__esModule) ? mod : { "default": mod };
4};
5Object.defineProperty(exports, "__esModule", { value: true });
6const path_1 = __importDefault(require("path"));
7const glob_1 = require("glob");
8const fs_extra_1 = __importDefault(require("fs-extra"));
9const WarningAggregator_1 = require("../WarningAggregator");
10const Xcodeproj_1 = require("./utils/Xcodeproj");
11// TODO: should it be possible to turn off these entitlements by setting false in app.json and running apply
12function setICloudEntitlement(config, _appleTeamId, entitlementsPlist) {
13 var _a;
14 if ((_a = config.ios) === null || _a === void 0 ? void 0 : _a.usesIcloudStorage) {
15 // TODO: need access to the appleTeamId for this one!
16 WarningAggregator_1.addWarningIOS('ios.usesIcloudStorage', 'Enable the iCloud Storage Entitlement from the Capabilities tab in your Xcode project.'
17 // TODO: add a link to a docs page with more information on how to do this
18 );
19 }
20 return entitlementsPlist;
21}
22exports.setICloudEntitlement = setICloudEntitlement;
23function 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}
30exports.setAppleSignInEntitlement = setAppleSignInEntitlement;
31function 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}
38exports.setAccessesContactNotes = setAccessesContactNotes;
39function 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}
46exports.setAssociatedDomains = setAssociatedDomains;
47function getEntitlementsPath(projectRoot) {
48 var _a;
49 return _a = getExistingEntitlementsPath(projectRoot), (_a !== null && _a !== void 0 ? _a : createEntitlementsFile(projectRoot));
50}
51exports.getEntitlementsPath = getEntitlementsPath;
52function createEntitlementsFile(projectRoot) {
53 /**
54 * Write file from template
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 * Add file to pbxproj under CODE_SIGN_ENTITLEMENTS
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}
76function 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}
82const 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 * Get the path to an existing entitlements file or use the default
92 */
93function 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//# sourceMappingURL=Entitlements.js.map
\No newline at end of file