@config-plugins/tv
Version:
Config plugin to reconfigure native directories for TV development if needed
89 lines (88 loc) • 3.83 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getDeviceFamilies = exports.getIsTabletOnly = exports.getSupportsTablet = exports.formatDeviceFamilies = exports.setXcodeProjectBuildSettings = exports.withTVXcodeProject = void 0;
const config_plugins_1 = require("expo/config-plugins");
const utils_1 = require("./utils");
const pkg = require("../package.json");
const withTVXcodeProject = (config, params) => {
const isTV = (0, utils_1.isTVEnabled)(params);
const verbose = (0, utils_1.showVerboseWarnings)(params);
return (0, config_plugins_1.withXcodeProject)(config, async (config) => {
config.modResults = await setXcodeProjectBuildSettings(config, {
project: config.modResults,
isTV,
verbose,
});
return config;
});
};
exports.withTVXcodeProject = withTVXcodeProject;
function setXcodeProjectBuildSettings(config, { project, isTV, verbose, }) {
const deviceFamilies = formatDeviceFamilies(getDeviceFamilies(config));
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") {
if (isTV && buildSettings.TARGETED_DEVICE_FAMILY !== "3") {
if (verbose) {
config_plugins_1.WarningAggregator.addWarningIOS("xcodeproject", `${pkg.name}@${pkg.version}: modifying target ${buildSettings?.PRODUCT_NAME} for ${isTV ? "tvOS" : "iOS"}`);
}
buildSettings.TARGETED_DEVICE_FAMILY = "3";
buildSettings.TVOS_DEPLOYMENT_TARGET = "13.0";
buildSettings.SDKROOT = "appletvos";
if (typeof buildSettings?.IOS_DEPLOYMENT_TARGET !== "undefined") {
delete buildSettings?.IOS_DEPLOYMENT_TARGET;
}
}
else if (!isTV && buildSettings.TARGETED_DEVICE_FAMILY === "3") {
config_plugins_1.WarningAggregator.addWarningIOS("xcodeproject", `${pkg.name}@${pkg.version}: modifying target ${buildSettings?.PRODUCT_NAME} for ${isTV ? "tvOS" : "iOS"}`);
buildSettings.TARGETED_DEVICE_FAMILY = deviceFamilies;
buildSettings.IOS_DEPLOYMENT_TARGET = "13.0";
buildSettings.SDKROOT = "iphoneos";
if (typeof buildSettings?.TVOS_DEPLOYMENT_TARGET !== "undefined") {
delete buildSettings?.TVOS_DEPLOYMENT_TARGET;
}
}
}
}
return project;
}
exports.setXcodeProjectBuildSettings = setXcodeProjectBuildSettings;
/**
* Wrapping the families in double quotes is the only way to set a value with a comma in it.
*
* @param deviceFamilies
*/
function formatDeviceFamilies(deviceFamilies) {
return `"${deviceFamilies.join(",")}"`;
}
exports.formatDeviceFamilies = formatDeviceFamilies;
function getSupportsTablet(config) {
return !!config.ios?.supportsTablet;
}
exports.getSupportsTablet = getSupportsTablet;
function getIsTabletOnly(config) {
return !!config?.ios?.isTabletOnly;
}
exports.getIsTabletOnly = getIsTabletOnly;
function getDeviceFamilies(config) {
const supportsTablet = getSupportsTablet(config);
const isTabletOnly = getIsTabletOnly(config);
if (isTabletOnly && config.ios?.supportsTablet === false) {
// add warning
}
// 1 is iPhone, 2 is iPad
if (isTabletOnly) {
return [2];
}
else if (supportsTablet) {
return [1, 2];
}
else {
// is iPhone only
return [1];
}
}
exports.getDeviceFamilies = getDeviceFamilies;