Parser utility for xcodeproj/project.pbxproj files that allows editing and writing back Xcode project files
npx @tessl/cli install tessl/npm-xcode@3.0.0xcode is a comprehensive parser utility for xcodeproj/project.pbxproj files that enables programmatic manipulation of Xcode project configurations. It provides both asynchronous and synchronous parsing capabilities, extensive file management, build configuration control, and complete project structure modification for iOS, macOS, and other Apple platform development.
npm install xcodeconst xcode = require('xcode');For ES modules:
import xcode from 'xcode';const xcode = require('xcode');
const fs = require('fs');
// Create project instance
const projectPath = 'myproject.xcodeproj/project.pbxproj';
const myProj = xcode.project(projectPath);
// Parse asynchronously
myProj.parse(function (err) {
if (err) throw err;
// Add files
myProj.addHeaderFile('src/MyHeader.h');
myProj.addSourceFile('src/MySource.m');
myProj.addFramework('MyFramework.framework');
// Write back to file
fs.writeFileSync(projectPath, myProj.writeSync());
console.log('Project updated successfully');
});
// Or parse synchronously
myProj.parseSync();
myProj.addResourceFile('resources/icon.png');
fs.writeFileSync(projectPath, myProj.writeSync());The xcode package is built around several key components:
Creates a new project instance for manipulating Xcode project files.
/**
* Create a new project instance
* @param {string} filename - Path to the .pbxproj file
* @returns {pbxProject} Project instance
*/
function project(filename);Core functionality for loading and saving Xcode project files with support for both asynchronous and synchronous operations.
/**
* Parse project file asynchronously using worker process
* @param {function} callback - Callback function(err, project)
*/
parse(callback);
/**
* Parse project file synchronously
* @returns {pbxProject} Self for chaining
*/
parseSync();
/**
* Write project data to string format
* @param {object} options - Formatting options
* @returns {string} Serialized project data
*/
writeSync(options);Comprehensive file management system supporting all Xcode file types including source files, headers, resources, plugin files, Core Data models, frameworks, and static libraries with automatic build phase integration.
/**
* Add source file to project with build phase integration
* @param {string} path - File path
* @param {object} opt - Options including target, weak linking, compiler flags
* @param {string} group - Group key for organization
* @returns {object|boolean} File object or false if exists
*/
addSourceFile(path, opt, group);
/**
* Add header file to project
* @param {string} path - File path
* @param {object} opt - Options object
* @param {string} group - Group key
* @returns {object|null} File object or null if exists
*/
addHeaderFile(path, opt, group);
/**
* Add resource file with automatic build phase integration
* @param {string} path - File path
* @param {object} opt - Options including plugin flag, target, variant group
* @param {string} group - Group key
* @returns {object|boolean} File object or false if exists
*/
addResourceFile(path, opt, group);
/**
* Add plugin file with special Cordova/PhoneGap handling
* @param {string} path - File path relative to project
* @param {object} opt - Options object including target specification
* @returns {object|null} File object or null if exists
*/
addPluginFile(path, opt);
/**
* Add Core Data model document to project
* @param {string} filePath - Path to .xcdatamodeld bundle
* @param {string} group - Group key, defaults to 'Resources'
* @param {object} opt - Options object
* @returns {object|null} File object or null if exists
*/
addDataModelDocument(filePath, group, opt);Framework and static library management with support for system frameworks, custom frameworks, embedded frameworks, weak linking, and automatic search path configuration.
/**
* Add framework to project with linking and embedding options
* @param {string} path - Framework path
* @param {object} opt - Options including customFramework, link, embed, target
* @returns {object|boolean} File object or false if exists
*/
addFramework(path, opt);
/**
* Add static library with automatic linking setup
* @param {string} path - Library path
* @param {object} opt - Options including plugin flag, target
* @returns {object|boolean} File object or false if exists
*/
addStaticLibrary(path, opt);Framework and Library Management
Project organization system for managing file groups, variant groups, and hierarchical project structure with support for custom groups, localization, and low-level PBX object manipulation.
/**
* Create new PBXGroup with files
* @param {string[]} filePathsArray - Array of file paths to include
* @param {string} name - Group name
* @param {string} path - Group path
* @param {string} sourceTree - Source tree type
* @returns {object} Group object with UUID
*/
addPbxGroup(filePathsArray, name, path, sourceTree);
/**
* Find group by name
* @param {string} name - Group name to search for
* @returns {object|null} Group object or null if not found
*/
pbxGroupByName(name);
/**
* Add file to any PBXGroup type with generic handling
* @param {object|string} file - File object or group key
* @param {string} groupKey - Target group UUID
* @param {string} groupType - PBX group type
*/
addToPbxGroupType(file, groupKey, groupType);
/**
* Get any PBX object section for direct manipulation
* @param {string} name - Section name (PBXGroup, PBXFileReference, etc.)
* @returns {object} Section object containing all items of that type
*/
getPBXObject(name);Build target management including creating new targets, managing target dependencies, and configuring target-specific build settings for iOS, macOS, watchOS, and extension targets.
/**
* Add new build target to project
* @param {string} name - Target name
* @param {string} type - Target type (application, app_extension, etc.)
* @param {string} subfolder - Target subfolder
* @param {string} bundleId - Bundle identifier
* @returns {object} Target object with UUID
*/
addTarget(name, type, subfolder, bundleId);
/**
* Add target dependency relationship
* @param {string} target - Target UUID
* @param {string[]} dependencyTargets - Array of dependency target UUIDs
* @returns {object} Target object
*/
addTargetDependency(target, dependencyTargets);Build settings and configuration management with support for Debug/Release configurations, custom build settings, search paths, linker flags, and target-specific configurations.
/**
* Add build property to configurations
* @param {string} prop - Property name
* @param {string|array} value - Property value
* @param {string} buildName - Build configuration name (Debug/Release)
*/
addBuildProperty(prop, value, buildName);
/**
* Update build property for specific target
* @param {string} prop - Property name
* @param {string|array} value - Property value
* @param {string} build - Build configuration name
* @param {string} targetName - Target name
*/
updateBuildProperty(prop, value, build, targetName);Build phase management for controlling compilation, resource copying, framework linking, and custom script execution with support for all Xcode build phase types.
/**
* Add custom build phase to target
* @param {string[]} filePathsArray - Files to include in build phase
* @param {string} buildPhaseType - Build phase type
* @param {string} comment - Build phase name/comment
* @param {string} target - Target UUID
* @param {object|string} options - Build phase options or folder type
* @param {string} subfolderPath - Subfolder path for copy phases
* @returns {object} Build phase object with UUID
*/
addBuildPhase(filePathsArray, buildPhaseType, comment, target, options, subfolderPath);Core utility functions for project management including UUID generation and project introspection.
/**
* Generate unique 24-character UUID for Xcode objects
* Ensures uniqueness by checking against existing UUIDs in project
* @returns {string} Unique 24-character uppercase hexadecimal UUID
*/
generateUuid();
/**
* Get all UUIDs currently used in the project
* Useful for debugging and ensuring UUID uniqueness
* @returns {string[]} Array of all UUIDs in project sections
*/
allUuids();/**
* Main project class representing an Xcode project
*/
class pbxProject {
constructor(filename: string);
/** Parsed project data structure */
hash: object;
/** Absolute path to project file */
filepath: string;
/** Product name from build settings */
get productName(): string;
}
/**
* File reference object with metadata
*/
class pbxFile {
constructor(filepath: string, opt?: object);
/** File basename */
basename: string;
/** Xcode file type */
lastKnownFileType: string;
/** Default group for file type */
group: string;
/** File path relative to project */
path: string;
/** Text encoding for text files */
fileEncoding?: number;
/** Source tree type */
sourceTree: string;
/** Include in index flag */
includeInIndex: number;
/** Build settings (weak linking, compiler flags, etc.) */
settings?: object;
}/**
* Options for file operations
*/
interface FileOptions {
/** Target UUID for multi-target projects */
target?: string;
/** Enable weak linking for frameworks */
weak?: boolean;
/** Custom compiler flags */
compilerFlags?: string;
/** Custom framework flag */
customFramework?: boolean;
/** Embed framework flag */
embed?: boolean;
/** Code sign on copy flag */
sign?: boolean;
/** Plugin file flag */
plugin?: boolean;
/** Explicit file type override */
explicitFileType?: string;
/** Last known file type override */
lastKnownFileType?: string;
/** Source tree override */
sourceTree?: string;
/** Default encoding override */
defaultEncoding?: number;
}/**
* Supported target types for addTarget
*/
type TargetType =
| 'application'
| 'app_extension'
| 'bundle'
| 'command_line_tool'
| 'dynamic_library'
| 'framework'
| 'static_library'
| 'unit_test_bundle'
| 'watch_app'
| 'watch2_app'
| 'watch_extension'
| 'watch2_extension';/**
* Supported build phase types
*/
type BuildPhaseType =
| 'PBXSourcesBuildPhase'
| 'PBXResourcesBuildPhase'
| 'PBXFrameworksBuildPhase'
| 'PBXCopyFilesBuildPhase'
| 'PBXShellScriptBuildPhase';