| Crates.io | kotoba2tsx |
| lib.rs | kotoba2tsx |
| version | 0.1.16 |
| created_at | 2025-09-17 15:48:43.971647+00 |
| updated_at | 2025-09-17 15:48:43.971647+00 |
| description | Complete toolchain for converting Kotoba configuration files to React TypeScript components |
| homepage | https://github.com/com-junkawasaki/kotoba |
| repository | https://github.com/com-junkawasaki/kotoba |
| max_upload_size | |
| id | 1843512 |
| size | 312,493 |
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.
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.
Kotoba File (.kotoba) โ Parser โ AST โ Generator โ TSX Component (.tsx)
โ โ โ โ
Jsonnet/JSON Validation TypeScript React + Hooks
Evaluation & Transform Generation Component Code
parser.rs)// Jsonnet-enhanced JSON parsing with validation
pub struct KotobaParser;
impl KotobaParser {
pub fn parse_file(&self, path: &str) -> Result<KotobaConfig>;
pub fn parse_content(&self, content: &str) -> Result<KotobaConfig>;
}
generator.rs)// TypeScript + React code generation
pub struct TsxGenerator;
impl TsxGenerator {
pub fn generate_tsx(&self, config: &KotobaConfig) -> Result<String>;
pub fn generate_file(&self, config: &KotobaConfig, path: &str) -> Result<()>;
}
swc_integration.rs)// Advanced code formatting and optimization
pub struct SwcCodeGenerator;
impl SwcCodeGenerator {
pub fn format_code(&self, code: &str) -> Result<String>;
pub fn create_react_import(&self) -> String;
}
| 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 |
use kotoba2tsx::prelude::*;
// 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 = kotoba2tsx::convert_content(kotoba_content)?;
println!("{}", tsx_code);
use kotoba2tsx::convert_file;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Convert .kotoba file to .tsx file
convert_file("app.kotoba", "App.tsx").await?;
Ok(())
}
use kotoba2tsx::{KotobaParser, TsxGenerator};
// Custom configuration
let parser = KotobaParser::new();
let config = parser.parse_file("complex_app.kotoba").await?;
let generator = TsxGenerator::new();
let tsx_code = generator.generate_tsx(&config)?;
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 |
cargo test -p kotoba2tsx
Test Coverage:
KotobaConfig] - Main configuration structureKotobaComponent] - Individual component definitionComponentType] - Component classification enumTsxGenerator] - Main code generation engineKotobaParser] - Configuration parsing engineTsxGenerationOptions] - Code generation configurationCssInJsLibrary] - CSS-in-JS framework selectionComponentStyle] - Styling configurationconvert_content()] - Convert string content to TSXconvert_file()] - Convert file to file (async)SwcCodeGenerator] - Advanced code formattingSee the main Kotoba repository for contribution guidelines.
Licensed under MIT OR Apache-2.0. See LICENSE for details.