CtrlK
BlogDocsLog inGet started
Tessl Logo

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

TypeScript type definitions for React Native Community CLI configuration and command structures

Pending
Overview
Eval results
Files

configuration-types.mddocs/

Configuration Types

Core configuration types that define the structure of React Native CLI configurations, including project settings, dependency management, and platform configurations with extensible platform support.

Capabilities

Main Configuration

The central configuration interface that contains all React Native CLI settings and project metadata.

/**
 * Complete CLI configuration object containing all project and platform settings
 */
interface Config {
  /** Root directory of the React Native project */
  root: string;
  /** Path to React Native installation */
  reactNativePath: string;
  /** Version of React Native being used */
  reactNativeVersion: string;
  /** Multi-platform project configuration */
  project: ProjectConfig;
  /** Dictionary of dependency configurations keyed by dependency name */
  dependencies: {
    [key: string]: DependencyConfig;
  };
  /** Platform-specific configurations with extensible platform support */
  platforms: {
    android: AndroidPlatformConfig;
    ios: IOSPlatformConfig;
    [name: string]: PlatformConfig<any, any, any, any>;
  };
  /** Array of asset directories to be processed */
  assets: string[];
  /** Available CLI commands */
  commands: Command[];
  /** Health check configurations (deprecated, will be removed) */
  healthChecks: [];
}

Usage Examples:

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

// Working with configuration
function analyzeProject(config: Config) {
  console.log(`Project root: ${config.root}`);
  console.log(`React Native: ${config.reactNativeVersion} at ${config.reactNativePath}`);
  
  // Check available platforms
  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 || 'None'}`);
  }
  
  // List dependencies
  Object.keys(config.dependencies).forEach(dep => {
    console.log(`Dependency: ${dep} at ${config.dependencies[dep].root}`);
  });
  
  // Count assets
  console.log(`Asset directories: ${config.assets.length}`);
  
  // Available commands
  console.log(`Available commands: ${config.commands.map(cmd => cmd.name).join(', ')}`);
}

Project Configuration

Multi-platform project configuration supporting Android, iOS, and custom platforms.

/**
 * Multi-platform project configuration
 */
type ProjectConfig = {
  /** Android project configuration (optional) */
  android?: Exclude<ReturnType<AndroidPlatformConfig['projectConfig']>, void>;
  /** iOS project configuration (optional) */
  ios?: Exclude<ReturnType<IOSPlatformConfig['projectConfig']>, void>;
  /** Custom platform configurations */
  [key: string]: any;
};

Usage Examples:

import { ProjectConfig, AndroidProjectConfig, IOSProjectConfig } from "@react-native-community/cli-types";

// Check what platforms are configured
function getPlatforms(project: ProjectConfig): string[] {
  const platforms: string[] = [];
  
  if (project.android) platforms.push('android');
  if (project.ios) platforms.push('ios');
  
  // Check for custom platforms
  Object.keys(project).forEach(key => {
    if (key !== 'android' && key !== 'ios' && project[key]) {
      platforms.push(key);
    }
  });
  
  return platforms;
}

// Validate project has required platforms
function validateProject(project: ProjectConfig, requiredPlatforms: string[]): boolean {
  return requiredPlatforms.every(platform => {
    if (platform === 'android') return !!project.android;
    if (platform === 'ios') return !!project.ios;
    return !!project[platform];
  });
}

Dependency Configuration

Configuration for individual dependencies with multi-platform support.

/**
 * Multi-platform dependency configuration
 */
interface DependencyConfig {
  /** Dependency name */
  name: string;
  /** Root directory of the dependency */
  root: string;
  /** Platform-specific dependency configurations */
  platforms: {
    /** Android dependency configuration (optional) */
    android?: Exclude<
      ReturnType<AndroidPlatformConfig['dependencyConfig']>,
      void
    >;
    /** iOS dependency configuration (optional) */
    ios?: Exclude<ReturnType<IOSPlatformConfig['dependencyConfig']>, void>;
    /** Custom platform dependency configurations */
    [key: string]: any;
  };
}

Usage Examples:

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

// Analyze dependency platform support
function analyzeDependency(dep: DependencyConfig) {
  console.log(`Dependency: ${dep.name}`);
  console.log(`Location: ${dep.root}`);
  
  const supportedPlatforms: string[] = [];
  
  if (dep.platforms.android) {
    supportedPlatforms.push('android');
    console.log(`Android library: ${dep.platforms.android.libraryName || 'default'}`);
  }
  
  if (dep.platforms.ios) {
    supportedPlatforms.push('ios');
    console.log(`iOS podspec: ${dep.platforms.ios.podspecPath}`);
  }
  
  // Check custom platforms
  Object.keys(dep.platforms).forEach(platform => {
    if (platform !== 'android' && platform !== 'ios' && dep.platforms[platform]) {
      supportedPlatforms.push(platform);
    }
  });
  
  console.log(`Supported platforms: ${supportedPlatforms.join(', ')}`);
}

// Filter dependencies by platform
function getDependenciesForPlatform(
  dependencies: {[key: string]: DependencyConfig}, 
  platform: string
): DependencyConfig[] {
  return Object.values(dependencies).filter(dep => 
    dep.platforms[platform] !== undefined
  );
}

User Configuration Types

Configuration types for user-provided settings with optional values and parameter objects.

/**
 * User-provided configuration with optional root and parameter-based project settings
 */
type UserConfig = Omit<Config, 'root'> & {
  /** React Native path (optional for user config) */
  reactNativePath: string | void;
  /** Project configuration using parameter objects */
  project: {
    android?: AndroidProjectParams;
    ios?: IOSProjectParams;
    [key: string]: any;
  };
};

/**
 * User-provided dependency configuration for packages that extend CLI functionality
 */
type UserDependencyConfig = {
  /** Dependency configuration without name and root (provided by package context) */
  dependency: Omit<DependencyConfig, 'name' | 'root'>;
  /** Commands provided by this dependency */
  commands: Command[];
  /** Platform configurations provided by this dependency */
  platforms: Config['platforms'];
  /** Health checks provided by this dependency (deprecated) */
  healthChecks: [];
};

Usage Examples:

import { UserConfig, UserDependencyConfig, AndroidProjectParams, IOSProjectParams } from "@react-native-community/cli-types";

// Create user configuration
const userConfig: UserConfig = {
  reactNativePath: './node_modules/react-native',
  reactNativeVersion: '0.72.0',
  project: {
    android: {
      sourceDir: 'android/app/src/main/java',
      appName: 'MyApp',
      packageName: 'com.mycompany.myapp'
    } as AndroidProjectParams,
    ios: {
      sourceDir: 'ios',
      automaticPodsInstallation: true
    } as IOSProjectParams
  },
  dependencies: {},
  platforms: {} as any,
  assets: ['./assets'],
  commands: [],
  healthChecks: []
};

// Create dependency configuration for a plugin
const pluginConfig: UserDependencyConfig = {
  dependency: {
    platforms: {
      android: {
        sourceDir: 'android',
        packageImportPath: 'com.myplugin.MyPlugin',
        packageInstance: 'new MyPlugin()',
        buildTypes: ['debug', 'release'],
        dependencyConfiguration: 'implementation'
      },
      ios: {
        podspecPath: './ios/MyPlugin.podspec',
        version: '1.0.0',
        scriptPhases: [],
        configurations: ['Debug', 'Release']
      }
    }
  },
  commands: [
    {
      name: 'my-plugin-command',
      description: 'Run my plugin command',
      func: async (argv, ctx, args) => {
        console.log('Running plugin command');
      }
    }
  ],
  platforms: {} as any,
  healthChecks: []
};

Platform Configuration Interface

Generic platform configuration interface that enables extensible platform support.

/**
 * Generic platform configuration interface enabling extensible platform support
 * @template ProjectConfig - Platform-specific project configuration type
 * @template ProjectParams - Platform-specific project parameters type
 * @template DependencyConfig - Platform-specific dependency configuration type
 * @template DependencyParams - Platform-specific dependency parameters type
 */
interface PlatformConfig<
  ProjectConfig,
  ProjectParams,
  DependencyConfig,
  DependencyParams,
> {
  /** NPM package name that provides this platform support (optional) */
  npmPackageName?: string;
  /** Function to generate project configuration from parameters */
  projectConfig: (
    projectRoot: string,
    projectParams: ProjectParams | void,
  ) => ProjectConfig | void;
  /** Function to generate dependency configuration from parameters */
  dependencyConfig: (
    dependency: string,
    params: DependencyParams,
  ) => DependencyConfig | void;
}

Usage Examples:

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

// Custom platform configuration
interface CustomProjectConfig {
  buildDir: string;
  mainFile: string;
}

interface CustomProjectParams {
  buildDir?: string;
  mainFile?: string;
}

interface CustomDependencyConfig {
  libPath: string;
  version: string;
}

interface CustomDependencyParams {
  libPath?: string;
}

const customPlatform: PlatformConfig<
  CustomProjectConfig,
  CustomProjectParams,
  CustomDependencyConfig,
  CustomDependencyParams
> = {
  npmPackageName: '@mycompany/react-native-custom-platform',
  
  projectConfig: (projectRoot: string, params: CustomProjectParams | void) => {
    return {
      buildDir: params?.buildDir || `${projectRoot}/build`,
      mainFile: params?.mainFile || `${projectRoot}/src/main.custom`
    };
  },
  
  dependencyConfig: (dependency: string, params: CustomDependencyParams) => {
    return {
      libPath: params.libPath || `./libs/${dependency}`,
      version: '1.0.0'
    };
  }
};

// Register custom platform
function addCustomPlatform(config: Config): Config {
  return {
    ...config,
    platforms: {
      ...config.platforms,
      custom: customPlatform as any
    }
  };
}

Platform-Specific Configuration Types

Type aliases for the built-in Android and iOS platform configurations.

/**
 * Android platform configuration type
 */
type AndroidPlatformConfig = PlatformConfig<
  AndroidProjectConfig,
  AndroidProjectParams,
  AndroidDependencyConfig,
  AndroidDependencyParams
>;

/**
 * iOS platform configuration type
 */
type IOSPlatformConfig = PlatformConfig<
  IOSProjectConfig,
  IOSProjectParams,
  IOSDependencyConfig,
  IOSDependencyParams
>;

Usage Examples:

import { AndroidPlatformConfig, IOSPlatformConfig, Config } from "@react-native-community/cli-types";

// Access platform configurations from main config
function getPlatformConfigs(config: Config) {
  const androidPlatform: AndroidPlatformConfig = config.platforms.android;
  const iosPlatform: IOSPlatformConfig = config.platforms.ios;
  
  // Use platform configurations to generate project configs
  const androidProject = androidPlatform.projectConfig('/path/to/project', {
    sourceDir: 'android/app/src/main/java',
    appName: 'MyApp'
  });
  
  const iosProject = iosPlatform.projectConfig('/path/to/project', {
    sourceDir: 'ios',
    automaticPodsInstallation: true
  });
  
  console.log('Android project:', androidProject);
  console.log('iOS project:', iosProject);
}

Install with Tessl CLI

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

docs

android-platform.md

command-system.md

configuration-types.md

index.md

ios-platform.md

third-party-types.md

tile.json