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