Skip to content

Commit 9112bf0

Browse files
author
John Doe
committed
refactor: adjust plugin code
1 parent 00256ee commit 9112bf0

File tree

3 files changed

+93
-41
lines changed

3 files changed

+93
-41
lines changed

tools/zod2md-nx-plugin/README.md

Lines changed: 83 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,100 @@
11
# @code-pushup/zod2md-nx-plugin
22

3-
[![npm](https://img.shields.io/npm/v/%40code-pushup%2Futils.svg)](https://www.npmjs.com/package/@code-pushup/zod2md-nx-plugin)
4-
[![downloads](https://img.shields.io/npm/dm/%40code-pushup%2Futils)](https://npmtrends.com/@code-pushup/zod2md-nx-plugin)
5-
[![dependencies](https://img.shields.io/librariesio/release/npm/%40code-pushup/utils)](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.
64

7-
Low-level **utilities** (helper functions, etc.) used by [Code PushUp CLI](../cli/README.md).
5+
Why should you use this plugin?
86

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
1011

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
1413

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+
}
1720
```
1821

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+
}
2137
```
2238

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+
└── ...
2553
```
2654

27-
## Usage
55+
The generated target:
2856

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
3160

32-
await executeProcess({
33-
command: 'npx',
34-
args: ['eslint', '--format=json', '--output-file=output.json', '**/*.js'],
35-
});
61+
## Options
3662

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. |
3866

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;
4098
```
99+
100+
For a full list of configuration options visit the [zod2md documentation](https://github.com/code-pushup/zod2md#readme).

tools/zod2md-nx-plugin/package.json

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,14 @@
22
"name": "@code-pushup/zod2md-nx-plugin",
33
"version": "0.0.0",
44
"license": "MIT",
5-
"homepage": "https://github.com/code-pushup/cli/tree/main/tools/zod2md-nx-plugin#readme",
65
"publishConfig": {
76
"access": "public"
87
},
98
"type": "module",
109
"engines": {
1110
"node": ">=17.0.0"
1211
},
13-
"dependencies": {
14-
"@code-pushup/models": "0.92.0",
15-
"ansis": "^3.3.0",
16-
"build-md": "^0.4.2",
17-
"bundle-require": "^5.1.0",
18-
"esbuild": "^0.25.2",
19-
"ora": "^9.0.0",
20-
"semver": "^7.6.0",
21-
"simple-git": "^3.20.0",
22-
"string-width": "^8.1.0",
23-
"wrap-ansi": "^9.0.2",
24-
"zod": "^4.0.5"
25-
},
12+
"dependencies": {},
2613
"files": [
2714
"src",
2815
"!**/*.tsbuildinfo"

tools/zod2md-nx-plugin/src/lib/plugin.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import { dirname } from 'node:path';
33
export const createNodesV2 = [
44
`**/zod2md.config.ts`,
55
async (zod2MdConfigurationFiles, createNodesOptions, context) => {
6+
const options = createNodesOptions ?? {};
7+
const targetName = options.targetName ?? 'generate-docs';
8+
69
return Promise.all(
710
zod2MdConfigurationFiles.map(async zod2MdConfigurationFile => {
811
const projectRoot = dirname(zod2MdConfigurationFile);
@@ -11,22 +14,24 @@ export const createNodesV2 = [
1114
projects: {
1215
[normalizedProjectRoot]: {
1316
targets: {
14-
'generate-docs': {
17+
[targetName]: {
1518
executor: 'nx:run-commands',
1619
options: {
1720
commands: [
18-
'zod2md --config {projectRoot}/zod2md.config.ts',
19-
'prettier --write {projectRoot}/docs/{projectName}-reference.md',
21+
'zod2md --config {args.config} --output {args.output}',
22+
'prettier --write {args.output}',
2023
],
2124
parallel: false,
25+
config: '{projectRoot}/zod2md.config.ts',
26+
output: '{projectRoot}/docs/{projectName}-reference.md',
2227
},
2328
cache: true,
2429
inputs: [
2530
'production',
2631
'^production',
2732
'{projectRoot}/zod2md.config.ts',
2833
],
29-
outputs: ['{projectRoot}/docs/{projectName}-reference.md'],
34+
outputs: ['{projectRoot}/docs/{outputFile}'],
3035
},
3136
},
3237
},

0 commit comments

Comments
 (0)