@duell10111/apple-targets
Version:
Generate Apple Targets with Expo Prebuild
54 lines (53 loc) • 2.69 kB
JavaScript
;
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.sync)(`${root}/${match}/expo-target.config.@(json|js)`, {
// const targets = globSync(`./targets/action/expo-target.config.@(json|js)`, {
cwd: projectRoot,
absolute: true,
});
targets.forEach((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}`);
}
config = (0, withWidget_1.default)(config, {
appleTeamId,
...evaluatedTargetConfigObject,
directory: path_1.default.relative(projectRoot, path_1.default.dirname(configPath)),
configPath,
});
});
(0, withPodTargetExtension_1.withPodTargetExtension)(config);
(0, withXcparse_1.withXcodeProjectBetaBaseMod)(config);
return config;
};
exports.withTargetsDir = withTargetsDir;
module.exports = exports.withTargetsDir;