Code generation tools for parsing React Native component definitions and generating native platform code.
—
Command-line utilities for parsing files, combining schemas, and generating code from the terminal.
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.jsUsage 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.tsThe parser CLI automatically detects file types based on extensions and outputs JSON schemas to stdout.
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.txtThe schema query file should contain space-separated paths to JSON schema files.
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 schemaUsage 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 MyAppGenerate 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 descriptorsThis generates code using all available generators:
descriptors - Component descriptor filesevents - Event emitter codeprops - Props interface codestates - Component state codetests - Test code generationshadow-nodes - Shadow node implementationsmodulesAndroid - Android TurboModule codemodulesCxx - C++ TurboModule codemodulesIOS - iOS TurboModule code# 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# 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 trueThe 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"
}
}All CLI tools provide detailed error messages for common issues:
Exit codes:
0: Success1: General error (file not found, invalid arguments)2: Parse error (invalid JavaScript/TypeScript syntax)3: Schema validation error4: Code generation errorInstall with Tessl CLI
npx tessl i tessl/npm-react-native--codegen