Skip to content

Commit 4a3e7fe

Browse files
authored
docs(clean): clarify clean wipes entire output dirs, not only generated files (#3657)
Clarifies that output.clean removes all files in the target and schemas directories, not just files produced by orval. Adds a warning against pointing target/schemas at package or library entrypoint roots that hold sentinel files (package.json, ng-package.json, public-api.ts), and a keep-file example (clean: ['!**/swagger.json']) for preserving specific files in-place. Brings the Chinese (zh) docs for clean to parity. Refs #3538
1 parent 5ca2b8b commit 4a3e7fe

4 files changed

Lines changed: 58 additions & 6 deletions

File tree

docs/content/docs/reference/cli.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ orval --watch ./src
5959

6060
### --clean
6161

62-
Clean generated files:
62+
Clean the output directories before regenerating:
6363

6464
```bash
6565
orval --clean

docs/content/docs/reference/configuration/output.mdx

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -782,9 +782,9 @@ export default defineConfig({
782782
**Type:** `Boolean | String[]`
783783
**Default:** `false`
784784

785-
Clean generated files before regenerating. Removes every file in the `target` and `schemas` directories (`.d.ts` files are preserved).
785+
Wipe the `target` and `schemas` directories before regenerating. Every file in those folders is removed (`.d.ts` files are preserved) — not only files produced by Orval, but also any other file that happens to live there.
786786

787-
When set to a `String[]`, the array entries are extra glob patterns appended to the deletion list, applied to both the `target` and `schemas` directories. Use negated globs (prefixed with `!`) to preserve files from removal, or positive globs to also remove files that would otherwise be kept.
787+
When set to a `String[]`, the array entries are extra glob patterns appended to the deletion list, applied to both the `target` and `schemas` directories. Use negated globs (prefixed with `!`) to preserve specific files from removal, or positive globs to also remove files that would otherwise be kept.
788788

789789
```ts title="orval.config.ts"
790790
export default defineConfig({
@@ -797,7 +797,24 @@ export default defineConfig({
797797
});
798798
```
799799

800-
Keep hand-written files (mutators, transformers, app code) outside the `target` and `schemas` directories — use a dedicated subfolder such as `./gen/` for output so `clean` does not remove them.
800+
For example, to keep a committed `swagger.json` next to the generated output:
801+
802+
```ts title="orval.config.ts"
803+
export default defineConfig({
804+
petstore: {
805+
output: {
806+
target: './src/generated',
807+
clean: ['!**/swagger.json'],
808+
},
809+
},
810+
});
811+
```
812+
813+
<Callout type="warn">
814+
`clean` removes the entire contents of the configured folders, not just generated files. Do not point `target` or `schemas` directly at a package or library entrypoint root that holds files you need to keep (`package.json`, `ng-package.json`, `public-api.ts`, etc.). Place generated output in a dedicated subdirectory such as `./generated/` so those files are never touched.
815+
</Callout>
816+
817+
Keep hand-written files (mutators, transformers, app code) outside the `target` and `schemas` directories for the same reason.
801818

802819
## formatter
803820

docs/content/docs/zh/reference/cli.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ orval --input ./openapi.yaml --output ./src/api.ts
3535

3636
### --clean
3737

38-
生成前清理输出目录或目标文件。谨慎使用,避免把非生成文件放进输出目录
38+
生成前清空输出目录(`target``schemas`)——会删除其中的所有文件,而不只是生成文件
3939

4040
### --formatter
4141

docs/content/docs/zh/reference/configuration/output.mdx

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,42 @@ export default defineConfig({
161161

162162
## clean
163163

164-
生成前清理输出。不要把手写代码放进被清理的生成目录。
164+
**类型:** `Boolean | String[]`
165+
**默认:** `false`
166+
167+
在重新生成前清空 `target``schemas` 目录。这两个目录中的**所有**文件都会被删除(`.d.ts` 文件会被保留)——不仅仅是 Orval 生成的文件,还包括其中存放的任何其他文件。
168+
169+
设为 `String[]` 时,数组项是追加到删除列表的额外 glob 模式,同时作用于 `target``schemas` 目录。用取反 glob(以 `!` 开头)来保留特定文件不被删除,或用正向 glob 来额外删除本会被保留的文件。
170+
171+
```ts title="orval.config.ts"
172+
export default defineConfig({
173+
petstore: {
174+
output: {
175+
// 保留 `important.ts`,并额外删除 `.d.ts` 文件
176+
clean: ['!**/important.ts', '**/*.d.ts'],
177+
},
178+
},
179+
});
180+
```
181+
182+
例如,要在生成产物旁保留已提交的 `swagger.json`
183+
184+
```ts title="orval.config.ts"
185+
export default defineConfig({
186+
petstore: {
187+
output: {
188+
target: './src/generated',
189+
clean: ['!**/swagger.json'],
190+
},
191+
},
192+
});
193+
```
194+
195+
<Callout type="warn">
196+
`clean` 会删除所配置目录中的全部内容,而不只是生成文件。不要把 `target``schemas` 直接指向包含你需要保留文件的包或库入口根目录(如 `package.json``ng-package.json``public-api.ts` 等)。请把生成产物放在专用子目录(例如 `./generated/`)中,以免这些文件被误删。
197+
</Callout>
198+
199+
出于同样的原因,请将手写文件(mutator、transformer、应用代码)放在 `target``schemas` 目录之外。
165200

166201
## formatter
167202

0 commit comments

Comments
 (0)