1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4  value: true
5});
6exports.formatDeviceFamilies = formatDeviceFamilies;
7exports.getDeviceFamilies = getDeviceFamilies;
8exports.getIsTabletOnly = getIsTabletOnly;
9exports.getSupportsTablet = getSupportsTablet;
10exports.setDeviceFamily = setDeviceFamily;
11exports.withDeviceFamily = void 0;
12function _iosPlugins() {
13  const data = require("../plugins/ios-plugins");
14  _iosPlugins = function () {
15    return data;
16  };
17  return data;
18}
19function _warnings() {
20  const data = require("../utils/warnings");
21  _warnings = function () {
22    return data;
23  };
24  return data;
25}
26const withDeviceFamily = config => {
27  return (0, _iosPlugins().withXcodeProject)(config, async config => {
28    config.modResults = await setDeviceFamily(config, {
29      project: config.modResults
30    });
31    return config;
32  });
33};
34exports.withDeviceFamily = withDeviceFamily;
35function getSupportsTablet(config) {
36  var _config$ios;
37  return !!((_config$ios = config.ios) !== null && _config$ios !== void 0 && _config$ios.supportsTablet);
38}
39function getIsTabletOnly(config) {
40  var _config$ios2;
41  return !!(config !== null && config !== void 0 && (_config$ios2 = config.ios) !== null && _config$ios2 !== void 0 && _config$ios2.isTabletOnly);
42}
43function getDeviceFamilies(config) {
44  var _config$ios3;
45  const supportsTablet = getSupportsTablet(config);
46  const isTabletOnly = getIsTabletOnly(config);
47  if (isTabletOnly && ((_config$ios3 = config.ios) === null || _config$ios3 === void 0 ? void 0 : _config$ios3.supportsTablet) === false) {
48    (0, _warnings().addWarningIOS)('ios.supportsTablet', `Found contradictory values: \`{ ios: { isTabletOnly: true, supportsTablet: false } }\`. Using \`{ isTabletOnly: true }\`.`);
49  }
50
51  // 1 is iPhone, 2 is iPad
52  if (isTabletOnly) {
53    return [2];
54  } else if (supportsTablet) {
55    return [1, 2];
56  } else {
57    // is iPhone only
58    return [1];
59  }
60}
61
62/**
63 * Wrapping the families in double quotes is the only way to set a value with a comma in it.
64 *
65 * @param deviceFamilies
66 */
67function formatDeviceFamilies(deviceFamilies) {
68  return `"${deviceFamilies.join(',')}"`;
69}
70
71/**
72 * Add to pbxproj under TARGETED_DEVICE_FAMILY
73 */
74function setDeviceFamily(config, {
75  project
76}) {
77  const deviceFamilies = formatDeviceFamilies(getDeviceFamilies(config));
78  const configurations = project.pbxXCBuildConfigurationSection();
79  // @ts-ignore
80  for (const {
81    buildSettings
82  } of Object.values(configurations || {})) {
83    // Guessing that this is the best way to emulate Xcode.
84    // Using `project.addToBuildSettings` modifies too many targets.
85    if (typeof (buildSettings === null || buildSettings === void 0 ? void 0 : buildSettings.PRODUCT_NAME) !== 'undefined') {
86      if (typeof (buildSettings === null || buildSettings === void 0 ? void 0 : buildSettings.TVOS_DEPLOYMENT_TARGET) !== 'undefined') {
87        buildSettings.TARGETED_DEVICE_FAMILY = '3';
88      } else {
89        buildSettings.TARGETED_DEVICE_FAMILY = deviceFamilies;
90      }
91    }
92  }
93  return project;
94}
95//# sourceMappingURL=DeviceFamily.js.map