CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-react-native-community--cli

Command line tools to interact with React Native projects

Pending
Overview
Eval results
Files

main-api.mddocs/

Main API Functions

Core programmatic interface for the React Native CLI providing functions for running the CLI, loading project configurations, and integrating with development tools.

Capabilities

CLI Execution

Primary entry point for running the React Native CLI programmatically with optional platform-specific behavior.

/**
 * Main entry point to run the CLI with optional platform name
 * @param platformName - Optional platform name for out-of-tree platforms (e.g., 'macos', 'windows')
 * @returns Promise that resolves when CLI execution completes
 * @throws CLIError when configuration loading fails or command execution encounters errors
 */
function run(platformName?: string): Promise<void>;

Usage Examples:

import { run } from "@react-native-community/cli";

// Run CLI with default behavior
await run();

// Run CLI with out-of-tree platform support
await run("macos");

Configuration Loading

Functions for loading React Native project configuration either synchronously or asynchronously.

/**
 * Synchronously loads React Native CLI configuration
 * @param options - Optional configuration loading options
 * @param options.projectRoot - Project root directory path (defaults to findProjectRoot())
 * @param options.selectedPlatform - Platform to load configuration for (e.g., 'ios', 'android')
 * @returns Config object with project settings, platforms, and commands
 * @throws Error if configuration cannot be loaded or project not found
 */
function loadConfig(options?: LoadConfigOptions): Config;

/**
 * Asynchronously loads React Native CLI configuration
 * @param options - Optional configuration loading options
 * @param options.projectRoot - Project root directory path (defaults to findProjectRoot())
 * @param options.selectedPlatform - Platform to load configuration for (e.g., 'ios', 'android')
 * @returns Promise resolving to Config object
 * @throws CLIError if configuration loading fails
 */
function loadConfigAsync(options?: LoadConfigOptions): Promise<Config>;

Usage Examples:

import { loadConfig, loadConfigAsync } from "@react-native-community/cli";

// Synchronous loading
try {
  const config = loadConfig();
  console.log("Project root:", config.root);
  console.log("React Native path:", config.reactNativePath);
} catch (error) {
  console.log("Not in a React Native project");
}

// Load with custom project root
const config = loadConfig({ projectRoot: "/path/to/project" });

// Asynchronous loading
const config = await loadConfigAsync();
console.log("Available platforms:", Object.keys(config.platforms));

// Platform-specific loading
const iosConfig = await loadConfigAsync({ selectedPlatform: "ios" });
console.log("iOS configuration:", iosConfig.platforms.ios);

Development Server Middleware

Creates middleware for Metro development server integration with WebSocket support for React Native development tools.

/**
 * Creates development server middleware for Metro bundler
 * @param options - Middleware configuration options
 * @param options.host - Server host (optional, defaults to localhost)
 * @param options.port - Server port number
 * @param options.watchFolders - Array of directories to watch for changes
 * @returns DevServerMiddleware object with endpoints and middleware
 */
function createDevServerMiddleware(options: MiddlewareOptions): DevServerMiddleware;

interface MiddlewareOptions {
  host?: string;
  port: number;
  watchFolders: ReadonlyArray<string>;
}

interface DevServerMiddleware {
  websocketEndpoints: {
    '/message': any;
    '/events': any;
  };
  messageSocketEndpoint: any;
  eventsSocketEndpoint: any;
  middleware: any;
}

Usage Examples:

import { createDevServerMiddleware } from "@react-native-community/cli";

// Create development server middleware
const middleware = createDevServerMiddleware({
  port: 8081,
  watchFolders: ["./src", "./node_modules"],
});

// Use with Express server
app.use(middleware.middleware);

Binary Path

Constant providing the path to the CLI binary entry point for programmatic access.

/**
 * Path to the CLI binary entry point
 * Resolved path to the bin.js file for programmatic execution
 */
const bin: string;

Usage Examples:

import { bin } from "@react-native-community/cli";
import { spawn } from "child_process";

// Execute CLI binary programmatically
const child = spawn("node", [bin, "info"], {
  stdio: "inherit"
});

Types

interface Config {
  root: string;
  reactNativePath: string;
  reactNativeVersion: string;
  project: ProjectConfig;
  dependencies: Record<string, DependencyConfig>;
  platforms: Record<string, PlatformConfig<any, any, any, any>>;
  assets: string[];
  commands: Command[];
  healthChecks: [];
}

interface LoadConfigOptions {
  projectRoot?: string;
  selectedPlatform?: string;
}

interface ProjectConfig {
  android?: AndroidProjectConfig;
  ios?: IOSProjectConfig;
  [key: string]: any;
}

interface MiddlewareOptions {
  host?: string;
  port: number;
  watchFolders: ReadonlyArray<string>;
}

interface DevServerMiddleware {
  websocketEndpoints: {
    '/message': WebSocketServer;
    '/events': WebSocketServer;
  };
  messageSocketEndpoint: MessageSocketEndpoint;
  eventsSocketEndpoint: EventsSocketEndpoint;
  middleware: ConnectMiddleware;
}

Install with Tessl CLI

npx tessl i tessl/npm-react-native-community--cli

docs

cli-commands.md

index.md

main-api.md

typescript-types.md

tile.json