Command line tools to interact with React Native projects
—
Comprehensive type system covering CLI configuration, commands, platform definitions, and development tool integration. All types are exported from @react-native-community/cli-types.
Primary interfaces for React Native CLI configuration and project settings.
/**
* Main CLI configuration containing project settings, platforms, and commands
*/
interface Config {
/** Project root directory path */
root: string;
/** Path to React Native installation */
reactNativePath: string;
/** Platform-specific configurations (Android, iOS, etc.) */
platforms: Record<string, PlatformConfig<any, any, any, any>>;
/** Available CLI commands */
commands: Command[];
/** Project dependencies with linking configuration */
dependencies: Record<string, DependencyConfig>;
/** Asset directories to include in builds */
assets: string[];
/** Haste module system configuration */
haste: {
platforms: string[];
providesModuleNodeModules: string[];
};
/** Metro resolver configuration */
resolver: {
resolverMainFields: string[];
platforms: string[];
};
}
/**
* User-provided configuration subset that can be specified in react-native.config.js
*/
interface UserConfig {
dependencies?: Record<string, UserDependencyConfig>;
assets?: string[];
platforms?: Record<string, Partial<PlatformConfig<any, any, any, any>>>;
commands?: Command[];
}Interfaces and types for the CLI command system with conditional typing for attached and detached commands.
/**
* Generic command interface with conditional typing for attached/detached commands
*/
interface Command<IsDetached extends boolean = boolean> {
/** Command name as used in CLI */
name: string;
/** Optional command description */
description?: string;
/** Command implementation function */
func: IsDetached extends true ? DetachedCommandFunction : CommandFunction;
/** Whether command works without project configuration */
detached?: IsDetached;
/** Command-line options */
options?: CommandOption[];
/** Usage examples */
examples?: Array<{desc: string; cmd: string}>;
}
/**
* Type alias for commands that work without project configuration
*/
type DetachedCommand = Command<true>;
/**
* Function signature for attached commands (require project configuration)
*/
type CommandFunction<Args = Object> = (
argv: Array<string>,
ctx: Config,
args: Args
) => Promise<void> | void;
/**
* Function signature for detached commands (work standalone)
*/
type DetachedCommandFunction<Args = Object> = (
argv: string[],
args: Args,
ctx: Config
) => Promise<void> | void;
/**
* Command option configuration
*/
interface CommandOption<T = OptionValue> {
/** Option name/flags (e.g., '--verbose', '-v --verbose') */
name: string;
/** Option description for help text */
description?: string;
/** Optional parsing function to transform the option value */
parse?: (value: string) => T;
/** Default value or function that returns default value */
default?: T | ((config?: Config) => T);
}
/**
* Valid command option value types
*/
type OptionValue = string | boolean | number;Generic platform configuration system supporting Android, iOS, and out-of-tree platforms.
/**
* Generic platform configuration structure
*/
interface PlatformConfig<
ProjectConfig,
ProjectParams,
DependencyConfig,
DependencyParams
> {
/** Platform name identifier */
npmPackageName: string;
/** Function to find project configuration */
projectConfig: (
projectRoot: string,
projectParams: ProjectParams | void
) => ProjectConfig | void;
/** Function to find dependency configuration */
dependencyConfig: (
dependency: string,
params: DependencyParams
) => DependencyConfig | void;
}
/**
* Project configuration with Android and iOS settings
*/
interface ProjectConfig {
android?: AndroidProjectConfig;
ios?: IOSProjectConfig;
}
/**
* Dependency configuration for native linking
*/
interface DependencyConfig {
name: string;
root: string;
platforms: {
android?: AndroidDependencyConfig;
ios?: IOSDependencyConfig;
[key: string]: any;
};
}Android-specific configuration types for project setup and dependency linking.
/**
* Android project configuration
*/
interface AndroidProjectConfig {
/** Source directory path */
sourceDir: string;
/** App source directory path */
appName: string;
/** Android package name */
packageName: string;
/** Path to AndroidManifest.xml */
manifestPath: string;
/** Build.gradle file path */
buildGradlePath: string;
/** Settings.gradle file path */
settingsGradlePath: string;
/** MainActivity.java file path */
mainActivityPath: string;
/** Strings.xml file path */
stringsPath: string;
}
/**
* Parameters for Android project configuration
*/
interface AndroidProjectParams {
sourceDir?: string;
appName?: string;
packageName?: string;
manifestPath?: string;
buildGradlePath?: string;
settingsGradlePath?: string;
mainActivityPath?: string;
stringsPath?: string;
}
/**
* Android dependency configuration for native linking
*/
interface AndroidDependencyConfig {
/** Source directory containing native code */
sourceDir: string;
/** Package name for the dependency */
packageName: string;
/** Gradle dependency statement */
dependencyConfiguration?: string;
/** Path to build.gradle */
buildGradlePath?: string;
/** Library name */
libraryName?: string;
/** Component descriptors for linking */
componentDescriptors?: string[];
/** AndroidManifest.xml path */
androidMkPath?: string;
}
/**
* Parameters for Android dependency configuration
*/
interface AndroidDependencyParams {
sourceDir?: string;
packageName?: string;
dependencyConfiguration?: string;
buildGradlePath?: string;
libraryName?: string;
componentDescriptors?: string[];
androidMkPath?: string;
}iOS-specific configuration types for Xcode project setup and dependency linking.
/**
* iOS project configuration
*/
interface IOSProjectConfig {
/** Xcode project information */
xcodeProject: IOSProjectInfo;
/** CocoaPods Podfile path */
podfile: string;
/** Podspec file path */
podspecPath: string;
/** Library folder for static libraries */
libraryFolder: string;
/** Shared libraries configuration */
sharedLibraries: string[];
/** Podfile template path */
plist: string[];
}
/**
* Parameters for iOS project configuration
*/
interface IOSProjectParams {
xcodeProject?: Partial<IOSProjectInfo>;
podfile?: string;
podspecPath?: string;
libraryFolder?: string;
sharedLibraries?: string[];
plist?: string[];
}
/**
* iOS dependency configuration for native linking
*/
interface IOSDependencyConfig {
/** Podspec file path */
podspecPath: string;
/** Library name */
libraryName: string;
/** Xcode project path */
projectPath: string;
/** Shared libraries */
sharedLibraries: string[];
/** Header search paths */
headerSearchPaths: string[];
/** Script phases for build process */
scriptPhases: IOSScriptPhase[];
}
/**
* Parameters for iOS dependency configuration
*/
interface IOSDependencyParams {
podspecPath?: string;
libraryName?: string;
projectPath?: string;
sharedLibraries?: string[];
headerSearchPaths?: string[];
scriptPhases?: IOSScriptPhase[];
}
/**
* iOS project information
*/
interface IOSProjectInfo {
/** Project name */
name: string;
/** Path to .xcodeproj or .xcworkspace */
path: string;
/** Whether it's an Xcode workspace */
isWorkspace: boolean;
}
/**
* CocoaPods script phase configuration
*/
interface IOSScriptPhase {
/** Script phase name */
name: string;
/** Script path or command */
path: string;
/** Execution position in build phases */
execution_position?: 'before_compile' | 'after_compile' | 'before_headers' | 'after_headers';
/** Input file paths */
input_files?: string[];
/** Output file paths */
output_files?: string[];
}Additional utility types for CLI functionality and user configuration.
/**
* User-provided dependency configuration
*/
interface UserDependencyConfig {
/** Platforms to enable for this dependency */
platforms?: {
android?: Partial<AndroidDependencyConfig> | null;
ios?: Partial<IOSDependencyConfig> | null;
};
/** Asset directories */
assets?: string[];
/** Build hooks */
hooks?: {
prelink?: string;
postlink?: string;
preunlink?: string;
postunlink?: string;
};
}
/**
* Prompt type for interactive CLI operations
*/
type Prompt = any;import type { Config, Command, DetachedCommand } from "@react-native-community/cli-types";
// Define a project command
const myProjectCommand: Command<false> = {
name: "my-command",
description: "Custom project command",
func: async (argv: string[], config: Config, options: any) => {
console.log("Project root:", config.root);
console.log("Available platforms:", Object.keys(config.platforms));
},
options: [
{
name: "--output <path>",
description: "Output directory",
default: "./output"
}
]
};
// Define a detached command
const myDetachedCommand: DetachedCommand = {
name: "my-init",
description: "Custom init command",
detached: true,
func: async (argv: string[], options: any, config?: Config) => {
console.log("Running detached command");
if (config) {
console.log("Found project configuration");
}
}
};import type { UserConfig, AndroidProjectParams, IOSProjectParams } from "@react-native-community/cli-types";
// Custom react-native.config.js
const config: UserConfig = {
dependencies: {
"my-native-library": {
platforms: {
android: {
sourceDir: "android/src/main/java",
packageName: "com.example.mylibrary"
},
ios: {
podspecPath: "ios/MyLibrary.podspec"
}
}
}
},
assets: ["./src/assets/fonts/"]
};Install with Tessl CLI
npx tessl i tessl/npm-react-native-community--cli