@nuxt/cli
Version:
Nuxt CLI
59 lines (58 loc) • 2 kB
JavaScript
import { a as globalCwdArgs, h as defineCommand } from "./_shared-B9W-9akb.mjs";
import { D as ActionableError } from "./startup-clock-SyYej6uN.mjs";
import { i as resolveRootDir } from "./paths-BipyohVL.mjs";
import { c as withNodePath } from "./terminal-theme-jW0dFyAX.mjs";
import process from "node:process";
import { resolveModulePath } from "exsolve";
import { dirname, resolve } from "pathe";
import { readFileSync } from "node:fs";
import { x } from "tinyexec";
// src/commands/module/_builder.ts
const moduleRootArgs = {
rootDir: {
type: "positional",
description: "The root directory of your Nuxt module (default: .)",
required: false,
default: void 0
},
cwd: {
...globalCwdArgs.cwd,
description: "Specify the root directory of your Nuxt module"
}
};
function defineModuleBuilderCommand(name, description, args) {
return defineCommand({
meta: {
name,
description
},
args: {
...moduleRootArgs,
...args
},
async run(ctx) {
const bin = resolveModuleBuilderBin(resolveRootDir(ctx.args), name);
const result = await x(process.execPath, [
bin,
name,
...ctx.rawArgs
], {
nodeOptions: { stdio: "inherit" },
throwOnError: false
});
if (result.exitCode !== 0) process.exit(result.exitCode ?? 1);
}
});
}
function resolveModuleBuilderBin(rootDir, command) {
const manifest = resolveModulePath("@nuxt/module-builder/package.json", {
from: withNodePath(rootDir),
try: true
});
if (!manifest) throw new ActionableError(`\`@nuxt/module-builder\` is not installed in this module. Install it as a development dependency to use \`nuxt module ${command}\`.`);
const { bin } = JSON.parse(readFileSync(manifest, "utf8"));
const script = typeof bin === "object" ? bin["nuxt-module-build"] : void 0;
if (!script) throw new ActionableError(`The installed version of \`@nuxt/module-builder\` does not support \`nuxt module ${command}\`.`);
return resolve(dirname(manifest), script);
}
export { defineModuleBuilderCommand as t };