This repository has been archived by the owner on Jan 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 477
/
Entitlements.ts
137 lines (117 loc) · 3.78 KB
/
Entitlements.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import fs from 'fs-extra';
import path from 'path';
import { ExpoConfig } from '../Config.types';
import { addWarningIOS } from '../WarningAggregator';
import { InfoPlist } from './IosConfig.types';
import * as Paths from './Paths';
import {
getPbxproj,
getProjectName,
isBuildConfig,
isNotComment,
isNotTestHost,
} from './utils/Xcodeproj';
type Plist = Record<string, any>;
// TODO: should it be possible to turn off these entitlements by setting false in app.json and running apply
export function getConfigEntitlements(config: ExpoConfig) {
return config.ios?.entitlements ?? {};
}
export function setCustomEntitlementsEntries(config: ExpoConfig, entitlements: InfoPlist) {
const entries = getConfigEntitlements(config);
return {
...entitlements,
...entries,
};
}
export function setICloudEntitlement(
config: ExpoConfig,
appleTeamId: string,
entitlementsPlist: Plist
): Plist {
if (config.ios?.usesIcloudStorage) {
// TODO: need access to the appleTeamId for this one!
addWarningIOS(
'ios.usesIcloudStorage',
'Enable the iCloud Storage Entitlement from the Capabilities tab in your Xcode project.'
// TODO: add a link to a docs page with more information on how to do this
);
}
return entitlementsPlist;
}
export function setAppleSignInEntitlement(
config: ExpoConfig,
{ 'com.apple.developer.applesignin': _, ...entitlementsPlist }: Plist
): Plist {
if (config.ios?.usesAppleSignIn) {
return {
...entitlementsPlist,
'com.apple.developer.applesignin': ['Default'],
};
}
return entitlementsPlist;
}
export function setAccessesContactNotes(
config: ExpoConfig,
{ 'com.apple.developer.contacts.notes': _, ...entitlementsPlist }: Plist
): Plist {
if (config.ios?.accessesContactNotes) {
return {
...entitlementsPlist,
'com.apple.developer.contacts.notes': config.ios.accessesContactNotes,
};
}
return entitlementsPlist;
}
export function setAssociatedDomains(
config: ExpoConfig,
{ 'com.apple.developer.associated-domains': _, ...entitlementsPlist }: Plist
): Plist {
if (config.ios?.associatedDomains) {
return {
...entitlementsPlist,
'com.apple.developer.associated-domains': config.ios.associatedDomains,
};
}
return entitlementsPlist;
}
export function getEntitlementsPath(projectRoot: string): string {
return Paths.getEntitlementsPath(projectRoot) ?? createEntitlementsFile(projectRoot);
}
function createEntitlementsFile(projectRoot: string) {
/**
* Write file from template
*/
const entitlementsPath = getDefaultEntitlementsPath(projectRoot);
if (!fs.pathExistsSync(path.dirname(entitlementsPath))) {
fs.mkdirSync(path.dirname(entitlementsPath));
}
fs.writeFileSync(entitlementsPath, ENTITLEMENTS_TEMPLATE);
const entitlementsRelativePath = entitlementsPath.replace(`${projectRoot}/ios/`, '');
/**
* Add file to pbxproj under CODE_SIGN_ENTITLEMENTS
*/
const project = getPbxproj(projectRoot);
Object.entries(project.pbxXCBuildConfigurationSection())
.filter(isNotComment)
.filter(isBuildConfig)
.filter(isNotTestHost)
.forEach(({ 1: { buildSettings } }: any) => {
buildSettings.CODE_SIGN_ENTITLEMENTS = entitlementsRelativePath;
});
fs.writeFileSync(project.filepath, project.writeSync());
return entitlementsPath;
}
function getDefaultEntitlementsPath(projectRoot: string) {
const projectName = getProjectName(projectRoot);
const project = getPbxproj(projectRoot);
const productName = project.productName;
return path.join(projectRoot, 'ios', projectName, `${productName}.entitlements`);
}
const ENTITLEMENTS_TEMPLATE = `
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
</dict>
</plist>
`;