docs.rs failed to build kotoba2tsx-0.1.16
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Kotoba2TSX
Complete toolchain for converting Kotoba configuration files to React TypeScript components. Transforms Jsonnet-based UI declarations into production-ready TSX code with full type safety and modern React patterns.
๐ฏ Overview
Kotoba2TSX bridges the gap between declarative UI configuration and React development. It parses Kotoba files (Jsonnet format) and generates TypeScript React components with proper typing, state management, and event handling.
๐๏ธ Architecture
Core Pipeline
Kotoba File (.kotoba) โ Parser โ AST โ Generator โ TSX Component (.tsx)
โ โ โ โ
Jsonnet/JSON Validation TypeScript React + Hooks
Evaluation & Transform Generation Component Code
Key Components
Parser (parser.rs)
// Jsonnet-enhanced JSON parsing with validation
;
Generator (generator.rs)
// TypeScript + React code generation
;
SWC Integration (swc_integration.rs)
// Advanced code formatting and optimization
;
๐ Quality Metrics
| Metric | Status |
|---|---|
| Compilation | โ Clean (with warnings to fix) |
| Tests | โ Comprehensive test suite (61 tests) |
| Documentation | โ Complete API docs |
| Performance | โ Efficient parsing and generation |
| TSX Output | โ Production-ready React code |
| Type Safety | โ Full TypeScript integration |
๐ง Usage
Basic Conversion
use *;
// Convert content string to TSX
let kotoba_content = r#"{
"name": "MyApp",
"version": "1.0.0",
"theme": "light",
"components": {
"Button": {
"type": "component",
"name": "Button",
"component_type": "button",
"props": {"children": "Click me"}
}
},
"handlers": {},
"states": {},
"config": {}
}"#;
let tsx_code = convert_content?;
println!;
File-based Conversion
use convert_file;
async
Advanced Generation
use ;
// Custom configuration
let parser = new;
let config = parser.parse_file.await?;
let generator = new;
let tsx_code = generator.generate_tsx?;
๐ Ecosystem Integration
Kotoba2TSX is part of the complete Kotoba toolchain:
| Crate | Purpose | Integration |
|---|---|---|
kotoba-jsonnet |
Required | Jsonnet evaluation for configuration files |
kotoba-core |
Required | Base types and IR definitions |
kotoba-server |
Optional | REST API for configuration serving |
swc |
Required | TypeScript/JavaScript processing |
๐งช Testing
Test Coverage:
- โ JSON/Jsonnet parsing and validation
- โ TSX code generation for all component types
- โ TypeScript interface generation
- โ React hooks and state management
- โ Event handler integration
- โ CSS-in-JS styled components
- โ SWC code formatting
- โ File I/O operations
- โ Error handling and edge cases
๐ Performance
- Fast Parsing: Efficient Jsonnet evaluation and AST construction
- Optimized Generation: Template-based TSX code generation
- SWC Integration: Lightning-fast code formatting and optimization
- Streaming Output: Memory-efficient large file processing
- Parallel Processing: Concurrent file conversion support
๐ Security
- Input Validation: Comprehensive Jsonnet/JSON syntax validation
- Code Injection Prevention: Safe code generation without eval()
- Type Safety: Full TypeScript type checking
- Sanitized Output: XSS-safe React component generation
๐ API Reference
Core Types
- [
KotobaConfig] - Main configuration structure - [
KotobaComponent] - Individual component definition - [
ComponentType] - Component classification enum - [
TsxGenerator] - Main code generation engine - [
KotobaParser] - Configuration parsing engine
Generation Options
- [
TsxGenerationOptions] - Code generation configuration - [
CssInJsLibrary] - CSS-in-JS framework selection - [
ComponentStyle] - Styling configuration
Utilities
- [
convert_content()] - Convert string content to TSX - [
convert_file()] - Convert file to file (async) - [
SwcCodeGenerator] - Advanced code formatting
๐ค Contributing
See the main Kotoba repository for contribution guidelines.
๐ License
Licensed under MIT OR Apache-2.0. See LICENSE for details.