Skip to content

Commit dbff6b1

Browse files
authored
fix: update command defaults and descriptions (#677)
1 parent 42ddc2c commit dbff6b1

File tree

3 files changed

+34
-23
lines changed

3 files changed

+34
-23
lines changed

src/commands/_shared.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import type { ArgDef } from 'citty'
2+
import { resolve } from 'pathe'
3+
4+
export const sharedArgs = {
5+
// cwd falls back to rootDir's default (indirect default)
6+
cwd: {
7+
type: 'string',
8+
valueHint: 'directory',
9+
description: 'Specify the working directory, this takes precedence over ROOTDIR (default: `.`)',
10+
default: undefined,
11+
},
12+
rootDir: {
13+
type: 'positional',
14+
description: 'Specifies the working directory (default: `.`)',
15+
required: false,
16+
default: '.',
17+
},
18+
} as const satisfies Record<string, ArgDef>
19+
20+
export const resolveCwdArg = (args: { cwd?: string, rootDir?: string }) => resolve(args.cwd || args.rootDir || '.')

src/commands/build.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,51 +16,49 @@ import { defineCommand } from 'citty'
1616
import { convertCompilerOptionsFromJson } from 'typescript'
1717

1818
import { name, version } from '../../package.json'
19+
import { resolveCwdArg, sharedArgs } from './_shared'
1920

2021
export default defineCommand({
2122
meta: {
2223
name: 'build',
2324
description: 'Build module for distribution',
2425
},
2526
args: {
26-
cwd: {
27-
type: 'string',
28-
description: 'Current working directory',
29-
},
30-
rootDir: {
31-
type: 'positional',
32-
description: 'Root directory',
33-
required: false,
34-
},
27+
...sharedArgs,
3528
outDir: {
3629
type: 'string',
30+
default: 'dist',
31+
description: 'Build directory',
3732
},
3833
sourcemap: {
3934
type: 'boolean',
35+
default: false,
36+
description: 'Generate sourcemaps',
4037
},
4138
stub: {
4239
type: 'boolean',
40+
default: false,
41+
description: 'Stub dist instead of actually building it for development',
4342
},
4443
},
4544
async run(context) {
4645
const { build } = await import('unbuild')
4746

48-
const cwd = resolve(context.args.cwd || context.args.rootDir || '.')
47+
const cwd = resolveCwdArg(context.args)
4948

5049
const jiti = createJiti(cwd)
51-
const outDir = context.args.outDir || 'dist'
5250

5351
await build(cwd, false, {
5452
declaration: 'node16',
5553
sourcemap: context.args.sourcemap,
5654
stub: context.args.stub,
5755
stubOptions: { absoluteJitiPath: true },
58-
outDir,
56+
outDir: context.args.outDir,
5957
entries: [
6058
'src/module',
6159
{
6260
input: 'src/runtime/',
63-
outDir: `${outDir}/runtime`,
61+
outDir: `${context.args.outDir}/runtime`,
6462
addRelativeDeclarationExtensions: true,
6563
ext: 'js',
6664
pattern: [

src/commands/prepare.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,20 @@
11
import type { NuxtConfig } from '@nuxt/schema'
22
import { defineCommand } from 'citty'
33
import { resolve } from 'pathe'
4+
import { resolveCwdArg, sharedArgs } from './_shared'
45

56
export default defineCommand({
67
meta: {
78
name: 'prepare',
89
description: 'Prepare @nuxt/module-builder environment by writing types and stubs',
910
},
1011
args: {
11-
cwd: {
12-
type: 'string',
13-
description: 'Current working directory',
14-
},
15-
rootDir: {
16-
type: 'positional',
17-
description: 'Root directory',
18-
required: false,
19-
},
12+
...sharedArgs,
2013
},
2114
async run(context) {
2215
const { runCommand } = await import('@nuxt/cli')
2316

24-
const cwd = resolve(context.args.cwd || context.args.rootDir || '.')
17+
const cwd = resolveCwdArg(context.args)
2518

2619
return runCommand('prepare', [cwd], {
2720
overrides: {

0 commit comments

Comments
 (0)