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
/
DeviceFamily.ts
56 lines (47 loc) · 1.61 KB
/
DeviceFamily.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
import * as fs from 'fs-extra';
import { ExpoConfig } from '../Config.types';
import { getPbxproj } from './utils/Xcodeproj';
export function getSupportsTablet(config: ExpoConfig): boolean {
return !!config.ios?.supportsTablet;
}
export function getIsTabletOnly(config: ExpoConfig): boolean {
return !!config?.ios?.isTabletOnly;
}
export function getDeviceFamilies(config: ExpoConfig): number[] {
const supportsTablet = getSupportsTablet(config);
const isTabletOnly = getIsTabletOnly(config);
// 1 is iPhone, 2 is iPad
if (isTabletOnly) {
return [2];
} else if (supportsTablet) {
return [1, 2];
} else {
// is iPhone only
return [1];
}
}
/**
* Wrapping the families in double quotes is the only way to set a value with a comma in it.
*
* @param deviceFamilies
*/
export function formatDeviceFamilies(deviceFamilies: number[]): string {
return `"${deviceFamilies.join(',')}"`;
}
/**
* Add to pbxproj under TARGETED_DEVICE_FAMILY
*/
export function setDeviceFamily(config: ExpoConfig, projectRoot: string) {
const deviceFamilies = formatDeviceFamilies(getDeviceFamilies(config));
const project = getPbxproj(projectRoot);
const configurations = project.pbxXCBuildConfigurationSection();
// @ts-ignore
for (const { buildSettings } of Object.values(configurations || {})) {
// Guessing that this is the best way to emulate Xcode.
// Using `project.addToBuildSettings` modifies too many targets.
if (typeof buildSettings?.PRODUCT_NAME !== 'undefined') {
buildSettings.TARGETED_DEVICE_FAMILY = deviceFamilies;
}
}
fs.writeFileSync(project.filepath, project.writeSync());
}