39 lines
1.8 KiB
TypeScript
39 lines
1.8 KiB
TypeScript
/**
|
|
* After `tauri build`: renames the NSIS installer to its published name (src/installer-name.ts), so
|
|
* the release step's `*-setup.exe` finds one file, and its name has no space.
|
|
*
|
|
* tsx scripts/installer-name.ts in src-tauri/target/release/bundle/nsis/
|
|
*/
|
|
import { existsSync, readdirSync, renameSync, rmSync } from 'node:fs';
|
|
import { join, resolve } from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
import { INSTALLER_PATTERN, installerName, tauriInstallerName } from '../src/installer-name.js';
|
|
import { gameVersion } from './domi-app.js';
|
|
import { SRC_TAURI } from './tauri.js';
|
|
|
|
/**
|
|
* Renames the version's installer in `dir` and removes any other installer there (an older build's,
|
|
* which the release's `*-setup.exe` would otherwise publish too). Returns the new path. Fails if the
|
|
* built file is missing, or if anything but the one accepted installer is left.
|
|
*/
|
|
export function renameInstaller(dir: string, version: string): string {
|
|
const from = join(dir, tauriInstallerName(version));
|
|
const name = installerName(version);
|
|
const to = join(dir, name);
|
|
if (!existsSync(from)) throw new Error(`no installer to rename: ${from}`);
|
|
for (const f of readdirSync(dir)) {
|
|
if (f.endsWith('-setup.exe') && f !== tauriInstallerName(version)) rmSync(join(dir, f));
|
|
}
|
|
renameSync(from, to);
|
|
const left = readdirSync(dir).filter((f) => f.endsWith('-setup.exe'));
|
|
if (left.length !== 1 || left[0] !== name || !INSTALLER_PATTERN.test(name)) {
|
|
throw new Error(`expected only ${name}, found: ${left.join(', ')}`);
|
|
}
|
|
return to;
|
|
}
|
|
|
|
if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
const to = renameInstaller(join(SRC_TAURI, 'target', 'release', 'bundle', 'nsis'), gameVersion());
|
|
console.log(`installer: ${to}`);
|
|
}
|