feat(cli): programmatically pass nuxt config overrides (to dev) (#19371)

This commit is contained in:
Sebastian Landwehr 2023-03-08 12:32:00 +01:00 committed by GitHub
parent c2ab76d68e
commit e344321d92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 6 deletions

View File

@ -22,7 +22,7 @@ export default defineNuxtCommand({
usage: 'npx nuxi dev [rootDir] [--dotenv] [--log-level] [--clipboard] [--open, -o] [--port, -p] [--host, -h] [--https] [--ssl-cert] [--ssl-key]', usage: 'npx nuxi dev [rootDir] [--dotenv] [--log-level] [--clipboard] [--open, -o] [--port, -p] [--host, -h] [--https] [--ssl-cert] [--ssl-key]',
description: 'Run nuxt development server' description: 'Run nuxt development server'
}, },
async invoke (args) { async invoke (args, options = {}) {
overrideEnv('development') overrideEnv('development')
const { listen } = await import('listhen') const { listen } = await import('listhen')
@ -50,7 +50,8 @@ export default defineNuxtCommand({
cwd: rootDir, cwd: rootDir,
overrides: { overrides: {
dev: true, dev: true,
logLevel: args['log-level'] logLevel: args['log-level'],
...(options.overrides || {})
} }
}) })
@ -96,7 +97,8 @@ export default defineNuxtCommand({
dev: true, dev: true,
ready: false, ready: false,
overrides: { overrides: {
logLevel: args['log-level'] logLevel: args['log-level'],
...(options.overrides || {})
} }
}) })

View File

@ -37,7 +37,7 @@ export interface NuxtCommandMeta {
export type CLIInvokeResult = void | 'error' | 'wait' export type CLIInvokeResult = void | 'error' | 'wait'
export interface NuxtCommand { export interface NuxtCommand {
invoke(args: Argv): Promise<CLIInvokeResult> | CLIInvokeResult invoke(args: Argv, options?: Record<string, any>): Promise<CLIInvokeResult> | CLIInvokeResult
meta: NuxtCommandMeta meta: NuxtCommandMeta
} }

View File

@ -2,12 +2,12 @@ import mri from 'mri'
import type { Command, NuxtCommand } from './commands' import type { Command, NuxtCommand } from './commands'
import { commands } from './commands' import { commands } from './commands'
export async function runCommand (command: string, argv = process.argv.slice(2)) { export async function runCommand (command: string, argv = process.argv.slice(2), options: Record<string, any> = {}) {
const args = mri(argv) const args = mri(argv)
args.clear = false // used by dev args.clear = false // used by dev
const cmd = await commands[command as Command]() as NuxtCommand const cmd = await commands[command as Command]() as NuxtCommand
if (!cmd) { if (!cmd) {
throw new Error(`Invalid command ${command}`) throw new Error(`Invalid command ${command}`)
} }
await cmd.invoke(args) await cmd.invoke(args, options)
} }