Skip to content

Commit ebece5e

Browse files
authored
feat(rstack): add help for Rslib commands (#317)
1 parent 823abe5 commit ebece5e

3 files changed

Lines changed: 172 additions & 0 deletions

File tree

packages/rstack/src/cli/commands.ts

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,84 @@ const renderPreviewHelp = (): string =>
110110
],
111111
});
112112

113+
const renderLibHelp = (): string =>
114+
renderHelp({
115+
usage: 'rs lib [command] [options]',
116+
sections: [
117+
{
118+
title: 'Commands',
119+
items: [
120+
['build', 'Build the library for production (default)'],
121+
['inspect', 'Inspect Rslib, Rsbuild, and Rspack configs'],
122+
['mf-dev', 'Start Rsbuild dev server for Module Federation'],
123+
],
124+
},
125+
{
126+
content: `For command-specific options, run:
127+
$ rs lib <command> -h`,
128+
dim: true,
129+
},
130+
{
131+
title: 'Options',
132+
items: [
133+
['-w, --watch', 'Enable watch mode and rebuild on changes'],
134+
['--dts', 'Emit declaration files (use --no-dts to disable)'],
135+
['-c, --config <path>', 'Specify Rstack config file path'],
136+
['-h, --help', 'Display this help message'],
137+
],
138+
},
139+
],
140+
});
141+
142+
const renderLibBuildHelp = (): string =>
143+
renderHelp({
144+
usage: 'rs lib build [options]',
145+
description: 'Build the library for production',
146+
sections: [
147+
{
148+
title: 'Options',
149+
items: [
150+
['-w, --watch', 'Enable watch mode and rebuild on changes'],
151+
['--dts', 'Emit declaration files (use --no-dts to disable)'],
152+
['-c, --config <path>', 'Specify Rstack config file path'],
153+
['-h, --help', 'Display this help message'],
154+
],
155+
},
156+
],
157+
});
158+
159+
const renderLibInspectHelp = (): string =>
160+
renderHelp({
161+
usage: 'rs lib inspect [options]',
162+
description: 'Inspect Rslib, Rsbuild, and Rspack configs',
163+
sections: [
164+
{
165+
title: 'Options',
166+
items: [
167+
['--output <path>', 'Set the output path for inspection results (default: .rsbuild)'],
168+
['--verbose', 'Show complete function definitions in output'],
169+
['-c, --config <path>', 'Specify Rstack config file path'],
170+
['-h, --help', 'Display this help message'],
171+
],
172+
},
173+
],
174+
});
175+
176+
const renderLibMfDevHelp = (): string =>
177+
renderHelp({
178+
usage: 'rs lib mf-dev [options]',
179+
description: 'Start Rsbuild dev server for Module Federation',
180+
sections: [
181+
{
182+
title: 'Options',
183+
items: [
184+
['-c, --config <path>', 'Specify Rstack config file path'],
185+
['-h, --help', 'Display this help message'],
186+
],
187+
},
188+
],
189+
});
190+
113191
async function runRsbuildCLI(args: string[]): Promise<void> {
114192
if (hasHelpFlag(args)) {
115193
switch (args[0]) {
@@ -147,6 +225,23 @@ async function runRstestCLI(args: string[]): Promise<void> {
147225
}
148226

149227
async function runRslibCLI(args: string[]): Promise<void> {
228+
if (hasHelpFlag(args)) {
229+
switch (args[0]) {
230+
case 'build':
231+
console.log(renderLibBuildHelp());
232+
return;
233+
case 'inspect':
234+
console.log(renderLibInspectHelp());
235+
return;
236+
case 'mf-dev':
237+
console.log(renderLibMfDevHelp());
238+
return;
239+
default:
240+
console.log(renderLibHelp());
241+
return;
242+
}
243+
}
244+
150245
const argv = [
151246
process.execPath,
152247
'rslib',

packages/rstack/tests/cli/__snapshots__/help.test.ts.snap

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,74 @@ Options:
3535
"
3636
`;
3737
38+
exports[`displays lib build help 1`] = `
39+
"Rstack v<version>
40+
41+
Usage:
42+
$ rs lib build [options]
43+
44+
Build the library for production
45+
46+
Options:
47+
-w, --watch Enable watch mode and rebuild on changes
48+
--dts Emit declaration files (use --no-dts to disable)
49+
-c, --config <path> Specify Rstack config file path
50+
-h, --help Display this help message
51+
"
52+
`;
53+
54+
exports[`displays lib help 1`] = `
55+
"Rstack v<version>
56+
57+
Usage:
58+
$ rs lib [command] [options]
59+
60+
Commands:
61+
build Build the library for production (default)
62+
inspect Inspect Rslib, Rsbuild, and Rspack configs
63+
mf-dev Start Rsbuild dev server for Module Federation
64+
65+
For command-specific options, run:
66+
$ rs lib <command> -h
67+
68+
Options:
69+
-w, --watch Enable watch mode and rebuild on changes
70+
--dts Emit declaration files (use --no-dts to disable)
71+
-c, --config <path> Specify Rstack config file path
72+
-h, --help Display this help message
73+
"
74+
`;
75+
76+
exports[`displays lib inspect help 1`] = `
77+
"Rstack v<version>
78+
79+
Usage:
80+
$ rs lib inspect [options]
81+
82+
Inspect Rslib, Rsbuild, and Rspack configs
83+
84+
Options:
85+
--output <path> Set the output path for inspection results (default: .rsbuild)
86+
--verbose Show complete function definitions in output
87+
-c, --config <path> Specify Rstack config file path
88+
-h, --help Display this help message
89+
"
90+
`;
91+
92+
exports[`displays lib mf-dev help 1`] = `
93+
"Rstack v<version>
94+
95+
Usage:
96+
$ rs lib mf-dev [options]
97+
98+
Start Rsbuild dev server for Module Federation
99+
100+
Options:
101+
-c, --config <path> Specify Rstack config file path
102+
-h, --help Display this help message
103+
"
104+
`;
105+
38106
exports[`displays preview help 1`] = `
39107
"Rstack v<version>
40108

packages/rstack/tests/cli/help.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,12 @@ for (const command of ['dev', 'build', 'preview']) {
2020
expect(normalizeHelpOutput(output)).toMatchSnapshot();
2121
});
2222
}
23+
24+
for (const command of ['lib', 'lib build', 'lib inspect', 'lib mf-dev']) {
25+
test(`displays ${command} help`, ({ execCli, expect }) => {
26+
const output = execCli(`${command} --help`);
27+
28+
expect(execCli(`${command} -h`)).toBe(output);
29+
expect(normalizeHelpOutput(output)).toMatchSnapshot();
30+
});
31+
}

0 commit comments

Comments
 (0)