CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-react-native--codegen

Code generation tools for parsing React Native component definitions and generating native platform code.

Pending
Overview
Eval results
Files

cli-tools.mddocs/

CLI Tools

Command-line utilities for parsing files, combining schemas, and generating code from the terminal.

Capabilities

Parser CLI

Parse Flow and TypeScript files and output their schemas to the console.

# Parse one or more files
node parser-cli.js file1.js file2.ts file3.tsx

# Using from node_modules
node node_modules/@react-native/codegen/lib/cli/parser/parser-cli.js MyComponent.js

Usage Example:

# Parse a Flow component file
node parser-cli.js ./src/MyButton.js

# Parse multiple TypeScript files
node parser-cli.js ./src/MyButton.tsx ./src/MyModal.tsx ./src/MyModule.ts

The parser CLI automatically detects file types based on extensions and outputs JSON schemas to stdout.

Schema Combination CLI

Combine multiple pre-generated schema files with platform filtering.

# Combine schemas with platform filtering
node combine-schemas-cli.js -p <platform> -o <output> -s @<schema-query-file>

# Parameters:
# -p, --platform: Target platform (ios or android) 
# -o, --output: Output JSON file path
# -s, --schema-query: File containing list of schema files (must start with @)

Usage Example:

# Create a query file listing schema files 
echo "schema1.json schema2.json schema3.json" > query.txt

# Combine for iOS platform
node combine-schemas-cli.js -p ios -o ios-combined.json -s @query.txt

# Combine for Android platform  
node combine-schemas-cli.js -p android -o android-combined.json -s @query.txt

The schema query file should contain space-separated paths to JSON schema files.

JavaScript-to-Schema CLI

Convert JavaScript/TypeScript source files directly to a combined schema.

# Convert JS/TS files to schema
node combine-js-to-schema-cli.js <outfile> <file1> [<file2> ...]

# Options:
# -p, --platform: Platform filter for filenames (ios/android)
# -e, --exclude: Regular expression to exclude files  
# -l, --libraryName: Library name for the generated schema

Usage Example:

# Basic conversion
node combine-js-to-schema-cli.js combined.json ./src/Component1.js ./src/Component2.tsx

# With platform filtering and library name
node combine-js-to-schema-cli.js schema.json ./src/*.js -p ios -l MyLibrary

# Exclude test files
node combine-js-to-schema-cli.js production.json ./src/**/*.js -e "test|spec" -l MyApp

Code Generation CLI

Generate all possible native code outputs from a schema file.

# Generate all code outputs
node generate-all.js <schemaPath> <libraryName> <outputDirectory> <packageName> <assumeNonnull>

# Parameters:
# schemaPath: Path to the JSON schema file
# libraryName: Name of the library being generated
# outputDirectory: Directory where generated files will be written  
# packageName: Package name for platform-specific code
# assumeNonnull: Whether to assume nonnull annotations (true/false)

Usage Example:

# Generate all outputs for a library
node generate-all.js ./schema.json MyLibrary ./generated com.example.mylibrary true

# The generated directory will contain:
# - iOS component files (Objective-C++/C++)
# - Android component files (Java/C++) 
# - TurboModule implementations
# - Test files
# - Component descriptors

This generates code using all available generators:

  • descriptors - Component descriptor files
  • events - Event emitter code
  • props - Props interface code
  • states - Component state code
  • tests - Test code generation
  • shadow-nodes - Shadow node implementations
  • modulesAndroid - Android TurboModule code
  • modulesCxx - C++ TurboModule code
  • modulesIOS - iOS TurboModule code

CLI Workflow Examples

Complete Development Workflow

# 1. Parse component files to understand their structure
node parser-cli.js src/MyComponent.js src/MyModule.ts

# 2. Combine source files into a schema
node combine-js-to-schema-cli.js app-schema.json src/**/*.{js,ts,tsx} -l MyApp

# 3. Generate platform-specific code
node generate-all.js app-schema.json MyApp ./ios/Generated com.example.myapp false

Platform-Specific Build Pipeline

# Create iOS-specific schema
node combine-js-to-schema-cli.js ios-schema.json src/**/*.{js,ts,tsx} -p ios -l MyApp

# Create Android-specific schema  
node combine-js-to-schema-cli.js android-schema.json src/**/*.{js,ts,tsx} -p android -l MyApp

# Generate platform-specific code
node generate-all.js ios-schema.json MyApp ./ios/Generated com.example.myapp true
node generate-all.js android-schema.json MyApp ./android/generated com.example.myapp true

Integration with Build Systems

The CLI tools can be integrated into npm scripts or build systems:

{
  "scripts": {
    "codegen": "node node_modules/@react-native/codegen/lib/cli/combine/combine-js-to-schema-cli.js schema.json src/**/*.{js,ts,tsx} -l MyApp",
    "codegen:ios": "node node_modules/@react-native/codegen/lib/cli/generators/generate-all.js schema.json MyApp ./ios/Generated com.example.myapp true",
    "codegen:android": "node node_modules/@react-native/codegen/lib/cli/generators/generate-all.js schema.json MyApp ./android/Generated com.example.myapp true"
  }
}

CLI Error Handling

All CLI tools provide detailed error messages for common issues:

  • File not found: Clear indication of missing files with full paths
  • Parse errors: Specific line and column information for syntax errors
  • Schema validation: Detailed validation error messages with suggestions
  • Platform conflicts: Clear explanation of platform exclusion conflicts
  • Generation failures: Specific generator error messages with context

Exit codes:

  • 0: Success
  • 1: General error (file not found, invalid arguments)
  • 2: Parse error (invalid JavaScript/TypeScript syntax)
  • 3: Schema validation error
  • 4: Code generation error

Install with Tessl CLI

npx tessl i tessl/npm-react-native--codegen

docs

cli-tools.md

code-generation.md

file-parsing.md

index.md

schema-management.md

tile.json