-
Notifications
You must be signed in to change notification settings - Fork 101
Expand file tree
/
Copy pathtauri.js
More file actions
executable file
·94 lines (76 loc) · 2.95 KB
/
Copy pathtauri.js
File metadata and controls
executable file
·94 lines (76 loc) · 2.95 KB
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
#!/usr/bin/env node
//MISE description="Run Tauri CLI"
//MISE depends="tauri:setup"
//MISE raw_args=true
/**
* Passes through to the Tauri CLI. When the first argument is a desktop runtime
* (`wry` or `cef`) and the second is `dev` or `build`, injects the appropriate
* Cargo feature flags (`--features <runtime>,updater --no-default-features`).
* Everything else is forwarded to `tauri` as-is.
*
* script/tauri cef dev --verbose
* → tauri dev --features cef,updater -- --verbose --no-default-features
*
* Pass `--no-updater` to omit the bundled auto-updater, for distro packagers and
* anyone building from source who updates through their own channel:
*
* script/tauri wry build --no-updater
* → tauri build --features wry -- --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);
process.chdir(join(__dirname, '..'));
const DESKTOP = new Set(['wry', 'cef']);
async function runTauri(args) {
logger.info(`${dim('Running:')} tauri ${args.join(' ')}`);
try {
await run(args, 'tauri');
} catch (error) {
logger.error(`Failed to run tauri: ${error?.message ?? error}`);
process.exit(1);
}
}
async function main() {
if (cmdlineArgs.length === 0 || !DESKTOP.has(cmdlineArgs[0])) {
return runTauri(cmdlineArgs);
}
const [platform, cmd, ...rawTauriArgs] = cmdlineArgs;
if (!cmd) {
return runTauri(cmdlineArgs);
}
if (!['dev', 'build'].includes(cmd)) {
return runTauri([cmd, ...rawTauriArgs]);
}
// Consumed here, not forwarded: the tauri CLI does not know this flag.
const noUpdater = rawTauriArgs.includes('--no-updater');
const tauriArgs = rawTauriArgs.filter((arg) => arg !== '--no-updater');
if (noUpdater) {
logger.info('Building without the auto-updater (--no-updater)');
}
// The frontend is built before Cargo, so mirror the updater feature into Vite.
process.env.VITE_DESKTOP_UPDATER_ENABLED = String(!noUpdater);
const base = noUpdater ? platform : `${platform},updater`;
const features = `${base},matrix-crypto`;
const args = [cmd, '--features', features, ...tauriArgs];
if (!tauriArgs.includes('--')) {
args.push('--');
}
args.push('--no-default-features');
if (noUpdater && cmd === 'build') {
// Signed updater artifacts would otherwise demand TAURI_SIGNING_PRIVATE_KEY.
args.splice(1, 0, '--config', JSON.stringify({ bundle: { createUpdaterArtifacts: false } }));
}
if (platform === 'cef' && cmd === 'build' && !tauriArgs.includes('--no-bundle')) {
args.splice(1, 0, '--no-bundle');
}
return runTauri(args);
}
main();