fix(ci): make portless optional for windows installs

This commit is contained in:
plebeius
2026-03-04 17:48:31 +08:00
parent 0207fad8ad
commit e484f96e3a
3 changed files with 48 additions and 3 deletions
+35
View File
@@ -0,0 +1,35 @@
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
? ['5chan', 'vite']
: ['--host', '5chan.localhost', '--port', '1355', '--strictPort'];
if (command !== portlessBin && process.env.PORTLESS !== '0') {
console.warn('portless unavailable on this platform, using vite directly on http://5chan.localhost:1355');
}
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);
});