@nuxt/cli
Version:
Nuxt CLI
45 lines (44 loc) • 1.64 kB
JavaScript
import process from "node:process";
// src/boot.ts
/** Flags that mean this is not going to be a panel session. */
const OPT_OUT = /^(?:--help|-h|--version|-v|--no-tui|--tui|--inspect|--inspect-brk|--profile)(?:=|$)/;
/**
* Paint the dev panel and bind its shortcuts, before the command graph loads.
*
* The `dev` command joins the same session and the same shortcut context, and
* gives the terminal back if the resolved arguments refuse the panel.
*/
async function bootDevUI() {
const argv = process.argv.slice(2);
if (argv[0] !== "dev" || argv.some((arg) => OPT_OUT.test(arg))) return;
if (!process.stdout.isTTY || !process.stdin.isTTY) return;
const options = {
cwd: resolveCwd(argv),
startTime: globalThis.__nuxt_cli__?.startTime
};
const { paintFirstFrame } = await import("./first-frame-Cpw2wqBl.mjs").then((n) => n.n);
const start = paintFirstFrame(options);
if (!start) return;
try {
const { devShortcutContext } = await import("./shortcut-context-jl_XQvPi.mjs");
const { setupDevUI } = await import("./controller-CGIgXr38.mjs");
await setupDevUI(devShortcutContext().context, {
...options,
start
});
} catch (error) {
start.surface.close();
throw error;
}
await new Promise((resolve) => setImmediate(resolve));
}
/** Where to read the project version from: `--cwd`, or `dev`'s `ROOTDIR`. */
function resolveCwd(argv) {
for (let index = 1; index < argv.length; index++) {
const arg = argv[index];
if (arg.startsWith("--cwd=")) return arg.slice(6);
if (arg === "--cwd") return argv[index + 1];
}
return argv[1] && !argv[1].startsWith("-") ? argv[1] : void 0;
}
export { bootDevUI };