|
| 1 | +export type UUID = string; |
| 2 | + |
| 3 | +/** |
| 4 | + * A section within the pbxproj objects dict. |
| 5 | + * Keys are UUIDs mapping to object records, or `${uuid}_comment` keys mapping to strings. |
| 6 | + */ |
| 7 | +export type PbxprojSection = Record<string, Record<string, unknown> | string>; |
| 8 | + |
| 9 | +/** Known section names within `hash.project.objects`. */ |
| 10 | +export interface PbxprojObjects { |
| 11 | + PBXBuildFile: PbxprojSection; |
| 12 | + PBXFileReference: PbxprojSection; |
| 13 | + PBXGroup: PbxprojSection; |
| 14 | + PBXNativeTarget: PbxprojSection; |
| 15 | + PBXProject: PbxprojSection; |
| 16 | + XCBuildConfiguration: PbxprojSection; |
| 17 | + XCConfigurationList: PbxprojSection; |
| 18 | + PBXSourcesBuildPhase?: PbxprojSection; |
| 19 | + PBXResourcesBuildPhase?: PbxprojSection; |
| 20 | + PBXFrameworksBuildPhase?: PbxprojSection; |
| 21 | + PBXVariantGroup?: PbxprojSection; |
| 22 | + XCVersionGroup?: PbxprojSection; |
| 23 | + PBXCopyFilesBuildPhase?: PbxprojSection; |
| 24 | + PBXShellScriptBuildPhase?: PbxprojSection; |
| 25 | + PBXContainerItemProxy?: PbxprojSection; |
| 26 | + PBXTargetDependency?: PbxprojSection; |
| 27 | + [sectionName: string]: PbxprojSection | undefined; |
| 28 | +} |
| 29 | + |
| 30 | +/** The full parsed .pbxproj structure, stored as `XcodeProject.hash`. */ |
| 31 | +export interface PbxprojHash { |
| 32 | + headComment?: string; |
| 33 | + project: { |
| 34 | + archiveVersion: string; |
| 35 | + objectVersion: string; |
| 36 | + rootObject: UUID; |
| 37 | + rootObject_comment?: string; |
| 38 | + classes: Record<string, never>; |
| 39 | + objects: PbxprojObjects; |
| 40 | + }; |
| 41 | +} |
| 42 | + |
| 43 | +export interface PBXFile { |
| 44 | + basename: string; |
| 45 | + lastKnownFileType?: string; |
| 46 | + group?: string; |
| 47 | + customFramework?: boolean; |
| 48 | + dirname?: string; |
| 49 | + path?: string; |
| 50 | + fileEncoding?: number; |
| 51 | + defaultEncoding?: number; |
| 52 | + explicitFileType?: string; |
| 53 | + sourceTree: string; |
| 54 | + includeInIndex: number; |
| 55 | + settings?: { ATTRIBUTES?: string[]; COMPILER_FLAGS?: string }; |
| 56 | + plugin?: boolean; |
| 57 | + uuid?: UUID; |
| 58 | + fileRef?: UUID; |
| 59 | + target?: string; |
| 60 | + /** Child model files, set by addDataModelDocument. */ |
| 61 | + models?: PBXFile[]; |
| 62 | + /** Current version model file, set by addDataModelDocument. */ |
| 63 | + currentModel?: PBXFile; |
| 64 | + [key: string]: unknown; |
| 65 | +} |
| 66 | + |
| 67 | +export interface PBXGroup { |
| 68 | + isa: string; |
| 69 | + children: Array<{ value: UUID; comment?: string }>; |
| 70 | + name?: string; |
| 71 | + path?: string; |
| 72 | + sourceTree: string; |
| 73 | + [key: string]: unknown; |
| 74 | +} |
| 75 | + |
| 76 | +export interface PBXNativeTarget { |
| 77 | + isa: string; |
| 78 | + buildConfigurationList: UUID; |
| 79 | + buildPhases: Array<{ value: UUID; comment?: string }>; |
| 80 | + buildRules: unknown[]; |
| 81 | + dependencies: Array<{ value: UUID; comment?: string }>; |
| 82 | + name: string; |
| 83 | + productName: string; |
| 84 | + productReference: UUID; |
| 85 | + productType: string; |
| 86 | + [key: string]: unknown; |
| 87 | +} |
| 88 | + |
| 89 | +export interface PBXProject { |
| 90 | + isa: string; |
| 91 | + attributes: Record<string, unknown>; |
| 92 | + buildConfigurationList: UUID; |
| 93 | + compatibilityVersion: string; |
| 94 | + developmentRegion: string; |
| 95 | + hasScannedForEncodings: number; |
| 96 | + knownRegions: string[]; |
| 97 | + mainGroup: UUID; |
| 98 | + productRefGroup: UUID; |
| 99 | + projectDirPath: string; |
| 100 | + projectRoot: string; |
| 101 | + targets: Array<{ value: UUID; comment?: string }>; |
| 102 | + [key: string]: unknown; |
| 103 | +} |
| 104 | + |
| 105 | +export interface XCBuildConfiguration { |
| 106 | + isa: string; |
| 107 | + baseConfigurationReference?: UUID; |
| 108 | + buildSettings: Record<string, string | string[] | number>; |
| 109 | + name: string; |
| 110 | + [key: string]: unknown; |
| 111 | +} |
| 112 | + |
| 113 | +export interface XCConfigurationList { |
| 114 | + isa: string; |
| 115 | + buildConfigurations: Array<{ value: UUID; comment?: string }>; |
| 116 | + defaultConfigurationIsVisible: number; |
| 117 | + defaultConfigurationName: string; |
| 118 | + [key: string]: unknown; |
| 119 | +} |
| 120 | + |
| 121 | +export interface BuildPhaseObject { |
| 122 | + isa: string; |
| 123 | + buildActionMask: number; |
| 124 | + files: Array<{ value: UUID; comment: string }>; |
| 125 | + runOnlyForDeploymentPostprocessing: number; |
| 126 | + name?: string; |
| 127 | + /** PBXShellScriptBuildPhase */ |
| 128 | + inputPaths?: string[]; |
| 129 | + /** PBXShellScriptBuildPhase */ |
| 130 | + outputPaths?: string[]; |
| 131 | + /** PBXShellScriptBuildPhase */ |
| 132 | + shellPath?: string; |
| 133 | + /** PBXShellScriptBuildPhase */ |
| 134 | + shellScript?: string; |
| 135 | + /** PBXCopyFilesBuildPhase */ |
| 136 | + dstPath?: string; |
| 137 | + /** PBXCopyFilesBuildPhase */ |
| 138 | + dstSubfolderSpec?: number; |
| 139 | + [key: string]: unknown; |
| 140 | +} |
| 141 | + |
| 142 | +export interface PBXFileOptions { |
| 143 | + lastKnownFileType?: string; |
| 144 | + defaultEncoding?: number; |
| 145 | + customFramework?: boolean; |
| 146 | + explicitFileType?: string; |
| 147 | + weak?: boolean; |
| 148 | + compilerFlags?: string; |
| 149 | + embed?: boolean; |
| 150 | + sign?: boolean; |
| 151 | + link?: boolean; |
| 152 | + sourceTree?: string; |
| 153 | + target?: string; |
| 154 | + group?: string; |
| 155 | + plugin?: boolean; |
| 156 | + variantGroup?: boolean; |
| 157 | +} |
| 158 | + |
| 159 | +export interface WriteOptions { |
| 160 | + omitEmptyValues?: boolean; |
| 161 | +} |
| 162 | + |
| 163 | +/** |
| 164 | + * Serialized error from child process worker (not an Error instance). |
| 165 | + * `parse()` runs in a forked process via `child_process.fork()` with JSON serialization, |
| 166 | + * so only own enumerable properties survive. PEG parser errors carry `message`/`name`; |
| 167 | + * filesystem errors carry `code`/`errno`. |
| 168 | + */ |
| 169 | +export interface ParseError { |
| 170 | + /** Present for PEG parser syntax errors. */ |
| 171 | + message?: string; |
| 172 | + /** "SyntaxError" for PEG parser errors. */ |
| 173 | + name?: string; |
| 174 | + /** Filesystem error code (e.g., "ENOENT"). */ |
| 175 | + code?: string; |
| 176 | + [key: string]: unknown; |
| 177 | +} |
| 178 | + |
| 179 | +export interface XcodeProject { |
| 180 | + filepath: string; |
| 181 | + hash: PbxprojHash; |
| 182 | + readonly productName: string | undefined; |
| 183 | + |
| 184 | + parse(callback?: (err: ParseError | null, results?: unknown) => void): this; |
| 185 | + parseSync(): this; |
| 186 | + writeSync(options?: WriteOptions): string; |
| 187 | + allUuids(): UUID[]; |
| 188 | + generateUuid(): UUID; |
| 189 | + |
| 190 | + // File management |
| 191 | + addPluginFile(path: string, opt?: PBXFileOptions): PBXFile | null; |
| 192 | + removePluginFile(path: string, opt?: PBXFileOptions): PBXFile; |
| 193 | + addProductFile(targetPath: string, opt?: PBXFileOptions): PBXFile; |
| 194 | + removeProductFile(path: string, opt?: PBXFileOptions): PBXFile; |
| 195 | + addSourceFile(path: string, opt?: PBXFileOptions, group?: string): PBXFile | false; |
| 196 | + removeSourceFile(path: string, opt?: PBXFileOptions, group?: string): PBXFile; |
| 197 | + addHeaderFile(path: string, opt?: PBXFileOptions, group?: string): PBXFile | null; |
| 198 | + removeHeaderFile(path: string, opt?: PBXFileOptions, group?: string): PBXFile; |
| 199 | + addResourceFile(path: string, opt?: PBXFileOptions, group?: string): PBXFile | false; |
| 200 | + removeResourceFile(path: string, opt?: PBXFileOptions, group?: string): PBXFile; |
| 201 | + addFramework(path: string, opt?: PBXFileOptions): PBXFile | false; |
| 202 | + removeFramework(path: string, opt?: PBXFileOptions): PBXFile; |
| 203 | + addCopyfile(path: string, opt?: PBXFileOptions): PBXFile; |
| 204 | + removeCopyfile(path: string, opt?: PBXFileOptions): PBXFile; |
| 205 | + addStaticLibrary(path: string, opt?: PBXFileOptions): PBXFile | false; |
| 206 | + hasFile(filePath: string): PBXFile | false; |
| 207 | + addFile(path: string, group?: string, opt?: PBXFileOptions): PBXFile | null; |
| 208 | + removeFile(path: string, group?: string, opt?: PBXFileOptions): PBXFile; |
| 209 | + addDataModelDocument(filePath: string, group?: string, opt?: PBXFileOptions): PBXFile | null; |
| 210 | + |
| 211 | + // Section manipulation |
| 212 | + addToPbxBuildFileSection(file: PBXFile): void; |
| 213 | + removeFromPbxBuildFileSection(file: PBXFile): void; |
| 214 | + addToPbxFileReferenceSection(file: PBXFile): void; |
| 215 | + removeFromPbxFileReferenceSection(file: PBXFile): PBXFile; |
| 216 | + addToXcVersionGroupSection(file: PBXFile): void; |
| 217 | + |
| 218 | + // Group management |
| 219 | + addPbxGroup( |
| 220 | + filePathsArray: string[], |
| 221 | + name: string, |
| 222 | + path: string, |
| 223 | + sourceTree?: string, |
| 224 | + ): { uuid: UUID; pbxGroup: PBXGroup }; |
| 225 | + removePbxGroup(groupName: string): void; |
| 226 | + addToPluginsPbxGroup(file: PBXFile): void; |
| 227 | + removeFromPluginsPbxGroup(file: PBXFile): void; |
| 228 | + addToResourcesPbxGroup(file: PBXFile): void; |
| 229 | + removeFromResourcesPbxGroup(file: PBXFile): void; |
| 230 | + addToFrameworksPbxGroup(file: PBXFile): void; |
| 231 | + removeFromFrameworksPbxGroup(file: PBXFile): void; |
| 232 | + addToProductsPbxGroup(file: PBXFile): void; |
| 233 | + removeFromProductsPbxGroup(file: PBXFile): void; |
| 234 | + addToPbxGroupType(file: PBXFile | string, groupKey: string, groupType: string): void; |
| 235 | + addToPbxVariantGroup(file: PBXFile | string, groupKey: string): void; |
| 236 | + addToPbxGroup(file: PBXFile | string, groupKey: string): void; |
| 237 | + pbxCreateGroupWithType(name: string, pathName: string | undefined, groupType: string): UUID; |
| 238 | + pbxCreateVariantGroup(name: string): UUID; |
| 239 | + pbxCreateGroup(name: string, pathName: string): UUID; |
| 240 | + removeFromPbxGroupAndType(file: PBXFile, groupKey: string, groupType: string): void; |
| 241 | + removeFromPbxGroup(file: PBXFile, groupKey: string): void; |
| 242 | + removeFromPbxVariantGroup(file: PBXFile, groupKey: string): void; |
| 243 | + getPBXGroupByKeyAndType(key: string, groupType: string): PBXGroup | undefined; |
| 244 | + getPBXGroupByKey(key: string): PBXGroup | undefined; |
| 245 | + getPBXVariantGroupByKey(key: string): PBXGroup | undefined; |
| 246 | + findPBXGroupKeyAndType(criteria: Record<string, string>, groupType: string): string | undefined; |
| 247 | + findPBXGroupKey(criteria: Record<string, string>): string | undefined; |
| 248 | + findPBXVariantGroupKey(criteria: Record<string, string>): string | undefined; |
| 249 | + addLocalizationVariantGroup(name: string): { uuid: UUID; fileRef: UUID; basename: string }; |
| 250 | + |
| 251 | + // Build phase management |
| 252 | + addToPbxEmbedFrameworksBuildPhase(file: PBXFile): void; |
| 253 | + removeFromPbxEmbedFrameworksBuildPhase(file: PBXFile): void; |
| 254 | + addToPbxSourcesBuildPhase(file: PBXFile): void; |
| 255 | + removeFromPbxSourcesBuildPhase(file: PBXFile): void; |
| 256 | + addToPbxResourcesBuildPhase(file: PBXFile): void; |
| 257 | + removeFromPbxResourcesBuildPhase(file: PBXFile): void; |
| 258 | + addToPbxFrameworksBuildPhase(file: PBXFile): void; |
| 259 | + removeFromPbxFrameworksBuildPhase(file: PBXFile): void; |
| 260 | + addToPbxCopyfilesBuildPhase(file: PBXFile): void; |
| 261 | + removeFromPbxCopyfilesBuildPhase(file: PBXFile): void; |
| 262 | + addBuildPhase( |
| 263 | + filePathsArray: string[], |
| 264 | + buildPhaseType: string, |
| 265 | + comment: string, |
| 266 | + target?: UUID, |
| 267 | + optionsOrFolderType?: string | Record<string, unknown>, |
| 268 | + subfolderPath?: string, |
| 269 | + ): { uuid: UUID; buildPhase: BuildPhaseObject }; |
| 270 | + |
| 271 | + // Target management |
| 272 | + addToPbxProjectSection(target: { uuid: UUID; pbxNativeTarget: PBXNativeTarget }): void; |
| 273 | + addToPbxNativeTargetSection(target: { uuid: UUID; pbxNativeTarget: PBXNativeTarget }): void; |
| 274 | + addXCConfigurationList( |
| 275 | + configurationObjectsArray: XCBuildConfiguration[], |
| 276 | + defaultConfigurationName: string, |
| 277 | + comment?: string, |
| 278 | + ): { uuid: UUID; xcConfigurationList: XCConfigurationList }; |
| 279 | + addTargetDependency( |
| 280 | + target: UUID, |
| 281 | + dependencyTargets: UUID[], |
| 282 | + ): { uuid: UUID; target: PBXNativeTarget } | undefined; |
| 283 | + addTarget( |
| 284 | + name: string, |
| 285 | + type: string, |
| 286 | + subfolder?: string, |
| 287 | + bundleId?: string, |
| 288 | + ): { uuid: UUID; pbxNativeTarget: PBXNativeTarget }; |
| 289 | + |
| 290 | + // Section accessors |
| 291 | + pbxProjectSection(): Record<string, PBXProject | string>; |
| 292 | + pbxBuildFileSection(): PbxprojSection; |
| 293 | + pbxXCBuildConfigurationSection(): Record<string, XCBuildConfiguration | string>; |
| 294 | + pbxFileReferenceSection(): PbxprojSection; |
| 295 | + pbxNativeTargetSection(): Record<string, PBXNativeTarget | string>; |
| 296 | + xcVersionGroupSection(): PbxprojSection; |
| 297 | + pbxXCConfigurationList(): Record<string, XCConfigurationList | string>; |
| 298 | + getPBXObject(name: string): PbxprojSection | undefined; |
| 299 | + |
| 300 | + // Section lookups |
| 301 | + pbxGroupByName(name: string): PBXGroup | null; |
| 302 | + pbxTargetByName(name: string): PBXNativeTarget | null; |
| 303 | + findTargetKey(name: string): string | null; |
| 304 | + pbxItemByComment(name: string, pbxSectionName: string): Record<string, unknown> | null; |
| 305 | + pbxSourcesBuildPhaseObj(target?: UUID): BuildPhaseObject | null; |
| 306 | + pbxResourcesBuildPhaseObj(target?: UUID): BuildPhaseObject | null; |
| 307 | + pbxFrameworksBuildPhaseObj(target?: UUID): BuildPhaseObject | null; |
| 308 | + pbxEmbedFrameworksBuildPhaseObj(target?: UUID): BuildPhaseObject | null; |
| 309 | + pbxCopyfilesBuildPhaseObj(target?: UUID): BuildPhaseObject | null; |
| 310 | + buildPhase(group: string, target?: UUID): string | undefined; |
| 311 | + buildPhaseObject(name: string, group: string, target?: UUID): BuildPhaseObject | null; |
| 312 | + |
| 313 | + // Build settings |
| 314 | + addBuildProperty(prop: string, value: string | string[] | number, buildName?: string): void; |
| 315 | + removeBuildProperty(prop: string, buildName?: string): void; |
| 316 | + updateBuildProperty(prop: string, value: string | string[] | number, build?: string, targetName?: string): void; |
| 317 | + updateProductName(name: string): void; |
| 318 | + getBuildProperty(prop: string, build?: string, targetName?: string): string | string[] | number | undefined; |
| 319 | + getBuildConfigByName(name: string): Record<string, XCBuildConfiguration>; |
| 320 | + addToFrameworkSearchPaths(file: PBXFile): void; |
| 321 | + removeFromFrameworkSearchPaths(file: PBXFile): void; |
| 322 | + addToLibrarySearchPaths(file: PBXFile | string): void; |
| 323 | + removeFromLibrarySearchPaths(file: PBXFile): void; |
| 324 | + addToHeaderSearchPaths(file: PBXFile | string): void; |
| 325 | + removeFromHeaderSearchPaths(file: PBXFile): void; |
| 326 | + addToOtherLinkerFlags(flag: string): void; |
| 327 | + removeFromOtherLinkerFlags(flag: string): void; |
| 328 | + addToBuildSettings(buildSetting: string, value: unknown): void; |
| 329 | + removeFromBuildSettings(buildSetting: string): void; |
| 330 | + |
| 331 | + // Project queries |
| 332 | + getFirstProject(): { uuid: UUID; firstProject: PBXProject }; |
| 333 | + getFirstTarget(): { uuid: UUID; firstTarget: PBXNativeTarget }; |
| 334 | + getTarget(productType: string): { uuid: UUID; target: PBXNativeTarget } | null; |
| 335 | + |
| 336 | + // Known regions |
| 337 | + addKnownRegion(name: string): void; |
| 338 | + removeKnownRegion(name: string): void; |
| 339 | + hasKnownRegion(name: string): boolean; |
| 340 | + |
| 341 | + // Target attributes |
| 342 | + addTargetAttribute(prop: string, value: unknown, target?: { uuid: UUID }): void; |
| 343 | + removeTargetAttribute(prop: string, target?: { uuid: UUID }): void; |
| 344 | +} |
| 345 | + |
| 346 | +export function project(projectPath: string): XcodeProject; |
0 commit comments