Skip to content

Commit 9068301

Browse files
author
Michael Hladky
committed
refactor: wip
1 parent 1daa238 commit 9068301

File tree

7 files changed

+99
-74
lines changed

7 files changed

+99
-74
lines changed

nx.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@
337337
"releaseTagPattern": "v{version}"
338338
},
339339
"plugins": [
340-
"./tools/zod2md-nx-plugin/src/lib/plugin.js",
340+
"./tools/zod2md-jsdocs/src/nx-plugin.js",
341341
{
342342
"plugin": "@push-based/nx-verdaccio",
343343
"options": {

tools/zod2md-jsdocs/README.md

Lines changed: 20 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,41 @@
1-
# @code-pushup/zod2md-jsdocs
1+
# zod2md-jsdocs
22

3-
TypeScript transformer plugin that automatically enhances type definitions with JSDoc comments and schema metadata.
3+
A comprehensive toolset for generating and enhancing TypeScript documentation from Zod schemas. This package combines an Nx plugin for automated documentation generation with a TypeScript transformer that enriches type definitions with JSDoc comments.
44

5-
## Purpose
5+
## What's Included
66

7-
This package provides a TypeScript compiler transformer that automatically adds JSDoc documentation to type aliases and interfaces during compilation. It's designed to improve developer experience by injecting helpful metadata and documentation links directly into generated type definitions.
7+
This package provides two main components:
88

9-
## How It Works
9+
1. **[Nx Plugin](./docs/zod2md-jsdocs-nx-plugin.md)** - Automatically generates documentation targets for projects with Zod schemas
10+
2. **[TypeScript Transformer](./docs/zod2md-jsdocs-ts-transformer.md)** - Enhances generated type definitions with JSDoc comments and schema metadata
1011

11-
The [TS transformer](https://github.com/itsdouges/typescript-transformer-handbook) hooks into the TypeScript compilation process using `ts-patch` and automatically adds JSDoc comments above type definitions. Each comment includes:
12+
## Quick Start
1213

13-
- The type name
14-
- A description explaining the type is derived from a Zod schema
15-
- A link to the type reference documentation
14+
### Using the Nx Plugin
1615

17-
## Example
16+
Add the plugin to your `nx.json`:
1817

19-
Given a type definition like:
20-
21-
```typescript
22-
export type Report = {
23-
// ... type properties
24-
};
18+
```jsonc
19+
{
20+
"plugins": ["./tools/zod2md-jsdocs/src/lib/plugin.js"],
21+
}
2522
```
2623

27-
The transformer automatically generates:
24+
Create a `zod2md.config.ts` in your project, and you'll automatically get a `generate-docs` target.
2825

29-
```typescript
30-
/**
31-
* Type Definition: `Report`
32-
*
33-
* This type is derived from a Zod schema and represents
34-
* the validated structure of `Report` used within the application.
35-
*
36-
* @see {@link https://github.com/code-pushup/cli/blob/main/packages/models/docs/models-reference.md#report}
37-
*/
38-
export type Report = {
39-
// ... type properties
40-
};
41-
```
26+
[Learn more about the Nx Plugin →](./docs/zod2md-jsdocs-nx-plugin.md)
4227

43-
## Usage
28+
### Using the TypeScript Transformer
4429

45-
1. `ts-patch install`
46-
47-
2. Add the transformer to your `tsconfig.json`:
30+
1. Install ts-patch: `ts-patch install`
31+
2. Add to your `tsconfig.json`:
4832

4933
```json
5034
{
5135
"compilerOptions": {
5236
"plugins": [
5337
{
54-
"transform": "./path/to/transformer/dist",
38+
"transform": "./tools/zod2md-jsdocs/dist/src",
5539
"afterDeclarations": true,
5640
"baseUrl": "https://example.com/docs/api-reference.md"
5741
}
@@ -60,12 +44,4 @@ export type Report = {
6044
}
6145
```
6246

63-
3. Build your TypeScript project. The transformer will run automatically and add JSDoc comments to your type definitions.
64-
65-
### Options
66-
67-
| Option | Type | Required | Description |
68-
| ------------------- | --------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
69-
| `transform` | `string` | Yes | Path to the transformer module |
70-
| `afterDeclarations` | `boolean` | No | Set to `true` to run the transformer after TypeScript generates declaration files (`.d.ts`). This ensures JSDoc comments are added to the emitted type definitions. |
71-
| `baseUrl` | `string` | Yes | Base URL for documentation links (e.g., `https://example.com/docs/api-reference.md`) |
47+
[Learn more about the TypeScript Transformer →](./docs/zod2md-jsdocs-ts-transformer.md)

tools/zod2md-nx-plugin/README.md renamed to tools/zod2md-jsdocs/docs/zod2md-jsdocs-nx-plugin.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# @code-pushup/zod2md-nx-plugin
1+
# @code-pushup/zod2md-jsdocs-nx-plugin
22

33
The Nx Plugin for [zod2md](https://github.com/matejchalk/zod2md), a tool for generating documentation from Zod schemas.
44

@@ -15,7 +15,7 @@ Why should you use this plugin?
1515
// nx.json
1616
{
1717
//...
18-
"plugins": ["./tools/zod2md-nx-plugin/src/lib/plugin.js"],
18+
"plugins": ["./tools/zod2md-jsdocs-nx-plugin/src/lib/plugin.js"],
1919
}
2020
```
2121

@@ -27,7 +27,7 @@ or with options:
2727
//...
2828
"plugins": [
2929
{
30-
"plugin": "./tools/zod2md-nx-plugin/src/lib/plugin.js",
30+
"plugin": "./tools/zod2md-jsdocs-nx-plugin/src/lib/plugin.js",
3131
"options": {
3232
"targetName": "zod-docs",
3333
},
@@ -92,7 +92,7 @@ All options are optional and provided in the `nx.json` file.
9292
//...
9393
"plugins": [
9494
{
95-
"plugin": "./tools/zod2md-nx-plugin/src/lib/plugin.js",
95+
"plugin": "./tools/zod2md-jsdocs-nx-plugin/src/lib/plugin.js",
9696
"options": {
9797
"targetName": "docs",
9898
},
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# zod2md-jsdocs-ts-transformer
2+
3+
TypeScript transformer plugin that automatically enhances type definitions with JSDoc comments and schema metadata.
4+
5+
## Purpose
6+
7+
This package provides a TypeScript compiler transformer that automatically adds JSDoc documentation to type aliases and interfaces during compilation. It's designed to improve developer experience by injecting helpful metadata and documentation links directly into generated type definitions.
8+
9+
## How It Works
10+
11+
The [TS transformer](https://github.com/itsdouges/typescript-transformer-handbook) hooks into the TypeScript compilation process using `ts-patch` and automatically adds JSDoc comments above type definitions. Each comment includes:
12+
13+
- The type name
14+
- A description explaining the type is derived from a Zod schema
15+
- A link to the type reference documentation
16+
17+
## Example
18+
19+
Given a type definition like:
20+
21+
```typescript
22+
export type Report = {
23+
// ... type properties
24+
};
25+
```
26+
27+
The transformer automatically generates:
28+
29+
```typescript
30+
/**
31+
* Type Definition: `Report`
32+
*
33+
* This type is derived from a Zod schema and represents
34+
* the validated structure of `Report` used within the application.
35+
*
36+
* @see {@link https://github.com/code-pushup/cli/blob/main/packages/models/docs/models-reference.md#report}
37+
*/
38+
export type Report = {
39+
// ... type properties
40+
};
41+
```
42+
43+
## Usage
44+
45+
1. `ts-patch install`
46+
47+
2. Add the transformer to your `tsconfig.json`:
48+
49+
```json
50+
{
51+
"compilerOptions": {
52+
"plugins": [
53+
{
54+
"transform": "./path/to/transformer/dist",
55+
"afterDeclarations": true,
56+
"baseUrl": "https://example.com/docs/api-reference.md"
57+
}
58+
]
59+
}
60+
}
61+
```
62+
63+
3. Build your TypeScript project. The transformer will run automatically and add JSDoc comments to your type definitions.
64+
65+
### Options
66+
67+
| Option | Type | Required | Description |
68+
| ------------------- | --------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
69+
| `transform` | `string` | Yes | Path to the transformer module |
70+
| `afterDeclarations` | `boolean` | No | Set to `true` to run the transformer after TypeScript generates declaration files (`.d.ts`). This ensures JSDoc comments are added to the emitted type definitions. |
71+
| `baseUrl` | `string` | Yes | Base URL for documentation links (e.g., `https://example.com/docs/api-reference.md`) |
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ export const createNodesV2 = [
4545
];
4646

4747
// default export for nx.json#plugins
48-
const plugin = {
49-
name: 'zod2md-nx-plugin',
48+
const nxPlugin = {
49+
name: 'zod2md-jsdocs-nx-plugin',
5050
createNodesV2,
5151
};
5252

53-
export default plugin;
53+
export default nxPlugin;

tools/zod2md-nx-plugin/eslint.config.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

tools/zod2md-nx-plugin/project.json

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)