0
# @tauri-apps/cli
1
2
@tauri-apps/cli is the command line interface for building cross-platform desktop applications with the Tauri framework. It provides a Node.js wrapper around a native Rust binary, enabling developers to scaffold, develop, build, and bundle Tauri applications through commands like `tauri dev`, `tauri build`, and `tauri init`.
3
4
## Package Information
5
6
- **Package Name**: @tauri-apps/cli
7
- **Package Type**: npm
8
- **Language**: TypeScript/JavaScript with native Rust binary
9
- **Installation**: `npm install -D @tauri-apps/cli`
10
11
## Core Imports
12
13
```javascript
14
const { run, logError } = require("@tauri-apps/cli");
15
```
16
17
For ES modules:
18
19
```javascript
20
import { run, logError } from "@tauri-apps/cli";
21
```
22
23
## Basic Usage
24
25
### Programmatic Usage
26
27
```javascript
28
const cli = require("@tauri-apps/cli");
29
30
// Run a Tauri CLI command programmatically
31
try {
32
await cli.run(['dev'], 'npm run tauri');
33
console.log('Command completed successfully');
34
} catch (error) {
35
cli.logError(error.message);
36
process.exit(1);
37
}
38
```
39
40
### CLI Binary Usage
41
42
The package provides a `tauri` binary that can be used directly:
43
44
```bash
45
# Initialize a new Tauri project
46
npx @tauri-apps/cli init
47
48
# Start development server
49
npx @tauri-apps/cli dev
50
51
# Build for production
52
npx @tauri-apps/cli build
53
54
# Or via package manager scripts
55
npm run tauri dev
56
yarn tauri build
57
pnpm tauri init
58
```
59
60
## Architecture
61
62
The @tauri-apps/cli package consists of several key components:
63
64
- **Node.js Wrapper**: High-level JavaScript API (`main.js`) providing Promise-based interface
65
- **NAPI Native Bindings**: Low-level interface (`index.js`) connecting to native Rust binary
66
- **CLI Executable**: Shell script (`tauri.js`) handling command-line invocation and argument processing
67
- **Native Rust Binary**: Core CLI implementation providing all Tauri development commands
68
- **Platform Detection**: Automatic detection and loading of platform-specific native binaries
69
70
## Capabilities
71
72
### CLI Execution
73
74
Execute Tauri CLI commands programmatically with full error handling and progress feedback.
75
76
```javascript { .api }
77
/**
78
* Execute Tauri CLI commands programmatically
79
* @param args - Array of command line arguments to pass to the CLI
80
* @param binName - Optional binary name for help display (defaults to detected context)
81
* @returns Promise that resolves with boolean result when command completes or rejects on error
82
*/
83
function run(args: Array<string>, binName?: string | undefined | null): Promise<boolean>;
84
```
85
86
**Usage Examples:**
87
88
```javascript
89
// Initialize a new Tauri project
90
await run(['init', '--name', 'my-app', '--template', 'vanilla']);
91
92
// Start development server with specific configuration
93
await run(['dev', '--config', 'tauri.dev.conf.json']);
94
95
// Build for production with debug symbols
96
await run(['build', '--debug']);
97
98
// Generate app icons from source image
99
await run(['icon', 'path/to/icon.png']);
100
101
// Show project and system information
102
await run(['info']);
103
```
104
105
### Error Logging
106
107
Log error messages to stderr with proper formatting for CLI output.
108
109
```javascript { .api }
110
/**
111
* Log error messages to stderr
112
* @param error - Error message string to log
113
*/
114
function logError(error: string): void;
115
```
116
117
**Usage Examples:**
118
119
```javascript
120
try {
121
await run(['build', '--invalid-flag']);
122
} catch (error) {
123
logError(`Build failed: ${error.message}`);
124
process.exit(1);
125
}
126
127
// Log validation errors
128
logError('Configuration file not found: tauri.conf.json');
129
```
130
131
## CLI Commands
132
133
The following commands are available through the `run()` function or CLI binary:
134
135
### Project Management Commands
136
137
```bash
138
# Initialize a new Tauri project
139
tauri init [options]
140
141
# Display project and system information
142
tauri info
143
144
# Migrate from Tauri v1 to v2
145
tauri migrate
146
```
147
148
### Development Commands
149
150
```bash
151
# Start development server with hot reload
152
tauri dev [options]
153
154
# Build application for production
155
tauri build [options]
156
157
# Bundle application for distribution
158
tauri bundle [options]
159
```
160
161
### Mobile Development Commands
162
163
```bash
164
# Android development and build commands
165
tauri android [subcommand]
166
167
# iOS development and build commands (macOS only)
168
tauri ios [subcommand]
169
```
170
171
### Asset and Resource Commands
172
173
```bash
174
# Generate application icons from source image
175
tauri icon [path-to-icon]
176
177
# Code signing utilities
178
tauri signer [subcommand]
179
```
180
181
### Plugin and Dependency Commands
182
183
```bash
184
# Add dependencies or features to project
185
tauri add [dependency]
186
187
# Remove dependencies or features from project
188
tauri remove [dependency]
189
190
# Plugin management commands
191
tauri plugin [subcommand]
192
```
193
194
### Permission and Security Commands
195
196
```bash
197
# Permission management
198
tauri permission [subcommand]
199
200
# Capability management
201
tauri capability [subcommand]
202
```
203
204
### Utility Commands
205
206
```bash
207
# Shell completion generation
208
tauri completions [shell]
209
210
# Project inspection utilities
211
tauri inspect [subcommand]
212
```
213
214
## Platform Support
215
216
### Supported Architectures
217
218
The package automatically detects and loads the appropriate native binary for:
219
220
- **Linux**: x86_64-gnu, x86_64-musl, aarch64-gnu, aarch64-musl, arm-gnueabihf, arm-musleabihf, riscv64-gnu, riscv64-musl, ppc64-gnu, s390x-gnu
221
- **Windows**: x86_64-msvc, i686-msvc, aarch64-msvc
222
- **macOS**: x86_64, aarch64 (Apple Silicon), universal binaries
223
- **FreeBSD**: x86_64, aarch64
224
- **OpenHarmony**: x86_64, aarch64, arm
225
- **Android**: arm64, arm-eabi
226
- **WebAssembly**: WASI support for cross-platform compatibility
227
228
### Runtime Requirements
229
230
- **Node.js**: >= 10
231
- **Platform**: Windows, macOS, Linux, FreeBSD, OpenHarmony, Android
232
- **Architecture**: x64, ARM64, ARM, RISC-V, PowerPC64, s390x (platform dependent)
233
- **Fallback**: WebAssembly (WASI) support when native binaries unavailable
234
235
## Error Handling
236
237
The CLI provides structured error handling with detailed error messages:
238
239
```javascript
240
try {
241
await run(['build', '--config', 'missing-file.json']);
242
} catch (error) {
243
// Error object contains detailed information
244
console.error('Command failed:', error.message);
245
246
// Log the error using the built-in logger
247
logError(error.message);
248
249
// Exit with error code
250
process.exit(1);
251
}
252
```
253
254
## Configuration Integration
255
256
The CLI integrates with Tauri's configuration system:
257
258
```javascript
259
// Use custom configuration file
260
await run(['dev', '--config', 'tauri.dev.conf.json']);
261
262
// Pass configuration inline as JSON
263
await run(['build', '--config', '{"bundle":{"active":true}}']);
264
265
// Use TOML configuration
266
await run(['build', '--config', 'tauri.prod.conf.toml']);
267
```
268
269
## Package Manager Integration
270
271
The CLI automatically detects the package manager context and adjusts help messages accordingly:
272
273
```javascript
274
// When run via npm scripts, shows: npm run tauri
275
// When run via yarn, shows: yarn tauri
276
// When run via pnpm, shows: pnpm tauri
277
// When run via bun, shows: bun tauri
278
// When run directly, shows: node tauri.js
279
```
280
281
## Types
282
283
```typescript { .api }
284
// Main API - Promise-based interface (main.js exports)
285
declare function run(
286
args: Array<string>,
287
binName?: string | undefined | null
288
): Promise<boolean>;
289
290
declare function logError(error: string): void;
291
292
// Native bindings - Callback-based interface (index.js exports)
293
declare function run(
294
args: Array<string>,
295
binName: string | undefined | null,
296
callback: ((err: Error | null, arg: boolean) => any)
297
): void;
298
299
declare function logError(error: string): void;
300
```