forked from rstackjs/rstack-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommandHelp.ts
More file actions
477 lines (457 loc) · 14 KB
/
Copy pathcommandHelp.ts
File metadata and controls
477 lines (457 loc) · 14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
import { color } from 'rslog';
declare global {
const RSTACK_VERSION: string;
}
type HelpItem = readonly [label: string, description: string];
type HelpSection =
| {
title: string;
items: readonly HelpItem[];
}
| {
content: string;
dim?: boolean;
};
type HelpDefinition = {
usage: string;
description?: string;
sections?: readonly HelpSection[];
};
export type HelpTopic =
| 'root'
| 'check'
| 'dev'
| 'build'
| 'preview'
| 'doc'
| 'doc build'
| 'doc preview'
| 'doc eject'
| 'test'
| 'test run'
| 'test watch'
| 'test list'
| 'test merge-reports'
| 'test init'
| 'lib'
| 'lib build'
| 'lib inspect'
| 'lib mf-dev'
| 'lint'
| 'fmt'
| 'staged'
| 'setup';
const CONFIG_OPTION: HelpItem = ['-c, --config <path>', 'Specify Rstack config file path'];
const HELP_OPTION: HelpItem = ['-h, --help', 'Display this help message'];
const VERSION_OPTION: HelpItem = ['-v, --version', 'Display version number'];
const CONFIG_HELP_OPTIONS = [CONFIG_OPTION, HELP_OPTION];
const OPEN_OPTION: HelpItem = ['-o, --open [url]', 'Open the page in browser on startup'];
const PORT_OPTION: HelpItem = ['--port <port>', 'Set the port number for the server'];
const STRICT_PORT_OPTION: HelpItem = [
'--strict-port',
'Exit if the specified port is already in use',
];
const HOST_OPTION: HelpItem = ['--host [host]', 'Set the host that the server listens to'];
const BASE_OPTION: HelpItem = ['--base <base>', 'Set the base path and override config.base'];
const SERVER_OPTIONS = [OPEN_OPTION, PORT_OPTION, STRICT_PORT_OPTION, HOST_OPTION];
const TEST_UPDATE_OPTION: HelpItem = ['-u, --update', 'Update snapshot files'];
const TEST_COVERAGE_OPTION: HelpItem = ['--coverage', 'Enable code coverage'];
const TEST_PROJECT_OPTION: HelpItem = ['--project <name>', 'Filter test projects by name'];
const TEST_NAME_OPTION: HelpItem = [
'-t, --test-name-pattern <pattern>',
'Run tests with names matching the pattern',
];
const TEST_OPTIONS = [
TEST_UPDATE_OPTION,
TEST_COVERAGE_OPTION,
TEST_PROJECT_OPTION,
TEST_NAME_OPTION,
];
const LIB_WATCH_OPTION: HelpItem = ['-w, --watch', 'Enable watch mode and rebuild on changes'];
const LIB_DTS_OPTION: HelpItem = ['--dts', 'Emit declaration files (use --no-dts to disable)'];
const LIB_BUILD_OPTIONS = [LIB_WATCH_OPTION, LIB_DTS_OPTION];
const commandHint = (command: string): HelpSection => ({
content: `For command-specific options, run:
$ rs ${command} <command> -h`,
dim: true,
});
const HELP_DEFINITIONS = {
root: {
usage: 'rs [command] [options]',
sections: [
{
title: 'Commands',
items: [
['dev', 'Run the app dev server'],
['build', 'Build the app for production'],
['preview', 'Preview the app production build'],
['lib', 'Build library'],
['doc', 'Serve or build docs'],
['fmt, format', 'Format code'],
['lint', 'Lint code'],
['check', 'Run static checks, including lint and format'],
['test', 'Run tests'],
['staged', 'Run tasks on staged Git files'],
['setup', 'Install Git hooks'],
],
},
{
content: `For command-specific options, run:
$ rs <command> -h`,
dim: true,
},
{
title: 'Options',
items: [CONFIG_OPTION, HELP_OPTION, VERSION_OPTION],
},
],
},
check: {
usage: 'rs check [options]',
description: 'Run static checks, including lint and format',
sections: [
{
title: 'Options',
items: [['--type-check', 'Enable TypeScript type checking'], ...CONFIG_HELP_OPTIONS],
},
],
},
dev: {
usage: 'rs dev [options]',
description: 'Run the app dev server',
sections: [
{
title: 'Options',
items: [...SERVER_OPTIONS, ...CONFIG_HELP_OPTIONS],
},
],
},
build: {
usage: 'rs build [options]',
description: 'Build the app for production',
sections: [
{
title: 'Options',
items: [
['-w, --watch', 'Enable watch mode to automatically rebuild on file changes'],
['--dist-path <dir>', 'Set the root directory of output files'],
['--source-map', 'Enable source map'],
...CONFIG_HELP_OPTIONS,
],
},
],
},
preview: {
usage: 'rs preview [options]',
description: 'Preview the app production build',
sections: [
{
title: 'Options',
items: [...SERVER_OPTIONS, ...CONFIG_HELP_OPTIONS],
},
],
},
doc: {
usage: 'rs doc [command] [root] [options]',
sections: [
{
title: 'Commands',
items: [
['[root]', 'Run the docs dev server (default)'],
['build [root]', 'Build docs for production'],
['preview [root]', 'Preview the docs production build'],
['eject [component]', 'Eject a theme component'],
],
},
commandHint('doc'),
{
title: 'Options',
items: [PORT_OPTION, HOST_OPTION, BASE_OPTION, ...CONFIG_HELP_OPTIONS],
},
],
},
'doc build': {
usage: 'rs doc build [root] [options]',
description: 'Build docs for production',
sections: [
{
title: 'Options',
items: [BASE_OPTION, ...CONFIG_HELP_OPTIONS],
},
],
},
'doc preview': {
usage: 'rs doc preview [root] [options]',
description: 'Preview the docs production build',
sections: [
{
title: 'Options',
items: [PORT_OPTION, HOST_OPTION, BASE_OPTION, ...CONFIG_HELP_OPTIONS],
},
],
},
'doc eject': {
usage: 'rs doc eject [component] [options]',
description: 'Eject a theme component',
sections: [
{
title: 'Options',
items: [HELP_OPTION],
},
],
},
test: {
usage: 'rs test [command] [...filters] [options]',
sections: [
{
title: 'Commands',
items: [
['[...filters]', 'Run tests (default)'],
['run [...filters]', 'Run tests once'],
['watch [...filters]', 'Run tests in watch mode'],
['list [...filters]', 'List matching tests'],
['merge-reports [path]', 'Merge blob reports'],
['init [project]', 'Initialize Rstest configuration'],
],
},
commandHint('test'),
{
title: 'Options',
items: [['-w, --watch', 'Enable watch mode'], ...TEST_OPTIONS, ...CONFIG_HELP_OPTIONS],
},
],
},
'test run': {
usage: 'rs test run [...filters] [options]',
description: 'Run tests once',
sections: [
{
title: 'Options',
items: [
['--related', 'Run tests related to source files'],
['--changed [commit]', 'Run tests related to changed files'],
['--shard <index/count>', 'Split tests into shards'],
...TEST_OPTIONS,
...CONFIG_HELP_OPTIONS,
],
},
],
},
'test watch': {
usage: 'rs test watch [...filters] [options]',
description: 'Run tests in watch mode',
sections: [
{
title: 'Options',
items: [...TEST_OPTIONS, ...CONFIG_HELP_OPTIONS],
},
],
},
'test list': {
usage: 'rs test list [...filters] [options]',
description: 'List matching tests',
sections: [
{
title: 'Options',
items: [
['--related', 'List tests related to source files'],
['--changed [commit]', 'List tests related to changed files'],
['--files-only', 'List matching test files only'],
['--json [path]', 'Print JSON or write it to a file'],
['--include-suites', 'Include test suites'],
['--print-location', 'Print test locations'],
['--summary', 'Print a summary'],
TEST_PROJECT_OPTION,
['-t, --test-name-pattern <pattern>', 'List tests with names matching the pattern'],
...CONFIG_HELP_OPTIONS,
],
},
],
},
'test merge-reports': {
usage: 'rs test merge-reports [path] [options]',
description: 'Merge blob reports',
sections: [
{
title: 'Options',
items: [
['--coverage', 'Generate coverage reports'],
['--reporters, --reporter <name>', 'Specify test reporters'],
['--cleanup', 'Remove blob reports after merging'],
...CONFIG_HELP_OPTIONS,
],
},
],
},
'test init': {
usage: 'rs test init [project] [options]',
description: 'Initialize Rstest configuration',
sections: [
{
title: 'Options',
items: [['--yes', 'Use default options without prompts'], HELP_OPTION],
},
],
},
lib: {
usage: 'rs lib [command] [options]',
sections: [
{
title: 'Commands',
items: [
['build', 'Build the library for production (default)'],
['inspect', 'Inspect Rslib, Rsbuild, and Rspack configs'],
['mf-dev', 'Start Rsbuild dev server for Module Federation'],
],
},
commandHint('lib'),
{
title: 'Options',
items: [...LIB_BUILD_OPTIONS, ...CONFIG_HELP_OPTIONS],
},
],
},
'lib build': {
usage: 'rs lib build [options]',
description: 'Build the library for production',
sections: [
{
title: 'Options',
items: [...LIB_BUILD_OPTIONS, ...CONFIG_HELP_OPTIONS],
},
],
},
'lib inspect': {
usage: 'rs lib inspect [options]',
description: 'Inspect Rslib, Rsbuild, and Rspack configs',
sections: [
{
title: 'Options',
items: [
['--output <path>', 'Set the output path for inspection results (default: .rsbuild)'],
['--verbose', 'Show complete function definitions in output'],
...CONFIG_HELP_OPTIONS,
],
},
],
},
'lib mf-dev': {
usage: 'rs lib mf-dev [options]',
description: 'Start Rsbuild dev server for Module Federation',
sections: [
{
title: 'Options',
items: [...CONFIG_HELP_OPTIONS],
},
],
},
lint: {
usage: 'rs lint [options] [files...]',
description: 'Lint code',
sections: [
{
title: 'Options',
items: [
['--fix', 'Automatically fix problems'],
['--type-check', 'Enable TypeScript type checking'],
['--type-check-only', 'Run only TypeScript type checking'],
['--format <format>', 'Set output format (default | jsonline | github | gitlab)'],
['--quiet', 'Report errors only'],
['--timing [all|N]', 'Print a per-rule timing table (all rules or top N)'],
['--max-warnings <count>', 'Set the maximum number of warnings'],
['--rule <rule>', 'Override a rule (repeatable)'],
['--no-color', 'Disable colored output'],
['--force-color', 'Force colored output'],
...CONFIG_HELP_OPTIONS,
],
},
],
},
fmt: {
usage: 'rs fmt [options] [files/globs...]',
description: 'Format code',
sections: [
{
title: 'Options',
items: [
['-w, --write', 'Write formatted files in place (default)'],
['--check', 'Check whether files are formatted'],
['-l, --list-different', 'Print paths of unformatted files'],
['--ignore-path <path>', 'Path to an additional ignore file (repeatable)'],
['-u, --ignore-unknown', 'Ignore unknown files'],
['--no-cache', 'Disable the formatting cache'],
['--cache-location <path>', 'Path to the formatting cache directory'],
['--no-error-on-unmatched-pattern', 'Do not error when no files match'],
['--with-node-modules', 'Process files inside node_modules'],
['--parallel-workers <count>', 'Number of parallel workers'],
['--stdin-filepath <path>', 'Format stdin as if it were saved at <path>'],
['--lsp', 'Run a language server on stdio'],
...CONFIG_HELP_OPTIONS,
],
},
],
},
staged: {
usage: 'rs staged [options]',
description: 'Run tasks on staged Git files',
sections: [
{
title: 'Options',
items: [
['--allow-empty', 'Allow empty commits when tasks revert all staged changes'],
[
'-p, --concurrent <number|boolean>',
'The number of tasks to run concurrently, or false for serial',
],
['--cwd <path>', 'Working directory to run all tasks in'],
['-d, --debug', 'Print additional debug information'],
['--no-stash', 'Disable backup stash and automatic revert'],
['-q, --quiet', "Disable lint-staged's own console output"],
['-r, --relative', 'Pass relative filepaths to tasks'],
[
'-v, --verbose',
'Show task output even when tasks succeed; by default only failed output is shown',
],
...CONFIG_HELP_OPTIONS,
],
},
],
},
setup: {
usage: 'rs setup [options]',
description: 'Install Git hooks in the current repository',
sections: [
{
title: 'Options',
items: [
['--hooks-dir <path>', 'Specify hooks directory relative to the Git repository root'],
HELP_OPTION,
],
},
],
},
} satisfies Record<HelpTopic, HelpDefinition>;
const renderItems = (items: readonly HelpItem[]): string => {
const labelWidth = items.reduce((width, [label]) => Math.max(width, label.length), 0);
return items
.map(([label, description]) => ` ${label.padEnd(labelWidth)} ${description}`)
.join('\n');
};
const renderSection = (section: HelpSection): string => {
if ('items' in section) {
return `${color.cyan(section.title)}:\n${renderItems(section.items)}`;
}
return section.dim ? color.dim(section.content) : section.content;
};
const renderHelp = ({ usage, description, sections = [] }: HelpDefinition): string => {
const blocks = [
color.bold(`Rstack v${RSTACK_VERSION}`),
`${color.cyan('Usage')}:\n${color.yellow(` $ ${usage}`)}`,
];
if (description) {
blocks.push(description);
}
blocks.push(...sections.map(renderSection));
return blocks.join('\n\n');
};
export const renderCommandHelp = (topic: HelpTopic): string => renderHelp(HELP_DEFINITIONS[topic]);