优化返水预览/确认/作废,新增玩家账变详情与后台一键重置为 seed 数据,并修复 dev 启动时 3000 端口占用。 Co-authored-by: Cursor <cursoragent@cursor.com>
40 lines
925 B
JavaScript
40 lines
925 B
JavaScript
import { execSync } from 'node:child_process';
|
|
|
|
const port = process.argv[2] ?? '3000';
|
|
|
|
function killWindows(portNum) {
|
|
let out = '';
|
|
try {
|
|
out = execSync(`netstat -ano | findstr :${portNum}`, { encoding: 'utf8' });
|
|
} catch {
|
|
return;
|
|
}
|
|
|
|
const pids = new Set();
|
|
for (const line of out.split('\n')) {
|
|
if (!line.includes('LISTENING')) continue;
|
|
const pid = line.trim().split(/\s+/).at(-1);
|
|
if (pid && pid !== '0') pids.add(pid);
|
|
}
|
|
|
|
for (const pid of pids) {
|
|
try {
|
|
console.log(`[ensure-port-free] freeing :${portNum} (PID ${pid})`);
|
|
execSync(`taskkill /F /PID ${pid}`, { stdio: 'ignore' });
|
|
} catch {
|
|
// already gone
|
|
}
|
|
}
|
|
}
|
|
|
|
function killUnix(portNum) {
|
|
try {
|
|
execSync(`lsof -ti tcp:${portNum} | xargs -r kill -9`, { stdio: 'ignore' });
|
|
} catch {
|
|
// port already free
|
|
}
|
|
}
|
|
|
|
if (process.platform === 'win32') killWindows(port);
|
|
else killUnix(port);
|