#!/usr/bin/env node /** * Script to run tauri commands for a given runtime (wry or cef) with prepended CLI args. * * Usage: * script/tauri [prepended-args...] * * Examples: * script/tauri cef dev --verbose * script/tauri cef dev -- --verbose * Both will run: tauri dev --features cef -- --verbose --no-default-features */ import { run } from '@tauri-apps/cli'; import { fileURLToPath } from 'url'; import { dirname, join } from 'path'; import process from 'node:process'; import { PrefixedLogger, createTextHelpers } from './utils/console-style.js'; const logger = new PrefixedLogger('[tauri]'); const { dim } = createTextHelpers({ useColor: logger.useColor }); const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); const cmdlineArgs = process.argv.slice(2); if (cmdlineArgs.length < 2) { logger.error('Usage: node scripts/tauri [prepended-args...]'); logger.error(` ${dim('command:')} dev or build`); logger.error(` ${dim('runtime:')} wry or cef`); logger.error( ` ${dim('prepended-args:')} Arguments to prepend to the cargo args (-- separator is optional)` ); process.exit(1); } const [runtime, cmd, ...tauriArgs] = cmdlineArgs; if (!['wry', 'cef'].includes(runtime)) { logger.error(`Invalid runtime: ${runtime}. Must be 'wry' or 'cef'`); process.exit(1); } if (!['dev', 'build'].includes(cmd)) { logger.error(`Invalid command: ${cmd}. Must be 'dev' or 'build'`); process.exit(1); } tauriArgs.unshift('--features', runtime); // tauri's Linux bundler can't package CEF; scripts/cef-package.sh does that. if (runtime === 'cef' && cmd === 'build' && !tauriArgs.includes('--no-bundle')) { tauriArgs.unshift('--no-bundle'); } if (!tauriArgs.includes('--')) { tauriArgs.push('--'); } tauriArgs.push('--no-default-features'); const args = [cmd, ...tauriArgs]; process.chdir(join(__dirname, '..')); logger.info(`${dim('Running:')} tauri ${args.join(' ')}`); run(args, 'tauri').catch((error) => { logger.error(`Failed to run tauri: ${error?.message ?? error}`); process.exit(1); });