mirror of
https://github.com/plebbit/seedit.git
synced 2026-04-17 21:58:58 -04:00
32 lines
998 B
JavaScript
32 lines
998 B
JavaScript
import { existsSync } from 'node:fs';
|
|
import { join } from 'node:path';
|
|
import { spawn } from 'node:child_process';
|
|
|
|
const isWindows = process.platform === 'win32';
|
|
const usePortless = process.env.PORTLESS !== '0' && !isWindows;
|
|
const binDir = join(process.cwd(), 'node_modules', '.bin');
|
|
const executableSuffix = isWindows ? '.cmd' : '';
|
|
const portlessBin = join(binDir, `portless${executableSuffix}`);
|
|
const viteBin = join(binDir, `vite${executableSuffix}`);
|
|
|
|
const command = usePortless && existsSync(portlessBin) ? portlessBin : viteBin;
|
|
const args = command === portlessBin ? ['seedit', 'vite'] : [];
|
|
|
|
if (command !== portlessBin && process.env.PORTLESS !== '0') {
|
|
console.warn('portless unavailable on this platform, using vite directly on http://localhost:3000');
|
|
}
|
|
|
|
const child = spawn(command, args, {
|
|
stdio: 'inherit',
|
|
env: process.env,
|
|
});
|
|
|
|
child.on('exit', (code, signal) => {
|
|
if (signal) {
|
|
process.kill(process.pid, signal);
|
|
return;
|
|
}
|
|
|
|
process.exit(code ?? 0);
|
|
});
|