Files
Your NameandClaude Sonnet 5.5 0b5f8bfa8b chore: project scaffold, build config, scripts and README
Bun + SvelteKit (static adapter) + Electron project files, icon resources,
dev/e2e/bench scripts and the README documenting the app.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-15 11:57:09 +02:00

34 lines
1.2 KiB
JavaScript

// `bun run dev` runs this: Electron with --dev, restarted whenever a file in electron/ changes.
// (Vite hot-reloads the page by itself, but the main process only loads its code once.)
import { spawn } from 'node:child_process';
import { watch } from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const root = path.join(path.dirname(fileURLToPath(import.meta.url)), '..');
const electron = path.join(root, 'node_modules', '.bin', 'electron');
let child = null;
let restarting = false;
let timer = null;
function start() {
child = spawn(electron, ['.', '--dev', ...process.argv.slice(2)], { cwd: root, stdio: 'inherit' });
child.on('exit', (code) => {
if (restarting) { restarting = false; start(); return; }
process.exit(code ?? 0); // the window was closed: stop dev mode, as before
});
}
watch(path.join(root, 'electron'), { recursive: true }, (_event, file) => {
if (!file || !/\.(c?js|json)$/.test(file)) return;
clearTimeout(timer);
timer = setTimeout(() => {
console.log(`[app] ${file} changed, restarting Electron`);
restarting = true;
child.kill('SIGTERM');
}, 250);
});
for (const sig of ['SIGINT', 'SIGTERM']) process.on(sig, () => { restarting = false; child?.kill(sig); });
start();