diff --git a/src/commands/_shared.ts b/src/commands/_shared.ts index e8c86f81d..936c4cf25 100644 --- a/src/commands/_shared.ts +++ b/src/commands/_shared.ts @@ -16,6 +16,13 @@ export const envNameArgs = { }, } as const +export const dotEnvArgs = { + dotenv: { + type: 'string', + description: 'Path to .env file', + }, +} as const + export const legacyRootDirArgs = { rootDir: { type: 'positional', diff --git a/src/commands/analyze.ts b/src/commands/analyze.ts index c5c4c129a..e57a938f7 100644 --- a/src/commands/analyze.ts +++ b/src/commands/analyze.ts @@ -8,7 +8,7 @@ import { defineCommand } from 'citty' import { loadKit } from '../utils/kit' import { clearDir } from '../utils/fs' import { overrideEnv } from '../utils/env' -import { sharedArgs, legacyRootDirArgs } from './_shared' +import { sharedArgs, legacyRootDirArgs, dotEnvArgs } from './_shared' export default defineCommand({ meta: { @@ -18,6 +18,7 @@ export default defineCommand({ args: { ...sharedArgs, ...legacyRootDirArgs, + ...dotEnvArgs, name: { type: 'string', description: 'Name of the analysis', @@ -42,6 +43,10 @@ export default defineCommand({ const nuxt = await loadNuxt({ cwd, + dotenv: { + cwd, + fileName: ctx.args.dotenv, + }, overrides: defu(ctx.data?.overrides, { build: { analyze: { diff --git a/src/commands/build.ts b/src/commands/build.ts index e26452a58..4703a6a48 100644 --- a/src/commands/build.ts +++ b/src/commands/build.ts @@ -6,7 +6,7 @@ import { loadKit } from '../utils/kit' import { clearBuildDir } from '../utils/fs' import { overrideEnv } from '../utils/env' import { showVersions } from '../utils/banner' -import { sharedArgs, envNameArgs, legacyRootDirArgs } from './_shared' +import { sharedArgs, envNameArgs, legacyRootDirArgs, dotEnvArgs } from './_shared' export default defineCommand({ meta: { @@ -23,10 +23,7 @@ export default defineCommand({ type: 'string', description: 'Nitro server preset', }, - dotenv: { - type: 'string', - description: 'Path to .env file', - }, + ...dotEnvArgs, ...envNameArgs, ...legacyRootDirArgs, }, diff --git a/src/commands/dev.ts b/src/commands/dev.ts index 688359959..c6918731b 100644 --- a/src/commands/dev.ts +++ b/src/commands/dev.ts @@ -17,7 +17,7 @@ import { loadKit } from '../utils/kit' import { importModule } from '../utils/esm' import { overrideEnv } from '../utils/env' import type { NuxtDevContext, NuxtDevIPCMessage } from '../utils/dev' -import { sharedArgs, envNameArgs, legacyRootDirArgs } from './_shared' +import { sharedArgs, envNameArgs, legacyRootDirArgs, dotEnvArgs } from './_shared' const forkSupported = !isBun && !isTest @@ -31,10 +31,7 @@ const command = defineCommand({ ...envNameArgs, ...legacyRootDirArgs, ...getListhenArgs(), - dotenv: { - type: 'string', - description: 'Path to .env file', - }, + ...dotEnvArgs, clear: { type: 'boolean', description: 'Clear console on restart', diff --git a/src/commands/generate.ts b/src/commands/generate.ts index f94eeb726..311459211 100644 --- a/src/commands/generate.ts +++ b/src/commands/generate.ts @@ -1,7 +1,7 @@ import { defineCommand } from 'citty' import buildCommand from './build' -import { sharedArgs, envNameArgs, legacyRootDirArgs } from './_shared' +import { sharedArgs, envNameArgs, legacyRootDirArgs, dotEnvArgs } from './_shared' export default defineCommand({ meta: { @@ -12,10 +12,7 @@ export default defineCommand({ ...sharedArgs, ...envNameArgs, ...legacyRootDirArgs, - dotenv: { - type: 'string', - description: 'Path to .env file', - }, + ...dotEnvArgs, }, async run(ctx) { ctx.args.prerender = true diff --git a/src/commands/prepare.ts b/src/commands/prepare.ts index 228182504..2d01368c0 100644 --- a/src/commands/prepare.ts +++ b/src/commands/prepare.ts @@ -7,7 +7,7 @@ import { defineCommand } from 'citty' import { clearBuildDir } from '../utils/fs' import { loadKit } from '../utils/kit' -import { sharedArgs, envNameArgs, legacyRootDirArgs } from './_shared' +import { sharedArgs, envNameArgs, legacyRootDirArgs, dotEnvArgs } from './_shared' export default defineCommand({ meta: { @@ -15,10 +15,7 @@ export default defineCommand({ description: 'Prepare Nuxt for development/build', }, args: { - dotenv: { - type: 'string', - description: 'Path to .env file', - }, + ...dotEnvArgs, ...sharedArgs, ...envNameArgs, ...legacyRootDirArgs, diff --git a/src/commands/preview.ts b/src/commands/preview.ts index f2d7fdf8f..2c35a2250 100644 --- a/src/commands/preview.ts +++ b/src/commands/preview.ts @@ -8,7 +8,7 @@ import { box, colors } from 'consola/utils' import { defineCommand } from 'citty' import { loadKit } from '../utils/kit' -import { sharedArgs, envNameArgs, legacyRootDirArgs } from './_shared' +import { sharedArgs, envNameArgs, legacyRootDirArgs, dotEnvArgs } from './_shared' export default defineCommand({ meta: { @@ -19,10 +19,7 @@ export default defineCommand({ ...sharedArgs, ...envNameArgs, ...legacyRootDirArgs, - dotenv: { - type: 'string', - description: 'Path to .env file', - }, + ...dotEnvArgs, }, async run(ctx) { process.env.NODE_ENV = process.env.NODE_ENV || 'production'