UNPKG

xcparse

Version:

pbxproj parser

98 lines 4.02 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isPBXFileReference = exports.isPBXBuildFile = exports.createReferenceList = void 0; /** Create a list of <UUID, Comment> */ function createReferenceList(project) { const strict = false; const objects = project?.objects ?? {}; const referenceCache = {}; function getXCConfigurationListComment(id) { for (const [innerId, obj] of Object.entries(objects)) { if (obj.buildConfigurationList === id) { let name = obj.name ?? obj.path ?? obj.productName; if (!name) { name = objects[obj.targets?.[0]]?.name; if (!name) { // NOTE(EvanBacon): I have no idea what I'm doing... // this is for the case where the build configuration list is pointing to the main `PBXProject` object (no name). // We locate the proxy (which may or may not be related) and use the remoteInfo property. const proxy = Object.values(objects).find((obj) => obj.isa === "PBXContainerItemProxy" && obj.containerPortal === innerId); name = proxy?.remoteInfo; } } return `Build configuration list for ${obj.isa} "${name}"`; } } return `Build configuration list for [unknown]`; } function getBuildPhaseNameContainingFile(buildFileId) { const buildPhase = Object.values(objects).find((obj) => obj.files?.includes(buildFileId)); return buildPhase ? getBuildPhaseName(buildPhase) : null; } function getPBXBuildFileComment(id, buildFile) { const buildPhaseName = getBuildPhaseNameContainingFile(id) ?? "[missing build phase]"; const name = getCommentForObject(buildFile.fileRef, objects[buildFile.fileRef]); return `${name} in ${buildPhaseName}`; } function getCommentForObject(id, object) { if (!object?.isa) { return null; } if (id in referenceCache) { return referenceCache[id]; } if (isPBXBuildFile(object)) { referenceCache[id] = getPBXBuildFileComment(id, object); } else if (isXCConfigurationList(object)) { referenceCache[id] = getXCConfigurationListComment(id); } else if (isPBXProject(object)) { referenceCache[id] = "Project object"; } else if (object.isa?.endsWith("BuildPhase")) { referenceCache[id] = getBuildPhaseName(object) ?? ""; } else { referenceCache[id] = object.name ?? object.path ?? object.isa ?? null; } return referenceCache[id] ?? null; } Object.entries(objects).forEach(([id, object]) => { if (id === project.rootObject) { return; } if (!getCommentForObject(id, object)) { if (strict) throw new Error("Failed to find comment reference for ID: " + id + ", isa: " + object.isa); } }); return referenceCache; } exports.createReferenceList = createReferenceList; function isPBXProject(val) { return val?.isa === "PBXProject"; } function isPBXBuildFile(val) { return val?.isa === "PBXBuildFile"; } exports.isPBXBuildFile = isPBXBuildFile; function isPBXFileReference(val) { return val?.isa === "PBXFileReference"; } exports.isPBXFileReference = isPBXFileReference; function isXCConfigurationList(val) { return val?.isa === "XCConfigurationList"; } function getBuildPhaseName(buildPhase) { return buildPhase.name ?? getDefaultBuildPhaseName(buildPhase.isa); } /** Return the default name for a build phase object based on the `isa` */ function getDefaultBuildPhaseName(isa) { return isa.match(/PBX([a-zA-Z]+)BuildPhase/)?.[1] ?? null; } //# sourceMappingURL=referenceBuilder.js.map