TypeScript type definitions for React Native Community CLI configuration and command structures
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
React Native Community CLI Types provides comprehensive TypeScript type definitions for the React Native Community CLI ecosystem. It defines core types for CLI commands, configuration structures, platform-specific settings for Android and iOS, dependency management, and project configuration patterns, enabling type-safe development across all React Native CLI packages.
npm install @react-native-community/cli-typesimport {
Config,
Command,
ProjectConfig,
DependencyConfig,
AndroidProjectConfig,
IOSProjectConfig
} from "@react-native-community/cli-types";For CommonJS:
const {
Config,
Command,
ProjectConfig,
DependencyConfig,
AndroidProjectConfig,
IOSProjectConfig
} = require("@react-native-community/cli-types");import {
Config,
Command,
CommandFunction,
AndroidProjectConfig,
IOSProjectConfig
} from "@react-native-community/cli-types";
// Define a command function
const myCommand: CommandFunction = async (argv, ctx, args) => {
console.log(`Running command in project: ${ctx.project.android?.appName}`);
};
// Define a command
const command: Command = {
name: "my-command",
description: "Example CLI command",
func: myCommand,
options: [
{
name: "--verbose",
description: "Enable verbose logging",
default: false
}
]
};
// Work with configuration
function processConfig(config: Config) {
console.log(`React Native path: ${config.reactNativePath}`);
console.log(`Project root: ${config.root}`);
if (config.project.android) {
console.log(`Android app: ${config.project.android.appName}`);
}
if (config.project.ios) {
console.log(`iOS project: ${config.project.ios.xcodeProject?.name}`);
}
}The type system is organized around several key areas:
Complete type definitions for CLI command development with support for standard commands, detached commands, and command options.
type CommandFunction<Args = Object> = (
argv: Array<string>,
ctx: Config,
args: Args
) => Promise<void> | void;
type Command<IsDetached extends boolean = false> = {
name: string;
description?: string;
detached?: IsDetached;
examples?: Array<{
desc: string;
cmd: string;
}>;
pkg?: {
name: string;
version: string;
};
func: IsDetached extends true
? DetachedCommandFunction<Object>
: CommandFunction<Object>;
options?: Array<CommandOption>;
};Core configuration types that define the structure of React Native CLI configurations, including project settings, dependency management, and platform configurations.
interface Config {
root: string;
reactNativePath: string;
reactNativeVersion: string;
project: ProjectConfig;
dependencies: {
[key: string]: DependencyConfig;
};
platforms: {
android: AndroidPlatformConfig;
ios: IOSPlatformConfig;
[name: string]: PlatformConfig<any, any, any, any>;
};
assets: string[];
commands: Command[];
healthChecks: [];
}
type ProjectConfig = {
android?: Exclude<ReturnType<AndroidPlatformConfig['projectConfig']>, void>;
ios?: Exclude<ReturnType<IOSPlatformConfig['projectConfig']>, void>;
[key: string]: any;
};Comprehensive Android platform configuration types covering project structure, dependency management, C++ modules, and build configuration.
interface AndroidProjectConfig {
sourceDir: string;
appName: string;
packageName: string;
applicationId: string;
mainActivity: string;
dependencyConfiguration?: string;
watchModeCommandParams?: string[];
assets: string[];
}
type AndroidDependencyConfig = {
sourceDir: string;
packageImportPath: string | null;
packageInstance: string | null;
dependencyConfiguration?: string;
buildTypes: string[];
libraryName?: string | null;
componentDescriptors?: string[] | null;
cmakeListsPath?: string | null;
cxxModuleCMakeListsModuleName?: string | null;
cxxModuleCMakeListsPath?: string | null;
cxxModuleHeaderName?: string | null;
isPureCxxDependency?: boolean;
};Complete iOS platform configuration types with CocoaPods integration, Xcode project handling, and script phase management.
interface IOSProjectConfig {
sourceDir: string;
xcodeProject: IOSProjectInfo | null;
watchModeCommandParams?: string[];
automaticPodsInstallation?: boolean;
assets: string[];
}
interface IOSDependencyConfig {
podspecPath: string;
version: string;
scriptPhases: Array<IOSScriptPhase>;
configurations: string[];
}
type IOSScriptPhase = ({script: string} | {path: string}) & {
name: string;
shell_path?: string;
input_files?: string[];
output_files?: string[];
input_file_lists?: string[];
output_file_lists?: string[];
show_env_vars_in_log?: boolean;
execution_position?: 'before_compile' | 'after_compile' | 'any';
dependency_file?: string;
always_out_of_date?: string;
};Type definitions for third-party modules used within the React Native CLI ecosystem, provided as module augmentation for enhanced TypeScript support.
// Available through module augmentation after installing this package
declare module 'node-stream-zip' {
interface StreamZipOptions {
file: string;
storeEntries?: boolean;
skipEntryNameValidation?: boolean;
chunkSize?: number;
}
class ZipEntry {
name: string;
isDirectory: boolean;
isFile: boolean;
comment: string;
size: number;
}
class StreamZip {
constructor(config: StreamZipOptions);
on(event: 'ready', handler: () => void): void;
entries(): ZipEntry[];
extract(entry: string | null, outPath: string, callback: (err?: any) => void): void;
close(callback?: (err?: any) => void): void;
}
}type Prompt = any;
type OptionValue = string | boolean | number;
type CommandOption<T = (ctx: Config) => OptionValue> = {
name: string;
description?: string;
parse?: (val: string) => any;
default?: OptionValue | T;
};
type DetachedCommandFunction<Args = Object> = (
argv: string[],
args: Args,
ctx: Config
) => Promise<void> | void;
type DetachedCommand = Command<true>;
interface PlatformConfig<
ProjectConfig,
ProjectParams,
DependencyConfig,
DependencyParams,
> {
npmPackageName?: string;
projectConfig: (
projectRoot: string,
projectParams: ProjectParams | void,
) => ProjectConfig | void;
dependencyConfig: (
dependency: string,
params: DependencyParams,
) => DependencyConfig | void;
}
interface DependencyConfig {
name: string;
root: string;
platforms: {
android?: AndroidDependencyConfig;
ios?: IOSDependencyConfig;
[key: string]: any;
};
}
type UserConfig = Omit<Config, 'root'> & {
reactNativePath: string | void;
project: {
android?: AndroidProjectParams;
ios?: IOSProjectParams;
[key: string]: any;
};
};
type UserDependencyConfig = {
dependency: Omit<DependencyConfig, 'name' | 'root'>;
commands: Command[];
platforms: Config['platforms'];
healthChecks: [];
};
type AndroidProjectParams = {
sourceDir?: string;
appName?: string;
manifestPath?: string;
packageName?: string;
dependencyConfiguration?: string;
watchModeCommandParams?: string[];
assets?: string[];
};
interface IOSProjectParams {
sourceDir?: string;
watchModeCommandParams?: string[];
automaticPodsInstallation?: boolean;
assets?: string[];
}
type IOSDependencyParams = Omit<
Partial<IOSDependencyConfig>,
'podspecPath' | 'version'
>;
type AndroidDependencyParams = {
sourceDir?: string;
manifestPath?: string;
packageName?: string;
dependencyConfiguration?: string;
packageImportPath?: string;
packageInstance?: string;
buildTypes?: string[];
libraryName?: string | null;
componentDescriptors?: string[] | null;
cmakeListsPath?: string | null;
cxxModuleCMakeListsModuleName?: string | null;
cxxModuleCMakeListsPath?: string | null;
cxxModuleHeaderName?: string | null;
};