nuxi
Version:
Nuxt CLI
133 lines (132 loc) • 5.7 kB
JavaScript
import { o as __toESM } from "./chunk-Vs_PY4HZ.mjs";
import { r as runMain$1, t as defineCommand } from "./dist-B03QHgrC.mjs";
import { n as colors } from "./consola.DXBYu-KD-qSGefJ79.mjs";
import "./utils-MaFlCoS1.mjs";
import { r as f } from "./dist-BkNIIgFa.mjs";
import { n as name, r as version, t as description } from "./package-CptHM_tu.mjs";
import { t as cwdArgs } from "./_shared-D6pJgr6t.mjs";
import { t as runCommand } from "./run-CwixkrKi.mjs";
import { t as consola } from "./dist-Bvi-he5H.mjs";
import { n as logger, t as debug } from "./logger-CtlB9piy.mjs";
import { t as templateNames } from "./names-eOHfdsDZ.mjs";
import { builtinModules, createRequire } from "node:module";
import nodeCrypto from "node:crypto";
import { resolve } from "node:path";
import process from "node:process";
//#region src/commands/index.ts
const _rDefault = (r) => r.default || r;
const commands = {
"add": () => import("./add-C1fhsUXS.mjs").then(_rDefault),
"add-template": () => import("./add-template-RtdeE1Rh.mjs").then(_rDefault),
"analyze": () => import("./analyze-B8Lh_5VU.mjs").then(_rDefault),
"build": () => import("./build-CfzeEH6E.mjs").then(_rDefault),
"cleanup": () => import("./cleanup-Cg2ymrnY.mjs").then(_rDefault),
"_dev": () => import("./dev-child-ezkhyRu2.mjs").then(_rDefault),
"dev": () => import("./dev-DmLpxaNs.mjs").then(_rDefault),
"devtools": () => import("./devtools-D87-Lylz.mjs").then(_rDefault),
"generate": () => import("./generate-BAyhAmgG.mjs").then(_rDefault),
"info": () => import("./info-DjxuxH-i.mjs").then(_rDefault),
"init": () => import("./init-ChRtB-EM.mjs").then(_rDefault),
"module": () => import("./module-DPNJFg5T.mjs").then(_rDefault),
"prepare": () => import("./prepare-BhN-kzKt.mjs").then((n) => n.n).then(_rDefault),
"preview": () => import("./preview-CCoLd3CB.mjs").then(_rDefault),
"start": () => import("./preview-CCoLd3CB.mjs").then(_rDefault),
"test": () => import("./test-B6M8z0SY.mjs").then(_rDefault),
"typecheck": () => import("./typecheck-CN1AVF0h.mjs").then(_rDefault),
"upgrade": () => import("./upgrade-BLEZHkBT.mjs").then(_rDefault)
};
//#endregion
//#region src/utils/console.ts
function wrapReporter(reporter) {
return { log(logObj, ctx) {
if (!logObj.args || !logObj.args.length) return;
const msg = logObj.args[0];
if (typeof msg === "string" && !process.env.DEBUG) {
if (msg.startsWith("[Vue Router warn]: No match found for location with path")) return;
if (msg.includes("ExperimentalWarning: The Fetch API is an experimental feature")) return;
if (msg.startsWith("Sourcemap") && msg.includes("node_modules")) return;
}
return reporter.log(logObj, ctx);
} };
}
function setupGlobalConsole(opts = {}) {
consola.options.reporters = consola.options.reporters.map(wrapReporter);
if (opts.dev) consola.wrapAll();
else consola.wrapConsole();
process.on("unhandledRejection", (err) => consola.error("[unhandledRejection]", err));
process.on("uncaughtException", (err) => consola.error("[uncaughtException]", err));
}
//#endregion
//#region src/utils/engines.ts
async function checkEngines() {
const satisfies = await import("./satisfies-DkYFy708.mjs").then((n) => /* @__PURE__ */ __toESM(n.t(), 1)).then((r) => r.default || r);
const currentNode = process.versions.node;
const nodeRange = ">= 18.0.0";
if (!satisfies(currentNode, nodeRange)) logger.warn(`Current version of Node.js (${colors.cyan(currentNode)}) is unsupported and might cause issues.\n Please upgrade to a compatible version ${colors.cyan(nodeRange)}.`);
}
//#endregion
//#region src/main.ts
if (!globalThis.crypto) globalThis.crypto = nodeCrypto.webcrypto;
if (!process.getBuiltinModule) {
const _require = createRequire(import.meta.url);
process.getBuiltinModule = (name) => {
if (name.startsWith("node:") || builtinModules.includes(name)) return _require.resolve(name);
};
}
const main = defineCommand({
meta: {
name: name.endsWith("nightly") ? name : "nuxi",
version,
description
},
args: {
...cwdArgs,
command: {
type: "positional",
required: false
}
},
subCommands: commands,
async setup(ctx) {
const command = ctx.args._[0];
setupGlobalConsole({ dev: command === "dev" });
debug(`Running \`nuxt ${command}\` command`);
let backgroundTasks;
if (command !== "_dev" && f !== "stackblitz") backgroundTasks = Promise.all([checkEngines()]).catch((err) => logger.error(String(err)));
if (command === "init") await backgroundTasks;
if (command === "add" && ctx.rawArgs[1] && templateNames.includes(ctx.rawArgs[1])) {
logger.warn(`${colors.yellow("Deprecated:")} Using ${colors.cyan("nuxt add <template> <name>")} is deprecated.`);
logger.info(`Please use ${colors.cyan("nuxt add-template <template> <name>")} instead.`);
await runCommand(await import("./add-template-RtdeE1Rh.mjs").then((m) => m.default || m), [...ctx.rawArgs.slice(1)]).catch((err) => {
console.error(err.message);
process.exit(1);
});
process.exit(0);
}
if (ctx.args.command && !(ctx.args.command in commands)) {
const cwd = resolve(ctx.args.cwd);
try {
const { x } = await import("./main-BD07ngkv.mjs").then((n) => n.n);
await x(`nuxt-${ctx.args.command}`, ctx.rawArgs.slice(1), {
nodeOptions: {
stdio: "inherit",
cwd
},
throwOnError: true
});
} catch (err) {
if (err instanceof Error && "code" in err && err.code === "ENOENT") return;
}
process.exit();
}
}
});
async function runMain() {
if (process.argv[2] === "complete") {
const { initCompletions } = await import("./completions-CmRQ8F9y.mjs");
await initCompletions(main);
}
return runMain$1(main);
}
//#endregion
export { main, runCommand, runMain };