Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions packages/nuxt-cli/src/commands/add-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@ import { templates } from '../utils/templates/index'
import { httpMethods, modes } from '../utils/templates/modifiers'
import { templateNames } from '../utils/templates/names'
import { cwdArgs, logLevelArgs } from './_shared'
import { commandMeta } from './meta'

const modifierArgs = Object.fromEntries([
...modes.map(mode => [mode, `Shorthand for \`--mode ${mode}\``] as const),
...httpMethods.map(method => [method, `Shorthand for \`--method ${method}\``] as const),
].map(([name, description]) => [name, { type: 'boolean', description }] as const))

export default defineCommand({
meta: {
name: 'add-template',
description: 'Create a new template file.',
},
meta: commandMeta['add-template'],
args: {
...cwdArgs,
...logLevelArgs,
Expand Down
6 changes: 2 additions & 4 deletions packages/nuxt-cli/src/commands/analyze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { intro, logger, outro } from '../utils/logger'
import { relativeToProcess, resolveRootDir } from '../utils/paths'
import { resolveServerBuild } from '../utils/server-build'
import { dotEnvArgs, extendsArgs, logLevelArgs, rootDirArgs } from './_shared'
import { commandMeta } from './meta'

const NON_WORD_RE = /[^\w-]/g

Expand All @@ -44,10 +45,7 @@ const indexHtml = `
`.trim()

export default defineCommand({
meta: {
name: 'analyze',
description: 'Build Nuxt and analyze production bundle (experimental)',
},
meta: commandMeta.analyze,
args: {
...rootDirArgs,
...logLevelArgs,
Expand Down
6 changes: 2 additions & 4 deletions packages/nuxt-cli/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@ import { createPhaseReporter, formatPhaseBreakdown } from '../utils/phase-report
import { startCpuProfile, stopCpuProfile } from '../utils/profile'
import { resolveServerBuild } from '../utils/server-build'
import { dotEnvArgs, envNameArgs, extendsArgs, logLevelArgs, profileArgs, rootDirArgs, targetArgs } from './_shared'
import { commandMeta } from './meta'

/** How often a phase repeats itself where there is no animated line. */
const HEARTBEAT_INTERVAL = 5000

export default defineCommand({
meta: {
name: 'build',
description: 'Build Nuxt for production deployment',
},
meta: commandMeta.build,
args: {
...rootDirArgs,
...logLevelArgs,
Expand Down
6 changes: 2 additions & 4 deletions packages/nuxt-cli/src/commands/cleanup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ import { logger } from '../utils/logger'
import { cleanupNuxtDirs } from '../utils/nuxt'
import { resolveRootDir } from '../utils/paths'
import { rootDirArgs } from './_shared'
import { commandMeta } from './meta'

export default defineCommand({
meta: {
name: 'cleanup',
description: 'Clean up generated Nuxt files and caches',
},
meta: commandMeta.cleanup,
args: {
...rootDirArgs,
},
Expand Down
6 changes: 2 additions & 4 deletions packages/nuxt-cli/src/commands/curl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { logger } from '../utils/logger'
import { logNetworkError } from '../utils/network'
import { resolveRootDir } from '../utils/paths'
import { rootDirArgs } from './_shared'
import { commandMeta } from './meta'

const HAS_SCHEME_RE = /^[a-z][a-z\d+.-]*:\/\//i
const JSON_CONTENT_TYPE_RE = /^application\/(?:[\w.+-]+\+)?json\b/i
Expand Down Expand Up @@ -45,10 +46,7 @@ const BINARY_SNIFF_BYTES = 4096
const HTTP_ERROR_EXIT_CODE = 22

export default defineCommand({
meta: {
name: 'curl',
description: 'Send an HTTP request to your running Nuxt dev server',
},
meta: commandMeta.curl,
args: {
// `url` has to precede the `dir` positional supplied by `rootDirArgs`
url: {
Expand Down
7 changes: 2 additions & 5 deletions packages/nuxt-cli/src/commands/dev-child.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@ import { defineCommand } from 'citty'
import { resolveRootDir } from '../utils/paths'

import { dotEnvArgs, envNameArgs, logLevelArgs, rootDirArgs } from './_shared'
import { commandMeta } from './meta'

export default defineCommand({
meta: {
name: '_dev',
description: 'Run Nuxt development server (internal command to start child process)',
hidden: true,
},
meta: commandMeta._dev,
args: {
...rootDirArgs,
...logLevelArgs,
Expand Down
6 changes: 2 additions & 4 deletions packages/nuxt-cli/src/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,14 @@ import { debug, logger } from '../utils/logger'
import { resolveRootDir } from '../utils/paths'
import { startupElapsedMs } from '../utils/startup-clock'
import { dotEnvArgs, envNameArgs, extendsArgs, logLevelArgs, profileArgs, rootDirArgs } from './_shared'
import { commandMeta } from './meta'

const startTime: number | undefined = Date.now()

const forkSupported = !isTest && (!isBun || isBunForkSupported())

const command = defineCommand({
meta: {
name: 'dev',
description: 'Run Nuxt development server',
},
meta: commandMeta.dev,
args: {
...rootDirArgs,
...logLevelArgs,
Expand Down
6 changes: 2 additions & 4 deletions packages/nuxt-cli/src/commands/devtools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ import { x } from 'tinyexec'
import { ActionableError } from '../utils/errors'
import { resolveRootDir } from '../utils/paths'
import { rootDirArgs } from './_shared'
import { commandMeta } from './meta'

export default defineCommand({
meta: {
name: 'devtools',
description: 'Enable or disable devtools in a Nuxt project',
},
meta: commandMeta.devtools,
args: {
command: {
type: 'positional',
Expand Down
6 changes: 2 additions & 4 deletions packages/nuxt-cli/src/commands/docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@ import { resolveRootDir } from '../utils/paths'
import { withSpinner } from '../utils/spinner'
import { isInteractive } from '../utils/stdout'
import { cwdArgs } from './_shared'
import { commandMeta } from './meta'

const MAX_RESULTS = 8

export default defineCommand({
meta: {
name: 'docs',
description: 'Search or open the Nuxt documentation',
},
meta: commandMeta.docs,
args: {
query: {
type: 'positional',
Expand Down
6 changes: 2 additions & 4 deletions packages/nuxt-cli/src/commands/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ import { defineCommand } from 'citty'

import { dotEnvArgs, envNameArgs, extendsArgs, logLevelArgs, profileArgs, rootDirArgs, targetArgs } from './_shared'
import buildCommand from './build'
import { commandMeta } from './meta'

export default defineCommand({
meta: {
name: 'generate',
description: 'Build Nuxt and prerender all routes',
},
meta: commandMeta.generate,
args: {
...rootDirArgs,
...logLevelArgs,
Expand Down
6 changes: 2 additions & 4 deletions packages/nuxt-cli/src/commands/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { detectPackageManager, getPackageManagerVersion } from '../utils/package
import { resolveRootDir } from '../utils/paths'
import { tryResolveNuxt } from '../utils/resolve-nuxt'
import { rootDirArgs } from './_shared'
import { commandMeta } from './meta'

const LEADING_SLASH_RE = /^\//

Expand All @@ -44,10 +45,7 @@ const JSON_KEYS: Record<string, string> = {
}

export default defineCommand({
meta: {
name: 'info',
description: 'Get information about Nuxt project',
},
meta: commandMeta.info,
args: {
...rootDirArgs,
json: {
Expand Down
7 changes: 2 additions & 5 deletions packages/nuxt-cli/src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@ import { defineCommand } from 'citty'

import { getCreateCommand } from '../utils/headless'
import { logger } from '../utils/logger'
import { commandMeta } from './meta'

export default defineCommand({
meta: {
name: 'init',
description: 'Scaffold a fresh project (moved to create-nuxt)',
hidden: true,
},
meta: commandMeta.init,
run(ctx) {
const command = [getCreateCommand(), ...ctx.rawArgs].join(' ')
logger.info(`Project scaffolding now lives in ${styleText('cyan', 'create-nuxt')}.`)
Expand Down
93 changes: 93 additions & 0 deletions packages/nuxt-cli/src/commands/meta.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import type { CommandMeta } from 'citty'

import type { commands } from '.'

export const commandMeta = {
'add': {
name: 'add',
description: 'Add Nuxt modules and layers',
},
'add-template': {
name: 'add-template',
description: 'Create a new template file.',
},
'analyze': {
name: 'analyze',
description: 'Build Nuxt and analyze production bundle (experimental)',
},
'build': {
name: 'build',
description: 'Build Nuxt for production deployment',
},
'cleanup': {
name: 'cleanup',
description: 'Clean up generated Nuxt files and caches',
},
'curl': {
name: 'curl',
description: 'Send an HTTP request to your running Nuxt dev server',
},
'_dev': {
name: '_dev',
description: 'Run Nuxt development server (internal command to start child process)',
hidden: true,
},
'dev': {
name: 'dev',
description: 'Run Nuxt development server',
},
'devtools': {
name: 'devtools',
description: 'Enable or disable devtools in a Nuxt project',
},
'docs': {
name: 'docs',
description: 'Search or open the Nuxt documentation',
},
'generate': {
name: 'generate',
description: 'Build Nuxt and prerender all routes',
},
'info': {
name: 'info',
description: 'Get information about Nuxt project',
},
'init': {
name: 'init',
description: 'Scaffold a fresh project (moved to create-nuxt)',
hidden: true,
},
'module': {
name: 'module',
description: 'Manage Nuxt modules',
},
'prepare': {
name: 'prepare',
description: 'Prepare Nuxt for development/build',
},
'preview': {
name: 'preview',
description: 'Launches Nitro server for local testing after `nuxt build`.',
},
'start': {
name: 'start',
description: 'Launches Nitro server for local testing after `nuxt build`.',
hidden: true,
},
'task': {
name: 'task',
description: 'List and run Nitro tasks on your dev server',
},
'test': {
name: 'test',
description: 'Run tests',
},
'typecheck': {
name: 'typecheck',
description: 'Runs type-checking throughout your app using `vue-tsc` or Golar.',
},
'upgrade': {
name: 'upgrade',
description: 'Upgrade Nuxt',
},
} as const satisfies Record<keyof typeof commands, CommandMeta>
3 changes: 2 additions & 1 deletion packages/nuxt-cli/src/commands/module/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { defaultPackageManager, detectPackageManager, isPackageManagerName, pack
import { createSpinner } from '../../utils/spinner'
import { getNuxtVersion } from '../../utils/versions'
import { cwdArgs, logLevelArgs } from '../_shared'
import { commandMeta } from '../meta'
import prepareCommand from '../prepare'
import { selectModulesAutocomplete } from './_autocomplete'
import { basePackageName, checkNuxtCompatibility, ensureNuxtDependency, fetchModules, forwardCommandArgs, getProjectDependencies, MODULES_API_URL, parseModuleSpec, resolveModuleEntry } from './_utils'
Expand All @@ -47,7 +48,7 @@ export function defineAddCommand({ layers = false }: { layers?: boolean } = {})
return defineCommand({
meta: {
name: 'add',
description: layers ? 'Add Nuxt modules and layers' : 'Add Nuxt modules',
description: layers ? commandMeta.add.description : 'Add Nuxt modules',
},
args: {
...cwdArgs,
Expand Down
6 changes: 2 additions & 4 deletions packages/nuxt-cli/src/commands/module/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { defineCommand } from 'citty'
import { commandMeta } from '../meta'

export default defineCommand({
meta: {
name: 'module',
description: 'Manage Nuxt modules',
},
meta: commandMeta.module,
args: {},
subCommands: {
add: () => import('./add').then(r => r.default || r),
Expand Down
6 changes: 2 additions & 4 deletions packages/nuxt-cli/src/commands/prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ import { readActiveLock } from '../utils/lockfile'
import { logger } from '../utils/logger'
import { relativeToProcess, resolveRootDir } from '../utils/paths'
import { dotEnvArgs, envNameArgs, extendsArgs, logLevelArgs, rootDirArgs } from './_shared'
import { commandMeta } from './meta'

export default defineCommand({
meta: {
name: 'prepare',
description: 'Prepare Nuxt for development/build',
},
meta: commandMeta.prepare,
args: {
...rootDirArgs,
...dotEnvArgs,
Expand Down
6 changes: 2 additions & 4 deletions packages/nuxt-cli/src/commands/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ import { relativeToProcess, resolveRootDir } from '../utils/paths'
import { resolveServerBuild } from '../utils/server-build'
import { findStaticEntry, formatServerURL, previewStaticOutput } from '../utils/static-preview'
import { dotEnvArgs, envNameArgs, extendsArgs, logLevelArgs, rootDirArgs } from './_shared'
import { commandMeta } from './meta'

const command = defineCommand({
meta: {
name: 'preview',
description: 'Launches Nitro server for local testing after `nuxt build`.',
},
meta: commandMeta.preview,
args: {
...rootDirArgs,
...logLevelArgs,
Expand Down
7 changes: 2 additions & 5 deletions packages/nuxt-cli/src/commands/start.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { defineCommand } from 'citty'

import { commandMeta } from './meta'
import preview from './preview'

export default defineCommand({
...preview,
meta: {
name: 'start',
description: 'Launches Nitro server for local testing after `nuxt build`.',
hidden: true,
},
meta: commandMeta.start,
})
6 changes: 2 additions & 4 deletions packages/nuxt-cli/src/commands/task/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { defineCommand } from 'citty'
import { commandMeta } from '../meta'

export default defineCommand({
meta: {
name: 'task',
description: 'List and run Nitro tasks on your dev server',
},
meta: commandMeta.task,
args: {},
subCommands: {
list: () => import('./list').then(r => r.default || r),
Expand Down
Loading
Loading