TeamsPeach desktop client: Electron UI, Rust core bridge, TS6 stream viewer, CI
This commit is contained in:
commit
7287fdb63e
94 files changed
+33133
No files matched your search
@@ -0,0 +1,77 @@
|
||||
// Packages TeamsPeach for one OS/arch. Refuses to package without a native core of exactly that
|
||||
// OS/arch (header check), and ships the core's third-party notices next to it.
|
||||
//
|
||||
// node scripts/dist.mjs --os win|linux|mac --arch x64|arm64 [--core <path>] [--targets "nsis zip"]
|
||||
//
|
||||
// Default core path: core/target/<rust-triple>/release/…, else core/target/release/… (host build).
|
||||
import { spawnSync } from 'node:child_process';
|
||||
import { copyFileSync, existsSync, mkdirSync, rmSync, readdirSync, statSync } from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { binaryArch } from './binary-arch.mjs';
|
||||
|
||||
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
||||
const argv = process.argv.slice(2);
|
||||
const opt = (n, d) => (argv.indexOf(`--${n}`) >= 0 ? argv[argv.indexOf(`--${n}`) + 1] : d);
|
||||
const os = opt('os');
|
||||
const arch = opt('arch');
|
||||
const TRIPLES = {
|
||||
'win-x64': 'x86_64-pc-windows-msvc',
|
||||
'win-arm64': 'aarch64-pc-windows-msvc',
|
||||
'linux-x64': 'x86_64-unknown-linux-gnu',
|
||||
'linux-arm64': 'aarch64-unknown-linux-gnu',
|
||||
'mac-x64': 'x86_64-apple-darwin',
|
||||
'mac-arm64': 'aarch64-apple-darwin',
|
||||
};
|
||||
const key = `${os}-${arch}`;
|
||||
if (!TRIPLES[key]) {
|
||||
console.error(`unsupported --os/--arch ${key}; one of ${Object.keys(TRIPLES).join(', ')}`);
|
||||
process.exit(2);
|
||||
}
|
||||
const exe = os === 'win' ? 'teamspeach-core.exe' : 'teamspeach-core';
|
||||
const candidates = [
|
||||
opt('core'),
|
||||
path.join(root, 'core', 'target', TRIPLES[key], 'release', exe),
|
||||
path.join(root, 'core', 'target', 'release', exe),
|
||||
].filter(Boolean);
|
||||
const core = candidates.find((c) => existsSync(c));
|
||||
if (!core) {
|
||||
console.error(`No core binary for ${key}. Looked at:\n ${candidates.join('\n ')}\nBuild it first: cargo build --release --locked --manifest-path core/Cargo.toml --target ${TRIPLES[key]}`);
|
||||
process.exit(1);
|
||||
}
|
||||
const info = binaryArch(core);
|
||||
if (info.os !== os || info.arch !== arch) {
|
||||
console.error(`Core ${core} is ${info.os}-${info.arch}, not ${key}. Refusing to package.`);
|
||||
process.exit(1);
|
||||
}
|
||||
const notices = path.join(root, 'core', 'THIRD_PARTY_NOTICES.md');
|
||||
if (!existsSync(notices)) {
|
||||
console.error('core/THIRD_PARTY_NOTICES.md is missing; it must ship with the binary.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const stage = path.join(root, 'core-bin', key);
|
||||
rmSync(stage, { recursive: true, force: true });
|
||||
mkdirSync(stage, { recursive: true });
|
||||
copyFileSync(core, path.join(stage, exe));
|
||||
copyFileSync(notices, path.join(stage, 'THIRD_PARTY_NOTICES.md'));
|
||||
console.log(`staged ${core} (${info.os}-${info.arch}, ${statSync(core).size} bytes) → ${stage}`);
|
||||
|
||||
const builderArgs = [`--${os}`, `--${arch}`, '--publish', 'never'];
|
||||
const targets = opt('targets');
|
||||
if (targets) builderArgs.splice(1, 0, ...targets.split(' '));
|
||||
const cli = path.join(root, 'node_modules', 'electron-builder', 'cli.js');
|
||||
const run = spawnSync(process.execPath, [cli, ...builderArgs], { cwd: root, stdio: 'inherit' });
|
||||
if (run.status !== 0) process.exit(run.status ?? 1);
|
||||
|
||||
// Verify the packaged app really contains the core for this target.
|
||||
const dist = path.join(root, 'dist');
|
||||
const unpacked = readdirSync(dist).filter((d) => d.endsWith('-unpacked') || d === 'mac' || d === 'mac-arm64').map((d) => path.join(dist, d));
|
||||
const packagedCore = unpacked
|
||||
.map((d) => (os === 'mac' ? path.join(d, 'TeamsPeach.app', 'Contents', 'Resources', 'core', exe) : path.join(d, 'resources', 'core', exe)))
|
||||
.find((p) => existsSync(p) && binaryArch(p).arch === arch);
|
||||
if (!packagedCore) {
|
||||
console.error('Packaged output does not contain resources/core for this target.');
|
||||
process.exit(1);
|
||||
}
|
||||
console.log(`packaged core verified: ${packagedCore} (${JSON.stringify(binaryArch(packagedCore))})`);
|
||||
Reference in new issue
Block a user