67 lines
2 KiB
JavaScript
67 lines
2 KiB
JavaScript
/**
|
|
* `npm run tauri <args>` wrapper.
|
|
*
|
|
* 1. Sets CARGO_TARGET_DIR to a space-free path so GNU windres does not break on
|
|
* spaces in the project path (see target-dir.js).
|
|
* 2. After `build`, replaces the executable's manifest with the single
|
|
* `requireAdministrator` one (GNU ld otherwise keeps the CRT's asInvoker
|
|
* manifest and UAC never triggers).
|
|
* 3. Re-runs `tauri bundle` so the installer contains the patched executable.
|
|
*
|
|
* Set LD_FDPI_NO_ADMIN=1 for an asInvoker test build (skips the manifest patch).
|
|
*/
|
|
import { spawnSync } from "node:child_process";
|
|
import path from "node:path";
|
|
import { ROOT, resolveTargetDir } from "./target-dir.js";
|
|
import { patchManifest } from "./patch-manifest.mjs";
|
|
|
|
const cli = path.join(ROOT, "node_modules", "@tauri-apps", "cli", "tauri.js");
|
|
const targetDir = resolveTargetDir();
|
|
const env = { ...process.env, CARGO_TARGET_DIR: targetDir };
|
|
const args = process.argv.slice(2);
|
|
|
|
const noAdmin = Boolean(process.env.LD_FDPI_NO_ADMIN);
|
|
const command = args[0];
|
|
const isBuild = command === "build";
|
|
const isBundle = command === "bundle";
|
|
const noBundle = args.includes("--no-bundle");
|
|
|
|
console.log(`[LD FDPI] CARGO_TARGET_DIR=${targetDir}`);
|
|
|
|
function run(list) {
|
|
const result = spawnSync(process.execPath, [cli, ...list], {
|
|
stdio: "inherit",
|
|
cwd: ROOT,
|
|
env,
|
|
});
|
|
return result.status ?? 1;
|
|
}
|
|
|
|
(async () => {
|
|
// Test builds stay asInvoker so they can be launched without UAC.
|
|
if (noAdmin) {
|
|
process.exit(run(args));
|
|
}
|
|
|
|
if (isBundle) {
|
|
await patchManifest();
|
|
process.exit(run(args));
|
|
}
|
|
|
|
if (isBuild && !noBundle) {
|
|
const buildStatus = run([...args, "--no-bundle"]);
|
|
if (buildStatus !== 0) process.exit(buildStatus);
|
|
await patchManifest();
|
|
// Package the already-patched binary into the NSIS installer.
|
|
process.exit(run(["bundle"]));
|
|
}
|
|
|
|
const status = run(args);
|
|
if (status === 0 && isBuild) {
|
|
await patchManifest();
|
|
}
|
|
process.exit(status);
|
|
})().catch((error) => {
|
|
console.error("[LD FDPI]", error.message);
|
|
process.exit(1);
|
|
});
|