|
1 | 1 | --- |
2 | 2 | name: rstack-cli-best-practices |
3 | | -description: Guidance on using Rstack CLI, including `rs` commands, the `rstack.config.ts` file, and import paths from the `rstack` package. Use for Rstack CLI-related tasks. |
| 3 | +description: Guidance for Rstack CLI work involving `rs` commands, `rstack.config.*`, package APIs, or Rstack-based projects and tooling. |
4 | 4 | --- |
5 | 5 |
|
6 | 6 | # Rstack CLI Best Practices |
7 | 7 |
|
8 | | -Rstack CLI is the `rstack` package, exposed through the `rs` binaries. It provides one CLI, one config file, and a consistent workflow for the Rstack JavaScript toolchain. |
| 8 | +Rstack CLI is the `rstack` package, exposed through the `rs` binaries. It provides one CLI, one |
| 9 | +config file, and a consistent workflow for the Rstack JavaScript toolchain. |
9 | 10 |
|
10 | 11 | It covers web app, library, docs, test, lint, formatting, Git hook, and staged-file workflows. |
11 | 12 |
|
12 | | -## Commands |
| 13 | +## ALWAYS read installed docs before working |
13 | 14 |
|
14 | | -Use `rs -h` for top-level help, and `rs <command> -h` for command help where supported. |
| 15 | +Before any Rstack work, find and read the relevant Markdown documentation shipped with the installed `rstack` package. |
15 | 16 |
|
16 | | -| Command | Purpose | Underlying tool | Config | |
17 | | -| ------------ | -------------------------------- | --------------- | --------------- | |
18 | | -| `rs dev` | Run the app dev server | Rsbuild | `define.app` | |
19 | | -| `rs build` | Build the app for production | Rsbuild | `define.app` | |
20 | | -| `rs preview` | Preview the app production build | Rsbuild | `define.app` | |
21 | | -| `rs lib` | Build a library | Rslib | `define.lib` | |
22 | | -| `rs doc` | Serve or build docs | Rspress | `define.doc` | |
23 | | -| `rs test` | Run tests | Rstest | `define.test` | |
24 | | -| `rs lint` | Lint code | Rslint | `define.lint` | |
25 | | -| `rs fmt` | Format code | Prettier | `define.fmt` | |
26 | | -| `rs setup` | Install project-local Git hooks | None | None | |
27 | | -| `rs staged` | Run tasks on staged Git files | lint-staged | `define.staged` | |
| 17 | +Model knowledge can be outdated; the installed documentation is the source of truth for the project's Rstack version. |
28 | 18 |
|
29 | | -Key behavior: |
| 19 | +1. Start with `node_modules/rstack/dist/docs/llms.txt`, then read only the linked pages relevant to the task before proposing or making changes. |
30 | 20 |
|
31 | | -- Unless `define.test` already sets `extends`, `rs test` extends `define.app` through `@rstest/adapter-rsbuild` or falls back to `define.lib` through `@rstest/adapter-rslib`. The app config takes precedence when both are defined. |
32 | | -- `rs doc` requires the optional `@rspress/core` dependency. |
| 21 | +2. For exact CLI flags and behavior, also run `rs -h` or `rs <command> -h` when supported. |
33 | 22 |
|
34 | | -## rstack.config.ts |
| 23 | +If the bundled docs are not available at that path, locate the installed `rstack` package. |
35 | 24 |
|
36 | | -Rstack CLI loads `rstack.config.{ts,js,mts,mjs}` by default. |
37 | | - |
38 | | -Register config with `define.*`: |
39 | | - |
40 | | -```ts |
41 | | -import { define } from 'rstack'; |
42 | | - |
43 | | -define.app({ |
44 | | - // Rsbuild config for `rs dev`, `rs build`, and `rs preview` |
45 | | -}); |
46 | | - |
47 | | -define.test({ |
48 | | - // Rstest config for `rs test` |
49 | | -}); |
50 | | -``` |
51 | | - |
52 | | -- `define.app(config)`: Rsbuild config for `rs dev`, `rs build`, and `rs preview`. Docs: https://rsbuild.rs/config/ |
53 | | -- `define.lib(config)`: Rslib config for `rs lib`; Docs: https://rslib.rs/config/ |
54 | | -- `define.doc(config)`: Rspress config for `rs doc`; Docs: https://rspress.rs/api/config/config-basic |
55 | | -- `define.test(config)`: Rstest config for `rs test`; Docs: https://rstest.rs/config/ |
56 | | -- `define.lint(config)`: Rslint config for `rs lint`; Docs: https://rslint.rs/config/ |
57 | | -- `define.fmt(config)`: Formatting options for `rs fmt`. |
58 | | -- `define.staged(config)`: lint-staged config for `rs staged`; accepts `Record<string, string | string[]>`. |
59 | | - |
60 | | -### Lazy Configuration |
61 | | - |
62 | | -Prefer async functions with dynamic imports for dependencies. Avoid top-level sync imports of heavy dependencies in `rstack.config.ts`. |
63 | | - |
64 | | -```ts |
65 | | -import { define } from 'rstack'; |
66 | | - |
67 | | -define.app(async () => { |
68 | | - const { pluginReact } = await import('@rsbuild/plugin-react'); |
69 | | - return { |
70 | | - plugins: [pluginReact()], |
71 | | - }; |
72 | | -}); |
73 | | -``` |
74 | | - |
75 | | -## Import Paths |
76 | | - |
77 | | -Prefer Rstack-exported paths: |
78 | | - |
79 | | -| Instead of | Prefer | |
80 | | -| ------------------------- | ------------------------ | |
81 | | -| `@rsbuild/core` | `rstack/app` | |
82 | | -| `@rslib/core` | `rstack/lib` | |
83 | | -| `@rstest/core` | `rstack/test` | |
84 | | -| `@rslint/core` | `rstack/lint` | |
85 | | -| `@rsbuild/core/types` | `rstack/types` | |
86 | | -| `@rslib/core/types` | `rstack/types` | |
87 | | -| `@rstest/core/globals` | `rstack/test/globals` | |
88 | | -| `@rstest/core/importMeta` | `rstack/test/importMeta` | |
89 | | - |
90 | | -## Git Hooks |
91 | | - |
92 | | -Use [`rs setup`](https://rstack.rs/guide/cli/setup) for project-local Git hooks, commonly with `rs staged` in a `pre-commit` hook. |
| 25 | +If they are still unavailable, verify that `rstack` is installed, and use CLI help plus the online [Rstack documentation](https://rstack.rs/) as a fallback. |
0 commit comments