Skip to content
Merged
2 changes: 1 addition & 1 deletion packages/models/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"dependsOn": [
"^build",
"generate-docs",
{ "projects": "models-transformers", "target": "build" }
{ "projects": "jsdoc-annotation-transformer", "target": "build" }
]
},
"lint": {},
Expand Down
23 changes: 0 additions & 23 deletions packages/models/transformers/project.json

This file was deleted.

2 changes: 1 addition & 1 deletion packages/models/tsconfig.lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"types": ["node"],
"plugins": [
{
"transform": "./packages/models/transformers/dist",
"transform": "./tools/jsdoc-annotation-transformer/dist",
"afterDeclarations": true
}
]
Expand Down
69 changes: 69 additions & 0 deletions tools/jsdoc-annotation-transformer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# @code-pushup/jsdocs-annotation-transformer

TypeScript transformer plugin that automatically enhances type definitions with JSDoc comments and schema metadata.

## Purpose

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.

## How It Works

The transformer hooks into the TypeScript compilation process using `ts-patch` and automatically adds JSDoc comments above type definitions. Each comment includes:

- The type name
- A description explaining the type is derived from a Zod schema
- A link to the type reference documentation

## Example

Given a type definition like:

```typescript
export type Report = {
// ... type properties
};
```

The transformer automatically generates:

```typescript
/**
* Type Definition: `Report`
*
* This type is derived from a Zod schema and represents
* the validated structure of `Report` used within the application.
*
* @see {@link https://github.com/code-pushup/cli/blob/main/packages/models/docs/models-reference.md#report}
*/
export type Report = {
// ... type properties
};
```

## Usage

1. ts-patch install

2. Add the transformer to your `tsconfig.json`:

```json
{
"compilerOptions": {
"plugins": [
{
"transform": "./path/to/transformer/dist",
"afterDeclarations": true
}
]
}
}
```

3. Build your TypeScript project. The transformer will run automatically and add JSDoc comments to your type definitions.

### Options

| Option | Type | Required | Description |
| ------------------- | --------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `transform` | `string` | Yes | Path to the transformer module |
| `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. |
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const baseConfig = require('../../../eslint.config.js').default;
const baseConfig = require('../../eslint.config.js').default;

module.exports = [
...baseConfig,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@code-pushup/models-transformers",
"name": "@code-pushup/jsdocs-annotation-transformer",
"version": "0.0.0",
"description": "TypeScript transformers enhancing models with JSDoc and schema metadata",
"type": "commonjs",
Expand Down
23 changes: 23 additions & 0 deletions tools/jsdoc-annotation-transformer/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "jsdoc-annotation-transformer",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "tools/jsdoc-annotation-transformer/src",
"projectType": "library",
"targets": {
"build": {
"executor": "@nx/js:tsc",
"outputs": ["{options.outputPath}"],
"dependsOn": ["pre-build"],
"options": {
"outputPath": "tools/jsdoc-annotation-transformer/dist",
"main": "tools/jsdoc-annotation-transformer/src/index.ts",
"tsConfig": "tools/jsdoc-annotation-transformer/tsconfig.lib.json"
}
},
"pre-build": {
"command": "ts-patch install",
"cache": true,
"inputs": ["sharedGlobals", { "runtime": "ts-patch check" }]
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../../tsconfig.base.json",
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"module": "commonjs",
"verbatimModuleSyntax": false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"outDir": "./dist",
"rootDir": "./",
"module": "commonjs",
"types": ["node"]
"types": ["node"],
"esModuleInterop": true
},
"include": ["src/**/*.ts"]
}
29 changes: 29 additions & 0 deletions tools/jsdoc-annotation-transformer/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"types": [
"vitest/globals",
"vitest/importMeta",
"vite/client",
"node",
"vitest"
]
},
"include": [
"vite.config.ts",
"vite.config.mts",
"vitest.config.ts",
"vitest.config.mts",
"vitest.unit.config.ts",
"src/**/*.test.ts",
"src/**/*.spec.ts",
"src/**/*.test.tsx",
"src/**/*.spec.tsx",
"src/**/*.test.js",
"src/**/*.spec.js",
"src/**/*.test.jsx",
"src/**/*.spec.jsx",
"src/**/*.d.ts"
]
}
3 changes: 3 additions & 0 deletions tools/jsdoc-annotation-transformer/vitest.unit.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { createUnitTestConfig } from '../../testing/test-setup-config/src/index.js';

export default createUnitTestConfig('jsdoc-annotation-transformer');