UNPKG

apple-targets-hugo-patch

Version:
72 lines (71 loc) 3.3 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.withTargetsDir = void 0; const glob_1 = require("glob"); const path_1 = __importDefault(require("path")); const chalk_1 = __importDefault(require("chalk")); const withPodTargetExtension_1 = require("./withPodTargetExtension"); const withWidget_1 = __importDefault(require("./withWidget")); const withXcparse_1 = require("./withXcparse"); let hasWarned = false; const withTargetsDir = (config, _props) => { var _a; let { appleTeamId = (_a = config === null || config === void 0 ? void 0 : config.ios) === null || _a === void 0 ? void 0 : _a.appleTeamId } = _props || {}; const { root = "./targets", match = "*" } = _props || {}; const projectRoot = config._internal.projectRoot; if (!appleTeamId && !hasWarned) { hasWarned = true; console.warn((0, chalk_1.default) `{yellow [bacons/apple-targets]} Expo config is missing required {cyan ios.appleTeamId} property. Find this in Xcode and add to the Expo Config to correct. iOS builds may fail until this is corrected.`); } const targets = (0, glob_1.globSync)(`${root}/${match}/expo-target.config.@(json|js)`, { // const targets = globSync(`./targets/action/expo-target.config.@(json|js)`, { cwd: projectRoot, absolute: true, }); const evaluatedTargets = targets.map((configPath) => { const targetConfig = require(configPath); let evaluatedTargetConfigObject = targetConfig; // If it's a function, evaluate it if (typeof targetConfig === "function") { evaluatedTargetConfigObject = targetConfig(config); if (typeof evaluatedTargetConfigObject !== "object") { throw new Error(`Expected target config function to return an object, but got ${typeof evaluatedTargetConfigObject}`); } } else if (typeof targetConfig !== "object") { throw new Error(`Expected target config to be an object or function that returns an object, but got ${typeof targetConfig}`); } if (!evaluatedTargetConfigObject.type) { throw new Error(`Expected target config to have a 'type' property denoting the type of target it is, e.g. 'widget'`); } return { ...evaluatedTargetConfigObject, directory: path_1.default.relative(projectRoot, path_1.default.dirname(configPath)), configPath, }; }); // Sort so that any watch-widget targets come before any watch targets, LIFO evaluatedTargets.sort((a, b) => { if (a.type === "watch-widget") { return -1; } if (b.type === "watch-widget") { return 1; } return 0; }); evaluatedTargets.forEach((target) => { config = (0, withWidget_1.default)(config, { appleTeamId, ...target, }); }); (0, withPodTargetExtension_1.withPodTargetExtension)(config); (0, withXcparse_1.withXcodeProjectBetaBaseMod)(config); return config; }; exports.withTargetsDir = withTargetsDir; module.exports = exports.withTargetsDir;