1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
//! # Tauri TypeGen
//!
//! Automatically generate TypeScript bindings from Tauri commands.
//!
//! This library scans Rust source code for `#[tauri::command]` functions and generates
//! strongly-typed TypeScript interfaces, command functions, and optional Zod schemas
//! with runtime validation.
//!
//! ## Features
//!
//! - 🔍 **Automatic Discovery**: Scans Rust source for `#[tauri::command]` functions
//! - 📝 **TypeScript Generation**: Creates TypeScript interfaces for command parameters and return types
//! - ✅ **Validation Support**: Optional Zod schema generation with runtime validation
//! - 🚀 **Command Bindings**: Strongly-typed frontend functions
//! - 📡 **Event Support**: Discovers and types `app.emit()` events
//! - 📞 **Channel Support**: Types for streaming `Channel<T>` parameters
//! - 🏷️ **Serde Support**: Respects `#[serde(rename)]` and `#[serde(rename_all)]` attributes
//!
//! ## Quick Start
//!
//! ### As a CLI Tool
//!
//! ```bash
//! # Install globally
//! cargo install tauri-typegen
//!
//! # Generate TypeScript bindings
//! cargo tauri-typegen generate
//! ```
//!
//! ### As a Build Dependency
//!
//! Add to your `src-tauri/build.rs`:
//!
//! ```rust,ignore
//! fn main() {
//! // Generate TypeScript bindings before build
//! tauri_typegen::BuildSystem::generate_at_build_time()
//! .expect("Failed to generate TypeScript bindings");
//!
//! tauri_build::build()
//! }
//! ```
//!
//! ### Programmatic Usage
//!
//! ```rust,no_run
//! use tauri_typegen::{GenerateConfig, generate_from_config};
//!
//! let config = GenerateConfig {
//! project_path: "./src-tauri".to_string(),
//! output_path: "./src/generated".to_string(),
//! validation_library: "zod".to_string(),
//! verbose: Some(true),
//! ..Default::default()
//! };
//!
//! let files = generate_from_config(&config)?;
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
//!
//! ## Example
//!
//! Given this Rust code:
//!
//! ```rust,ignore
//! use serde::{Deserialize, Serialize};
//!
//! #[derive(Serialize, Deserialize)]
//! pub struct User {
//! pub id: i32,
//! pub name: String,
//! }
//!
//! #[tauri::command]
//! pub async fn get_user(id: i32) -> Result<User, String> {
//! // Implementation
//! }
//! ```
//!
//! Generates this TypeScript:
//!
//! ```typescript
//! export interface User {
//! id: number;
//! name: string;
//! }
//!
//! export async function getUser(params: { id: number }): Promise<User> {
//! return invoke('get_user', params);
//! }
//! ```
//!
//! ## Configuration
//!
//! Configure via `tauri.conf.json`:
//!
//! ```json
//! {
//! "plugins": {
//! "tauri-typegen": {
//! "project_path": ".",
//! "output_path": "../src/generated",
//! "validation_library": "zod",
//! "type_mappings": {
//! "DateTime<Utc>": "string",
//! "PathBuf": "string"
//! }
//! }
//! }
//! }
//! ```
// Core library modules for the CLI tool
// pub mod commands; // Removed: plugin commands are not used
pub use ;
pub use *;
// Convenience re-exports for common use cases
pub use GenerateConfig;
pub use generate_from_config;
pub use ;
// Build system integration
pub use BuildSystem;