|
| 1 | +#!/usr/bin/env node |
| 2 | + |
| 3 | +import { spawn } from "node:child_process"; |
| 4 | +import fs from "node:fs"; |
| 5 | +import path from "node:path"; |
| 6 | +import process from "node:process"; |
| 7 | +import { fileURLToPath } from "node:url"; |
| 8 | + |
| 9 | +const scriptDir = path.dirname(fileURLToPath(import.meta.url)); |
| 10 | +const repoRoot = path.resolve(scriptDir, ".."); |
| 11 | +const packageJsonPath = path.join(repoRoot, "package.json"); |
| 12 | +const cargoTomlPath = path.join(repoRoot, "src-tauri", "Cargo.toml"); |
| 13 | +const tauriConfigPath = path.join(repoRoot, "src-tauri", "tauri.conf.json"); |
| 14 | + |
| 15 | +function syncCargoVersion(version) { |
| 16 | + const current = fs.readFileSync(cargoTomlPath, "utf8"); |
| 17 | + const next = current.replace(/^version = "[^"]+"/m, `version = "${version}"`); |
| 18 | + |
| 19 | + if (next !== current) { |
| 20 | + fs.writeFileSync(cargoTomlPath, next); |
| 21 | + return true; |
| 22 | + } |
| 23 | + |
| 24 | + return false; |
| 25 | +} |
| 26 | + |
| 27 | +function syncTauriConfigVersion(version) { |
| 28 | + const current = JSON.parse(fs.readFileSync(tauriConfigPath, "utf8")); |
| 29 | + |
| 30 | + if (current.version === version) { |
| 31 | + return false; |
| 32 | + } |
| 33 | + |
| 34 | + current.version = version; |
| 35 | + fs.writeFileSync(tauriConfigPath, `${JSON.stringify(current, null, 2)}\n`); |
| 36 | + return true; |
| 37 | +} |
| 38 | + |
| 39 | +const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8")); |
| 40 | +const version = packageJson.version; |
| 41 | +const args = process.argv.slice(2); |
| 42 | + |
| 43 | +const cargoSynced = syncCargoVersion(version); |
| 44 | +const tauriConfigSynced = syncTauriConfigVersion(version); |
| 45 | +const versionSynced = cargoSynced || tauriConfigSynced; |
| 46 | + |
| 47 | +if (versionSynced) { |
| 48 | + console.log(`[tauri] Synced src-tauri version files to ${version}`); |
| 49 | +} |
| 50 | + |
| 51 | +const env = { ...process.env }; |
| 52 | +const command = args[0]; |
| 53 | +const tauriArgs = [...args]; |
| 54 | + |
| 55 | +if ( |
| 56 | + process.platform === "linux" && |
| 57 | + (command === "build" || command === "bundle") && |
| 58 | + !env.APPIMAGE_EXTRACT_AND_RUN |
| 59 | +) { |
| 60 | + env.APPIMAGE_EXTRACT_AND_RUN = "1"; |
| 61 | + console.log("[tauri] Enabled APPIMAGE_EXTRACT_AND_RUN=1 for local Linux bundling"); |
| 62 | +} |
| 63 | + |
| 64 | +if (process.platform === "linux" && (command === "build" || command === "bundle") && !env.NO_STRIP) { |
| 65 | + env.NO_STRIP = "1"; |
| 66 | + console.log("[tauri] Enabled NO_STRIP=1 to avoid linuxdeploy strip failures"); |
| 67 | +} |
| 68 | + |
| 69 | +if ( |
| 70 | + (command === "build" || command === "bundle") && |
| 71 | + !env.TAURI_SIGNING_PRIVATE_KEY && |
| 72 | + !env.TAURI_SIGNING_PRIVATE_KEY_PATH |
| 73 | +) { |
| 74 | + tauriArgs.push( |
| 75 | + "--config", |
| 76 | + JSON.stringify({ |
| 77 | + bundle: { |
| 78 | + createUpdaterArtifacts: false, |
| 79 | + }, |
| 80 | + }) |
| 81 | + ); |
| 82 | + console.log("[tauri] Disabled updater artifacts for this local unsigned build"); |
| 83 | +} |
| 84 | + |
| 85 | +const tauriBin = |
| 86 | + process.platform === "win32" |
| 87 | + ? path.join(repoRoot, "node_modules", ".bin", "tauri.cmd") |
| 88 | + : path.join(repoRoot, "node_modules", ".bin", "tauri"); |
| 89 | + |
| 90 | +const child = spawn(tauriBin, tauriArgs, { |
| 91 | + cwd: repoRoot, |
| 92 | + env, |
| 93 | + stdio: "inherit", |
| 94 | +}); |
| 95 | + |
| 96 | +child.on("exit", (code, signal) => { |
| 97 | + if (signal) { |
| 98 | + process.kill(process.pid, signal); |
| 99 | + return; |
| 100 | + } |
| 101 | + |
| 102 | + process.exit(code ?? 0); |
| 103 | +}); |
| 104 | + |
| 105 | +child.on("error", (error) => { |
| 106 | + console.error("[tauri] Failed to start Tauri CLI:", error); |
| 107 | + process.exit(1); |
| 108 | +}); |
0 commit comments