Skip to content

Commit 867c80d

Browse files
author
John Doe
committed
refactor: move models-transformers into tools
1 parent 068984b commit 867c80d

12 files changed

Lines changed: 113 additions & 17 deletions

File tree

packages/models/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"dependsOn": [
2222
"^build",
2323
"generate-docs",
24-
{ "projects": "models-transformers", "target": "build" }
24+
{ "projects": "jsdocs-annotation-transformer", "target": "build" }
2525
]
2626
},
2727
"lint": {},

packages/models/tsconfig.lib.json

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,7 @@
33
"compilerOptions": {
44
"outDir": "../../dist/out-tsc",
55
"declaration": true,
6-
"types": ["node"],
7-
"plugins": [
8-
{
9-
"transform": "./packages/models/transformers/dist",
10-
"afterDeclarations": true
11-
}
12-
]
6+
"types": ["node"]
137
},
148
"include": ["src/**/*.ts"],
159
"exclude": [
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# @code-pushup/jsdocs-annotation-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 transformer 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 models 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": "./packages/models/transformers/dist",
55+
"afterDeclarations": true
56+
}
57+
]
58+
}
59+
}
60+
```
61+
62+
3. Build your TypeScript project. The transformer will run automatically and add JSDoc comments to your type definitions.
63+
64+
### Options
65+
66+
| Option | Type | Required | Description |
67+
| ------------------- | --------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
68+
| `transform` | `string` | Yes | Path to the transformer module |
69+
| `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. |

packages/models/transformers/eslint.config.cjs renamed to tools/jsdoc-annotation-transformer/eslint.config.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const baseConfig = require('../../../eslint.config.js').default;
1+
const baseConfig = require('../../eslint.config.js').default;
22

33
module.exports = [
44
...baseConfig,

packages/models/transformers/package.json renamed to tools/jsdoc-annotation-transformer/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "@code-pushup/models-transformers",
2+
"name": "@code-pushup/jsdocs-annotation-transformer",
33
"version": "0.0.0",
44
"description": "TypeScript transformers enhancing models with JSDoc and schema metadata",
55
"type": "commonjs",

packages/models/transformers/project.json renamed to tools/jsdoc-annotation-transformer/project.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
{
2-
"name": "models-transformers",
2+
"name": "jsdoc-annotation-transformer",
33
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
4-
"sourceRoot": "packages/models/transformers/src",
4+
"sourceRoot": "tools/jsdoc-annotation-transformer/src",
55
"projectType": "library",
66
"targets": {
77
"build": {
88
"executor": "@nx/js:tsc",
99
"outputs": ["{options.outputPath}"],
1010
"dependsOn": ["pre-build"],
1111
"options": {
12-
"outputPath": "packages/models/transformers/dist",
13-
"main": "packages/models/transformers/src/index.ts",
14-
"tsConfig": "packages/models/transformers/tsconfig.lib.json"
12+
"outputPath": "tools/jsdoc-annotation-transformer/dist",
13+
"main": "tools/jsdoc-annotation-transformer/src/index.ts",
14+
"tsConfig": "tools/jsdoc-annotation-transformer/tsconfig.lib.json"
1515
}
1616
},
1717
"pre-build": {
File renamed without changes.

packages/models/transformers/src/lib/transformers.ts renamed to tools/jsdoc-annotation-transformer/src/lib/transformers.ts

File renamed without changes.

packages/models/transformers/tsconfig.json renamed to tools/jsdoc-annotation-transformer/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"extends": "../../../tsconfig.base.json",
2+
"extends": "../../tsconfig.base.json",
33
"compilerOptions": {
44
"module": "commonjs",
55
"verbatimModuleSyntax": false

packages/models/transformers/tsconfig.lib.json renamed to tools/jsdoc-annotation-transformer/tsconfig.lib.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"outDir": "./dist",
55
"rootDir": "./",
66
"module": "commonjs",
7-
"types": ["node"]
7+
"types": ["node"],
8+
"esModuleInterop": true
89
},
910
"include": ["src/**/*.ts"]
1011
}

0 commit comments

Comments
 (0)