1"use strict"; 2 3Object.defineProperty(exports, "__esModule", { 4 value: true 5}); 6exports.TargetType = void 0; 7exports.findApplicationTargetWithDependenciesAsync = findApplicationTargetWithDependenciesAsync; 8exports.findFirstNativeTarget = findFirstNativeTarget; 9exports.findNativeTargetByName = findNativeTargetByName; 10exports.findSignableTargets = findSignableTargets; 11exports.getNativeTargets = getNativeTargets; 12exports.getXCBuildConfigurationFromPbxproj = getXCBuildConfigurationFromPbxproj; 13exports.isTargetOfType = isTargetOfType; 14function _BuildScheme() { 15 const data = require("./BuildScheme"); 16 _BuildScheme = function () { 17 return data; 18 }; 19 return data; 20} 21function _Xcodeproj() { 22 const data = require("./utils/Xcodeproj"); 23 _Xcodeproj = function () { 24 return data; 25 }; 26 return data; 27} 28function _string() { 29 const data = require("./utils/string"); 30 _string = function () { 31 return data; 32 }; 33 return data; 34} 35let TargetType; 36exports.TargetType = TargetType; 37(function (TargetType) { 38 TargetType["APPLICATION"] = "com.apple.product-type.application"; 39 TargetType["EXTENSION"] = "com.apple.product-type.app-extension"; 40 TargetType["WATCH"] = "com.apple.product-type.application.watchapp"; 41 TargetType["APP_CLIP"] = "com.apple.product-type.application.on-demand-install-capable"; 42 TargetType["STICKER_PACK_EXTENSION"] = "com.apple.product-type.app-extension.messages-sticker-pack"; 43 TargetType["FRAMEWORK"] = "com.apple.product-type.framework"; 44 TargetType["OTHER"] = "other"; 45})(TargetType || (exports.TargetType = TargetType = {})); 46function getXCBuildConfigurationFromPbxproj(project, { 47 targetName, 48 buildConfiguration = 'Release' 49} = {}) { 50 const [, nativeTarget] = targetName ? findNativeTargetByName(project, targetName) : findFirstNativeTarget(project); 51 const [, xcBuildConfiguration] = (0, _Xcodeproj().getBuildConfigurationForListIdAndName)(project, { 52 configurationListId: nativeTarget.buildConfigurationList, 53 buildConfiguration 54 }); 55 return xcBuildConfiguration !== null && xcBuildConfiguration !== void 0 ? xcBuildConfiguration : null; 56} 57async function findApplicationTargetWithDependenciesAsync(projectRoot, scheme) { 58 const applicationTargetName = await (0, _BuildScheme().getApplicationTargetNameForSchemeAsync)(projectRoot, scheme); 59 const project = (0, _Xcodeproj().getPbxproj)(projectRoot); 60 const [, applicationTarget] = findNativeTargetByName(project, applicationTargetName); 61 const dependencies = getTargetDependencies(project, applicationTarget); 62 return { 63 name: (0, _string().trimQuotes)(applicationTarget.name), 64 type: TargetType.APPLICATION, 65 signable: true, 66 dependencies 67 }; 68} 69function getTargetDependencies(project, parentTarget) { 70 if (!parentTarget.dependencies || parentTarget.dependencies.length === 0) { 71 return undefined; 72 } 73 const nonSignableTargetTypes = [TargetType.FRAMEWORK]; 74 return parentTarget.dependencies.map(({ 75 value 76 }) => { 77 const { 78 target: targetId 79 } = project.getPBXGroupByKeyAndType(value, 'PBXTargetDependency'); 80 const [, target] = findNativeTargetById(project, targetId); 81 const type = isTargetOfType(target, TargetType.EXTENSION) ? TargetType.EXTENSION : TargetType.OTHER; 82 return { 83 name: (0, _string().trimQuotes)(target.name), 84 type, 85 signable: !nonSignableTargetTypes.some(signableTargetType => isTargetOfType(target, signableTargetType)), 86 dependencies: getTargetDependencies(project, target) 87 }; 88 }); 89} 90function isTargetOfType(target, targetType) { 91 return (0, _string().trimQuotes)(target.productType) === targetType; 92} 93function getNativeTargets(project) { 94 const section = project.pbxNativeTargetSection(); 95 return Object.entries(section).filter(_Xcodeproj().isNotComment); 96} 97function findSignableTargets(project) { 98 const targets = getNativeTargets(project); 99 const signableTargetTypes = [TargetType.APPLICATION, TargetType.APP_CLIP, TargetType.EXTENSION, TargetType.WATCH, TargetType.STICKER_PACK_EXTENSION]; 100 const applicationTargets = targets.filter(([, target]) => { 101 for (const targetType of signableTargetTypes) { 102 if (isTargetOfType(target, targetType)) { 103 return true; 104 } 105 } 106 return false; 107 }); 108 if (applicationTargets.length === 0) { 109 throw new Error(`Could not find any signable targets in project.pbxproj`); 110 } 111 return applicationTargets; 112} 113function findFirstNativeTarget(project) { 114 const targets = getNativeTargets(project); 115 const applicationTargets = targets.filter(([, target]) => isTargetOfType(target, TargetType.APPLICATION)); 116 if (applicationTargets.length === 0) { 117 throw new Error(`Could not find any application target in project.pbxproj`); 118 } 119 return applicationTargets[0]; 120} 121function findNativeTargetByName(project, targetName) { 122 const nativeTargets = getNativeTargets(project); 123 const nativeTargetEntry = nativeTargets.find(([, i]) => (0, _string().trimQuotes)(i.name) === targetName); 124 if (!nativeTargetEntry) { 125 throw new Error(`Could not find target '${targetName}' in project.pbxproj`); 126 } 127 return nativeTargetEntry; 128} 129function findNativeTargetById(project, targetId) { 130 const nativeTargets = getNativeTargets(project); 131 const nativeTargetEntry = nativeTargets.find(([key]) => key === targetId); 132 if (!nativeTargetEntry) { 133 throw new Error(`Could not find target with id '${targetId}' in project.pbxproj`); 134 } 135 return nativeTargetEntry; 136} 137//# sourceMappingURL=Target.js.map