TypeScript type definitions for React Native Community CLI configuration and command structures
—
Complete iOS platform configuration types with CocoaPods integration, Xcode project handling, and script phase management for React Native development.
Complete iOS project configuration defining Xcode project structure, CocoaPods settings, and development workflow parameters.
/**
* Complete iOS project configuration
*/
interface IOSProjectConfig {
/** Source directory containing iOS code (e.g., "ios") */
sourceDir: string;
/** Xcode project information (null if no Xcode project found) */
xcodeProject: IOSProjectInfo | null;
/** Additional command parameters for watch mode */
watchModeCommandParams?: string[];
/** Whether to automatically run 'pod install' */
automaticPodsInstallation?: boolean;
/** Asset directories for this platform */
assets: string[];
}
/**
* Xcode project information
*/
type IOSProjectInfo = {
/** Project or workspace name */
name: string;
/** Path to .xcodeproj or .xcworkspace file */
path: string;
/** Whether this is a workspace (.xcworkspace) or project (.xcodeproj) */
isWorkspace: boolean;
};Usage Examples:
import { IOSProjectConfig, IOSProjectInfo } from "@react-native-community/cli-types";
// Standard iOS project configuration
const iosConfig: IOSProjectConfig = {
sourceDir: "ios",
xcodeProject: {
name: "MyReactNativeApp",
path: "ios/MyReactNativeApp.xcodeproj",
isWorkspace: false
},
watchModeCommandParams: ["--verbose"],
automaticPodsInstallation: true,
assets: ["./ios/MyReactNativeApp/Images.xcassets"]
};
// Configuration with workspace
const workspaceConfig: IOSProjectConfig = {
sourceDir: "ios",
xcodeProject: {
name: "MyReactNativeApp",
path: "ios/MyReactNativeApp.xcworkspace",
isWorkspace: true
},
automaticPodsInstallation: true,
assets: []
};
// Configuration without Xcode project
const noXcodeConfig: IOSProjectConfig = {
sourceDir: "ios",
xcodeProject: null,
automaticPodsInstallation: false,
assets: []
};
// Validate iOS configuration
function validateIOSConfig(config: IOSProjectConfig): boolean {
if (!config.sourceDir) return false;
if (config.xcodeProject) {
return !!(config.xcodeProject.name && config.xcodeProject.path);
}
return true;
}
// Get build command based on project type
function getBuildCommand(config: IOSProjectConfig): string {
if (!config.xcodeProject) return "";
const buildTarget = config.xcodeProject.isWorkspace ?
`-workspace "${config.xcodeProject.path}"` :
`-project "${config.xcodeProject.path}"`;
return `xcodebuild ${buildTarget} -scheme ${config.xcodeProject.name}`;
}Input parameters for configuring iOS projects with optional fields for auto-detection.
/**
* Parameters for iOS project configuration with optional auto-detection fields
*/
interface IOSProjectParams {
/** Source directory (optional, will be detected if not provided) */
sourceDir?: string;
/** Additional command parameters for watch mode */
watchModeCommandParams?: string[];
/** Whether to automatically run 'pod install' */
automaticPodsInstallation?: boolean;
/** Asset directories */
assets?: string[];
}Usage Examples:
import { IOSProjectParams } from "@react-native-community/cli-types";
// Minimal iOS parameters (auto-detection)
const minimalParams: IOSProjectParams = {
automaticPodsInstallation: true
};
// Full iOS parameters
const fullParams: IOSProjectParams = {
sourceDir: "ios",
watchModeCommandParams: ["--verbose", "--simulator", "iPhone 14"],
automaticPodsInstallation: true,
assets: ["./assets", "./ios/MyApp/Images.xcassets"]
};
// Parameters for manual CocoaPods management
const manualPodsParams: IOSProjectParams = {
sourceDir: "ios",
automaticPodsInstallation: false,
assets: []
};
// Create parameters from existing config
function paramsFromConfig(config: IOSProjectConfig): IOSProjectParams {
return {
sourceDir: config.sourceDir,
watchModeCommandParams: config.watchModeCommandParams,
automaticPodsInstallation: config.automaticPodsInstallation,
assets: config.assets
};
}CocoaPods-based dependency configuration with script phases and build configuration support.
/**
* iOS dependency configuration using CocoaPods
*/
interface IOSDependencyConfig {
/** Path to the podspec file */
podspecPath: string;
/** Version of the dependency */
version: string;
/** CocoaPods script phases for this dependency */
scriptPhases: Array<IOSScriptPhase>;
/** Xcode configurations this dependency supports (e.g., ["Debug", "Release"]) */
configurations: string[];
}
/**
* CocoaPods script phase configuration
* Based on CocoaPods script_phase DSL: https://www.rubydoc.info/gems/cocoapods-core/Pod/Podfile/DSL#script_phase-instance_method
*/
type IOSScriptPhase = ({script: string} | {path: string}) & {
/** Name of the script phase */
name: string;
/** Shell path for script execution (optional, defaults to /bin/sh) */
shell_path?: string;
/** Input files for the script phase */
input_files?: string[];
/** Output files for the script phase */
output_files?: string[];
/** Input file lists for the script phase */
input_file_lists?: string[];
/** Output file lists for the script phase */
output_file_lists?: string[];
/** Whether to show environment variables in build log */
show_env_vars_in_log?: boolean;
/** When to execute the script phase */
execution_position?: 'before_compile' | 'after_compile' | 'any';
/** Dependency file for incremental builds */
dependency_file?: string;
/** Whether script is always out of date (always runs) */
always_out_of_date?: string;
};Usage Examples:
import { IOSDependencyConfig, IOSScriptPhase } from "@react-native-community/cli-types";
// Simple iOS library dependency
const simpleDependency: IOSDependencyConfig = {
podspecPath: "./ios/MyLibrary.podspec",
version: "1.0.0",
scriptPhases: [],
configurations: ["Debug", "Release"]
};
// Script phase with inline script
const inlineScriptPhase: IOSScriptPhase = {
name: "Generate Assets",
script: "echo 'Generating assets...' && node scripts/generate-assets.js",
shell_path: "/bin/bash",
execution_position: "before_compile",
show_env_vars_in_log: true,
input_files: ["scripts/generate-assets.js"],
output_files: ["${BUILT_PRODUCTS_DIR}/generated-assets.json"]
};
// Script phase with external file
const fileScriptPhase: IOSScriptPhase = {
name: "Build Native Module",
path: "./scripts/build-native.sh",
execution_position: "after_compile",
input_file_lists: ["${SRCROOT}/native-sources.xcfilelist"],
output_file_lists: ["${BUILT_PRODUCTS_DIR}/native-outputs.xcfilelist"],
dependency_file: "${TEMP_DIR}/native-deps.d"
};
// Complex dependency with script phases
const complexDependency: IOSDependencyConfig = {
podspecPath: "./react-native-my-native-module.podspec",
version: "2.1.0",
scriptPhases: [
{
name: "Prepare Build Environment",
script: "mkdir -p ${BUILT_PRODUCTS_DIR}/native-temp",
execution_position: "before_compile"
},
{
name: "Post-build Cleanup",
path: "./scripts/ios-cleanup.sh",
shell_path: "/bin/bash",
execution_position: "after_compile",
show_env_vars_in_log: false
}
],
configurations: ["Debug", "Release", "Staging"]
};
// Validate script phase
function validateScriptPhase(phase: IOSScriptPhase): boolean {
const hasScript = 'script' in phase && !!phase.script;
const hasPath = 'path' in phase && !!phase.path;
return (hasScript || hasPath) && !!phase.name;
}
// Get script content for phase
function getScriptContent(phase: IOSScriptPhase): string {
if ('script' in phase) return phase.script;
if ('path' in phase) return `source "${phase.path}"`;
return "";
}Input parameters for configuring iOS dependencies with optional fields for auto-detection.
/**
* Parameters for iOS dependency configuration (excludes podspecPath and version which are auto-detected)
*/
type IOSDependencyParams = Omit<
Partial<IOSDependencyConfig>,
'podspecPath' | 'version'
>;Usage Examples:
import { IOSDependencyParams, IOSScriptPhase } from "@react-native-community/cli-types";
// Minimal dependency parameters (auto-detection)
const minimalDependencyParams: IOSDependencyParams = {};
// Parameters with custom configurations
const customConfigParams: IOSDependencyParams = {
configurations: ["Debug", "Release", "Staging"],
scriptPhases: []
};
// Parameters with script phases
const scriptPhasesParams: IOSDependencyParams = {
scriptPhases: [
{
name: "Bundle React Native Code",
script: "npx react-native bundle --platform ios --dev false",
execution_position: "before_compile",
output_files: ["${BUILT_PRODUCTS_DIR}/main.jsbundle"]
}
],
configurations: ["Debug", "Release"]
};
// Convert to full config (simulated auto-detection)
function simulateIOSConfigGeneration(
params: IOSDependencyParams,
detectedPodspecPath: string,
detectedVersion: string
): IOSDependencyConfig {
return {
podspecPath: detectedPodspecPath,
version: detectedVersion,
scriptPhases: params.scriptPhases || [],
configurations: params.configurations || ["Debug", "Release"]
};
}How iOS types integrate with the broader platform configuration system.
Usage Examples:
import { Config, IOSProjectParams, IOSDependencyParams } from "@react-native-community/cli-types";
// The iOS platform configuration is accessed through Config.platforms.ios
// Note: IOSPlatformConfig type is not exported, but the platform is accessible
// Generate iOS project config from parameters
function generateIOSProjectConfig(
config: Config,
projectRoot: string,
params?: IOSProjectParams
): IOSProjectConfig | void {
return config.platforms.ios.projectConfig(projectRoot, params);
}
// Generate iOS dependency config
function generateIOSDependencyConfig(
config: Config,
dependency: string,
params: IOSDependencyParams
): IOSDependencyConfig | void {
return config.platforms.ios.dependencyConfig(dependency, params);
}
// Check if project has iOS support
function hasIOSSupport(config: Config): boolean {
return !!config.project.ios;
}
// Get iOS build settings
function getIOSBuildSettings(config: Config) {
const iosProject = config.project.ios;
if (!iosProject) return null;
return {
sourceDir: iosProject.sourceDir,
projectName: iosProject.xcodeProject?.name,
projectPath: iosProject.xcodeProject?.path,
isWorkspace: iosProject.xcodeProject?.isWorkspace || false,
automaticPods: iosProject.automaticPodsInstallation || false
};
}
// Count script phases across all iOS dependencies
function countIOSScriptPhases(config: Config): number {
return Object.values(config.dependencies)
.map(dep => dep.platforms.ios?.scriptPhases?.length || 0)
.reduce((total, count) => total + count, 0);
}
// Access iOS platform through config
function getIOSSettings(config: Config) {
const iosPlatform = config.platforms.ios;
return {
npmPackageName: iosPlatform.npmPackageName,
hasProjectConfig: typeof iosPlatform.projectConfig === 'function',
hasDependencyConfig: typeof iosPlatform.dependencyConfig === 'function'
};
}Install with Tessl CLI
npx tessl i tessl/npm-react-native-community--cli-types