Files
s41r4j-phomber/scripts/local.mjs
T
2026-11-20 15:34:50 +05:30

23 lines
932 B
JavaScript

import { spawn } from 'node:child_process';
import { access } from 'node:fs/promises';
import { fileURLToPath } from 'node:url';
import { join } from 'node:path';
const root = fileURLToPath(new URL('../', import.meta.url));
const entry = join(root, 'dist', 'cli', 'index.js');
try { await access(entry); }
catch { console.error('Build PH0MBER first: npm run setup:local'); process.exit(1); }
const child = spawn(process.execPath, [entry, ...process.argv.slice(2)], {
env: process.env,
stdio: 'inherit',
});
const interrupt = () => child.kill('SIGINT');
const terminate = () => child.kill('SIGTERM');
process.on('SIGINT', interrupt);
process.on('SIGTERM', terminate);
child.on('error', error => { console.error(error.message); process.exitCode = 1; });
child.on('exit', (code, signal) => {
process.off('SIGINT', interrupt);
process.off('SIGTERM', terminate);
process.exitCode = code ?? (signal === 'SIGINT' ? 130 : 1);
});