Skip to content

Commit e6a804e

Browse files
authored
chore: modify inspect cli commands and add cli commands docs (#348)
1 parent 6432229 commit e6a804e

File tree

4 files changed

+130
-15
lines changed

4 files changed

+130
-15
lines changed

packages/core/src/cli/commands.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,12 @@ export function runCli(): void {
5757
});
5858

5959
inspectCommand
60-
.description('inspect the Rslib / Rsbuild / Rspack configs')
61-
.option('--env <env>', 'specify env mode', 'development')
62-
.option('--output <output>', 'specify inspect content output path', './')
60+
.description('inspect the Rsbuild / Rspack configs of Rslib projects')
61+
.option(
62+
'--output <output>',
63+
'specify inspect content output path',
64+
'.rsbuild',
65+
)
6366
.option('--verbose', 'show full function definitions in output')
6467
.action(async (options: InspectOptions) => {
6568
try {

tests/integration/cli/index.test.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,29 @@ test('inspect command', async () => {
1212
cwd: __dirname,
1313
});
1414

15-
const files = await globContentJSON(path.join(__dirname, 'dist'));
16-
const fileNames = Object.keys(files);
15+
const files = await globContentJSON(path.join(__dirname, 'dist/.rsbuild'));
16+
const fileNames = Object.keys(files).sort();
1717

18-
const rsbuildConfig = fileNames.find((item) =>
19-
item.includes('rsbuild.config.mjs'),
20-
);
18+
expect(fileNames).toMatchInlineSnapshot(`
19+
[
20+
"<ROOT>/tests/integration/cli/dist/.rsbuild/rsbuild.config.cjs.mjs",
21+
"<ROOT>/tests/integration/cli/dist/.rsbuild/rsbuild.config.esm.mjs",
22+
"<ROOT>/tests/integration/cli/dist/.rsbuild/rspack.config.cjs.mjs",
23+
"<ROOT>/tests/integration/cli/dist/.rsbuild/rspack.config.esm.mjs",
24+
]
25+
`);
2126

22-
expect(rsbuildConfig).toBeTruthy();
23-
expect(files[rsbuildConfig!]).toContain("type: 'modern-module'");
27+
// esm rsbuild config
28+
const rsbuildConfigEsm = fileNames.find((item) =>
29+
item.includes('rsbuild.config.esm.mjs'),
30+
);
31+
expect(rsbuildConfigEsm).toBeTruthy();
32+
expect(files[rsbuildConfigEsm!]).toContain("type: 'modern-module'");
2433

25-
const rspackConfig = fileNames.find((item) =>
34+
// esm rspack config
35+
const rspackConfigEsm = fileNames.find((item) =>
2636
item.includes('rspack.config.esm.mjs'),
2737
);
28-
expect(rspackConfig).toBeTruthy();
29-
expect(files[rspackConfig!]).toContain("type: 'modern-module'");
38+
expect(rspackConfigEsm).toBeTruthy();
39+
expect(files[rspackConfigEsm!]).toContain("type: 'modern-module'");
3040
});
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { defineConfig } from '@rslib/core';
2-
import { generateBundleEsmConfig } from 'test-helper';
2+
import { generateBundleCjsConfig, generateBundleEsmConfig } from 'test-helper';
33

44
export default defineConfig({
5-
lib: [generateBundleEsmConfig()],
5+
lib: [generateBundleEsmConfig(), generateBundleCjsConfig()],
66
});
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,103 @@
11
# CLI
2+
3+
Rslib comes with a lightweight CLI that includes commands such as build and inspect.
4+
5+
## rslib -h
6+
7+
To view all available CLI commands, run the following command in the project directory:
8+
9+
```bash
10+
npx rslib -h
11+
```
12+
13+
The output is shown below:
14+
15+
```text
16+
Usage: rslib <command> [options]
17+
18+
Options:
19+
-V, --version output the version number
20+
-h, --help display help for command
21+
22+
Commands:
23+
build [options] build the library for production
24+
inspect [options] inspect the Rsbuild / Rspack configs of Rslib projects
25+
help [command] display help for command
26+
```
27+
28+
## rslib build
29+
30+
The `rslib build` command will build the outputs for production in the `dist/` directory by default.
31+
32+
```text
33+
Usage: rslib build [options]
34+
35+
build the library for production
36+
37+
Options:
38+
-c --config <config> specify the configuration file, can be a relative or absolute path
39+
--env-mode <mode> specify the env mode to load the `.env.[mode]` file
40+
-w --watch turn on watch mode, watch for changes and rebuild
41+
-h, --help display help for command
42+
```
43+
44+
:::tip
45+
46+
You can use `rslib build --watch` to turn on watch mode for watching for changes and rebuild.
47+
:::
48+
49+
## rslib inspect
50+
51+
The `rslib inspect` command is used to view the Rsbuild config and Rspack config of the Rslib project.
52+
53+
```text
54+
Usage: rslib inspect [options]
55+
56+
inspect the Rsbuild / Rspack configs of Rslib projects
57+
58+
Options:
59+
-c --config <config> specify the configuration file, can be a relative or absolute path
60+
--env-mode <mode> specify the env mode to load the `.env.[mode]` file
61+
--output <output> specify inspect content output path (default: ".rsbuild")
62+
--verbose show full function definitions in output
63+
-h, --help display help for command
64+
```
65+
66+
When you run the command `npx rslib inspect` in the project root directory, the following files will be generated in the `dist/.rsbuild` directory of the project:
67+
68+
- `rsbuild.config.mjs`: Represents the Rsbuild configuration used during the build.
69+
- `rspack.config.web.mjs`: Represents the Rspack configuration used during the build.
70+
71+
```text
72+
➜ npx rslib inspect
73+
74+
success Inspect config succeed, open following files to view the content:
75+
76+
- Rsbuild Config: /project/dist/.rsbuild/rsbuild.config.mjs
77+
- Rspack Config (esm): /project/dist/.rsbuild/rspack.config.esm.mjs
78+
```
79+
80+
### Verbose content
81+
82+
By default, the inspect command omits the content of functions in the configuration object. You can add the `--verbose` option to output the complete content of functions:
83+
84+
```bash
85+
rslib inspect --verbose
86+
```
87+
88+
### Multiple output formats
89+
90+
If the current project has multiple output formats, such as ESM artifact and CJS artifact simultaneously, multiple Rspack configuration files will be generated in the `dist/.rsbuild` directory.
91+
92+
```text
93+
➜ npx rslib inspect
94+
95+
Inspect config succeed, open following files to view the content:
96+
97+
success Inspect config succeed, open following files to view the content:
98+
99+
- Rsbuild Config (esm): /project/dist/.rsbuild/rsbuild.config.esm.mjs
100+
- Rsbuild Config (cjs): /project/dist/.rsbuild/rsbuild.config.cjs.mjs
101+
- Rspack Config (esm): /project/dist/.rsbuild/rspack.config.esm.mjs
102+
- Rspack Config (cjs): /project/dist/.rsbuild/rspack.config.cjs.mjs
103+
```

0 commit comments

Comments
 (0)