miranda-engine / client-scripts /open-editor-preview.mjs
hunt
Rebuild Miranda-Engine from scratch β€” real repo, real content
fed1528
Raw History Blame Contribute Delete
4.06 kB
#!/usr/bin/env node
/**
* Opens the EVE ECC preview inside VS Code / Cursor / Insiders Simple Browser
* when a compatible CLI is available; otherwise prints Ports-panel instructions.
*
* Env:
* EVE_PREVIEW_URL default http://127.0.0.1:5173
* EVE_PREVIEW_PORT default 5173
*/
import { spawnSync } from "node:child_process";
import { createConnection } from "node:net";
const url = process.env.EVE_PREVIEW_URL || "http://127.0.0.1:5173";
const port = Number(process.env.EVE_PREVIEW_PORT || 5173);
const isWin = process.platform === "win32";
function waitForPort(p, host = "127.0.0.1", timeoutMs = 60000) {
const start = Date.now();
return new Promise((resolve, reject) => {
const tryOnce = () => {
const socket = createConnection({ port: p, host }, () => {
socket.end();
resolve(true);
});
socket.on("error", () => {
socket.destroy();
if (Date.now() - start > timeoutMs) {
reject(new Error(`Timed out waiting for ${host}:${p}`));
return;
}
setTimeout(tryOnce, 400);
});
};
tryOnce();
});
}
function run(cmd, args) {
return spawnSync(cmd, args, {
stdio: "inherit",
shell: isWin,
env: process.env,
});
}
function findEditorCli() {
const candidates = [
process.env.VSCODE_GIT_ASKPASS?.includes("code-insiders")
? "code-insiders"
: null,
"code-insiders",
"code",
"cursor",
].filter(Boolean);
for (const cli of candidates) {
const probe = spawnSync(cli, ["-v"], {
shell: isWin,
stdio: "ignore",
});
if (probe.status === 0) return cli;
}
return null;
}
console.log(`[eve-preview] waiting for port ${port}…`);
try {
await waitForPort(port);
} catch (err) {
console.error(`[eve-preview] ${err.message}`);
console.error("[eve-preview] Start the dev server first: npm run dev");
process.exit(1);
}
console.log(`[eve-preview] ${url} is up`);
// Prefer VS Code Insiders URI handler that routes into Simple Browser when possible.
// Note: external browser may still open depending on OS defaults β€” Ports panel
// "openPreview" is the reliable in-editor path (configured in .vscode/settings.json).
const cli = findEditorCli();
if (cli) {
console.log(`[eve-preview] editor CLI: ${cli}`);
console.log("[eve-preview] Tip: Ports β†’ 5173 β†’ Open in Browser uses Simple Browser (openPreview).");
console.log("[eve-preview] Or Command Palette β†’ β€œSimple Browser: Show”");
} else {
console.log("[eve-preview] No code/cursor CLI on PATH β€” use Ports panel / Simple Browser: Show");
}
console.log("");
console.log("β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”");
console.log("β”‚ In-editor preview (Cursor / Claude / VS Code style) β”‚");
console.log("β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€");
console.log("β”‚ 1. Ports panel β†’ port 5173 β†’ globe / Open in Browser β”‚");
console.log("β”‚ (configured as Simple Browser / openPreview) β”‚");
console.log("β”‚ 2. Command Palette β†’ β€œSimple Browser: Show” β”‚");
console.log(`β”‚ β†’ ${url.padEnd(43)}β”‚`);
console.log("β”‚ 3. Task: β€œEVE: Start Preview in Editor” β”‚");
console.log("β”‚ β”‚");
console.log("β”‚ Reserved project ports β”‚");
console.log("β”‚ 5173 EVE ECC IDE (Vite) β”‚");
console.log("β”‚ 4173 Production preview β”‚");
console.log("β”‚ 8100 ACE controller β”‚");
console.log("β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜");