|
1 | 1 | # @code-pushup/zod2md-nx-plugin |
2 | 2 |
|
3 | | -[](https://www.npmjs.com/package/@code-pushup/zod2md-nx-plugin) |
4 | | -[](https://npmtrends.com/@code-pushup/zod2md-nx-plugin) |
5 | | -[](https://www.npmjs.com/package/@code-pushup/zod2md-nx-plugin?activeTab=dependencies) |
| 3 | +The Nx Plugin for [zod2md](https://github.com/code-pushup/zod2md), a tool for generating documentation from Zod schemas. |
6 | 4 |
|
7 | | -Low-level **utilities** (helper functions, etc.) used by [Code PushUp CLI](../cli/README.md). |
| 5 | +Why should you use this plugin? |
8 | 6 |
|
9 | | -## Setup |
| 7 | +- Zero setup cost. Just add a `zod2md.config.ts` file and you're good to go. |
| 8 | +- Automatic target generation |
| 9 | +- Minimal configuration |
| 10 | +- Automated caching and dependency tracking |
10 | 11 |
|
11 | | -If you've already installed another `@code-pushup/*` package, then you may have already installed `@code-pushup/zod2md-nx-plugin` indirectly. |
12 | | - |
13 | | -If not, you can always install it separately: |
| 12 | +## Usage |
14 | 13 |
|
15 | | -```sh |
16 | | -npm install --save-dev @code-pushup/zod2md-nx-plugin |
| 14 | +```jsonc |
| 15 | +// nx.json |
| 16 | +{ |
| 17 | + //... |
| 18 | + "plugins": ["./tools/zod2md-nx-plugin/src/lib/plugin.js"], |
| 19 | +} |
17 | 20 | ``` |
18 | 21 |
|
19 | | -```sh |
20 | | -yarn add --dev @code-pushup/zod2md-nx-plugin |
| 22 | +or with options: |
| 23 | + |
| 24 | +```jsonc |
| 25 | +// nx.json |
| 26 | +{ |
| 27 | + //... |
| 28 | + "plugins": [ |
| 29 | + { |
| 30 | + "plugin": "./tools/zod2md-nx-plugin/src/lib/plugin.js", |
| 31 | + "options": { |
| 32 | + "targetName": "docs", |
| 33 | + }, |
| 34 | + }, |
| 35 | + ], |
| 36 | +} |
21 | 37 | ``` |
22 | 38 |
|
23 | | -```sh |
24 | | -pnpm add --save-dev @code-pushup/zod2md-nx-plugin |
| 39 | +Now every project with a `zod2md.config.ts` file will have a `generate-docs` target automatically created. |
| 40 | + |
| 41 | +- `nx run <project-name>:generate-docs` |
| 42 | + |
| 43 | +Run it and the project will automatically generate documentation from your Zod schemas. |
| 44 | + |
| 45 | +```text |
| 46 | +Root/ |
| 47 | +├── project-name/ |
| 48 | +│ ├── zod2md.config.ts |
| 49 | +│ ├── docs/ |
| 50 | +│ │ └── project-name-reference.md 👈 generated |
| 51 | +│ └── ... |
| 52 | +└── ... |
25 | 53 | ``` |
26 | 54 |
|
27 | | -## Usage |
| 55 | +The generated target: |
28 | 56 |
|
29 | | -```ts |
30 | | -import { executeProcess, readJsonFile, slugify } from '@code-pushup/zod2md-nx-plugin'; |
| 57 | +1. Runs `zod2md` with the project's configuration |
| 58 | +2. Formats the generated markdown with Prettier |
| 59 | +3. Caches the result for better performance |
31 | 60 |
|
32 | | -await executeProcess({ |
33 | | - command: 'npx', |
34 | | - args: ['eslint', '--format=json', '--output-file=output.json', '**/*.js'], |
35 | | -}); |
| 61 | +## Options |
36 | 62 |
|
37 | | -const data = await readJsonFile('output.json'); |
| 63 | +| Name | type | description | |
| 64 | +| -------------- | ---------------------------------- | ------------------------------------------------------ | |
| 65 | +| **targetName** | `string` (DEFAULT 'generate-docs') | The id used to identify a target in your project.json. | |
38 | 66 |
|
39 | | -const slug = slugify('Hello, world!'); // "hello-world" |
| 67 | +All options are optional and provided in the `nx.json` file. |
| 68 | + |
| 69 | +```jsonc |
| 70 | +// nx.json |
| 71 | +{ |
| 72 | + //... |
| 73 | + "plugins": [ |
| 74 | + { |
| 75 | + "plugin": "./tools/zod2md-nx-plugin/src/lib/plugin.js", |
| 76 | + "options": { |
| 77 | + "targetName": "docs", |
| 78 | + }, |
| 79 | + }, |
| 80 | + ], |
| 81 | +} |
| 82 | +``` |
| 83 | + |
| 84 | +## Configuration |
| 85 | + |
| 86 | +Create a `zod2md.config.ts` file in your project: |
| 87 | + |
| 88 | +```ts |
| 89 | +import type { Config } from 'zod2md'; |
| 90 | + |
| 91 | +export default { |
| 92 | + entry: 'packages/models/src/index.ts', |
| 93 | + tsconfig: 'packages/models/tsconfig.lib.json', |
| 94 | + format: 'esm', |
| 95 | + title: 'Models reference', |
| 96 | + output: 'packages/models/docs/models-reference.md', |
| 97 | +} satisfies Config; |
40 | 98 | ``` |
| 99 | + |
| 100 | +For a full list of configuration options visit the [zod2md documentation](https://github.com/code-pushup/zod2md#readme). |
0 commit comments