Command line interface for building Tauri apps with Node.js wrapper around native Rust binary
npx @tessl/cli install tessl/npm-tauri-apps--cli@2.8.0@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.
npm install -D @tauri-apps/cliconst { run, logError } = require("@tauri-apps/cli");For ES modules:
import { run, logError } from "@tauri-apps/cli";const cli = require("@tauri-apps/cli");
// Run a Tauri CLI command programmatically
try {
await cli.run(['dev'], 'npm run tauri');
console.log('Command completed successfully');
} catch (error) {
cli.logError(error.message);
process.exit(1);
}The package provides a tauri binary that can be used directly:
# Initialize a new Tauri project
npx @tauri-apps/cli init
# Start development server
npx @tauri-apps/cli dev
# Build for production
npx @tauri-apps/cli build
# Or via package manager scripts
npm run tauri dev
yarn tauri build
pnpm tauri initThe @tauri-apps/cli package consists of several key components:
main.js) providing Promise-based interfaceindex.js) connecting to native Rust binarytauri.js) handling command-line invocation and argument processingExecute Tauri CLI commands programmatically with full error handling and progress feedback.
/**
* Execute Tauri CLI commands programmatically
* @param args - Array of command line arguments to pass to the CLI
* @param binName - Optional binary name for help display (defaults to detected context)
* @returns Promise that resolves with boolean result when command completes or rejects on error
*/
function run(args: Array<string>, binName?: string | undefined | null): Promise<boolean>;Usage Examples:
// Initialize a new Tauri project
await run(['init', '--name', 'my-app', '--template', 'vanilla']);
// Start development server with specific configuration
await run(['dev', '--config', 'tauri.dev.conf.json']);
// Build for production with debug symbols
await run(['build', '--debug']);
// Generate app icons from source image
await run(['icon', 'path/to/icon.png']);
// Show project and system information
await run(['info']);Log error messages to stderr with proper formatting for CLI output.
/**
* Log error messages to stderr
* @param error - Error message string to log
*/
function logError(error: string): void;Usage Examples:
try {
await run(['build', '--invalid-flag']);
} catch (error) {
logError(`Build failed: ${error.message}`);
process.exit(1);
}
// Log validation errors
logError('Configuration file not found: tauri.conf.json');The following commands are available through the run() function or CLI binary:
# Initialize a new Tauri project
tauri init [options]
# Display project and system information
tauri info
# Migrate from Tauri v1 to v2
tauri migrate# Start development server with hot reload
tauri dev [options]
# Build application for production
tauri build [options]
# Bundle application for distribution
tauri bundle [options]# Android development and build commands
tauri android [subcommand]
# iOS development and build commands (macOS only)
tauri ios [subcommand]# Generate application icons from source image
tauri icon [path-to-icon]
# Code signing utilities
tauri signer [subcommand]# Add dependencies or features to project
tauri add [dependency]
# Remove dependencies or features from project
tauri remove [dependency]
# Plugin management commands
tauri plugin [subcommand]# Permission management
tauri permission [subcommand]
# Capability management
tauri capability [subcommand]# Shell completion generation
tauri completions [shell]
# Project inspection utilities
tauri inspect [subcommand]The package automatically detects and loads the appropriate native binary for:
The CLI provides structured error handling with detailed error messages:
try {
await run(['build', '--config', 'missing-file.json']);
} catch (error) {
// Error object contains detailed information
console.error('Command failed:', error.message);
// Log the error using the built-in logger
logError(error.message);
// Exit with error code
process.exit(1);
}The CLI integrates with Tauri's configuration system:
// Use custom configuration file
await run(['dev', '--config', 'tauri.dev.conf.json']);
// Pass configuration inline as JSON
await run(['build', '--config', '{"bundle":{"active":true}}']);
// Use TOML configuration
await run(['build', '--config', 'tauri.prod.conf.toml']);The CLI automatically detects the package manager context and adjusts help messages accordingly:
// When run via npm scripts, shows: npm run tauri
// When run via yarn, shows: yarn tauri
// When run via pnpm, shows: pnpm tauri
// When run via bun, shows: bun tauri
// When run directly, shows: node tauri.js// Main API - Promise-based interface (main.js exports)
declare function run(
args: Array<string>,
binName?: string | undefined | null
): Promise<boolean>;
declare function logError(error: string): void;
// Native bindings - Callback-based interface (index.js exports)
declare function run(
args: Array<string>,
binName: string | undefined | null,
callback: ((err: Error | null, arg: boolean) => any)
): void;
declare function logError(error: string): void;