Skip to content

Commit 5a9df5d

Browse files
authored
Merge 8a4a584 into 7b6e72c
2 parents 7b6e72c + 8a4a584 commit 5a9df5d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1863
-179
lines changed

e2e/nx-plugin-e2e/tests/plugin-plugins-config.e2e.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ describe('nx-plugin pluginsConfig', () => {
7474

7575
await materializeTree(tree, cwd);
7676

77-
const { code, projectJson } = await nxShowProjectJson(cwd, project);
77+
const { code, stderr, projectJson } = await nxShowProjectJson(cwd, project);
78+
expect(stderr).toBe('');
7879
expect(code).toBe(0);
7980

8081
expect(projectJson).toStrictEqual(

nx.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@
345345
"releaseTagPattern": "v{version}"
346346
},
347347
"plugins": [
348-
"./tools/zod2md-jsdocs/src/nx-plugin.ts",
348+
"./tools/zod2md-jsdocs/src/lib/plugin/nx-plugin.ts",
349349
{
350350
"plugin": "@push-based/nx-verdaccio",
351351
"options": {

packages/models/project.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,10 @@
33
"$schema": "../../node_modules/nx/schemas/project-schema.json",
44
"sourceRoot": "packages/models/src",
55
"projectType": "library",
6+
"implicitDependencies": ["zod2md-jsdocs"],
67
"targets": {
78
"build": {
8-
"dependsOn": [
9-
"^build",
10-
"generate-docs",
11-
{ "projects": "zod2md-jsdocs", "target": "build" },
12-
{ "projects": "zod2md-jsdocs", "target": "ts-patch" }
13-
]
9+
"dependsOn": ["^build", "generate-docs", "ts-patch"]
1410
},
1511
"lint": {},
1612
"unit-test": {},

testing/test-nx-utils/src/lib/utils/nx.ts

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import {
99
} from '@nx/devkit';
1010
import { libraryGenerator } from '@nx/js';
1111
import type { LibraryGeneratorSchema } from '@nx/js/src/generators/library/schema';
12-
import path from 'node:path';
12+
import * as path from 'node:path';
1313
import { createTreeWithEmptyWorkspace } from 'nx/src/generators/testing-utils/create-tree-with-empty-workspace';
14-
import { executeProcess } from '@code-pushup/utils';
14+
import { executeProcess } from '@code-pushup/test-utils';
1515

1616
export function executorContext<
1717
T extends { projectName: string; cwd?: string },
@@ -95,11 +95,29 @@ export async function nxShowProjectJson<T extends ProjectConfiguration>(
9595
cwd: string,
9696
project: string,
9797
) {
98-
const { code, stderr, stdout } = await executeProcess({
99-
command: 'npx',
100-
args: ['nx', 'show', `project --json ${project}`],
101-
cwd,
102-
});
98+
try {
99+
const { stderr, stdout } = await executeProcess({
100+
command: 'npx',
101+
args: ['nx', 'show', 'project', project, '--json'],
102+
cwd,
103+
});
103104

104-
return { code, stderr, projectJson: JSON.parse(stdout) as T };
105+
return {
106+
code: 0,
107+
stderr,
108+
projectJson: JSON.parse(stdout) as T,
109+
};
110+
} catch (error: unknown) {
111+
const execError = error as {
112+
code?: number | string | null;
113+
stderr?: string;
114+
stdout?: string;
115+
message?: string;
116+
};
117+
return {
118+
code: typeof execError.code === 'number' ? execError.code : 1,
119+
stderr: execError.stderr ?? execError.message ?? String(error),
120+
projectJson: JSON.parse('{}'),
121+
};
122+
}
105123
}

testing/test-utils/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ export * from './lib/utils/project-graph.js';
1212
export * from './lib/utils/test-folder-setup.js';
1313
export * from './lib/utils/omit-trace-json.js';
1414
export * from './lib/utils/profiler.mock.js';
15+
export * from './lib/utils/execute-process.js';
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/** THIS IS A COPY OF THE UTILS PACKAGE AND TESTED THERE **/
2+
import { execFile } from 'node:child_process';
3+
import { promisify } from 'node:util';
4+
5+
export async function executeProcess(cfg: {
6+
command: string;
7+
args: string[];
8+
cwd: string;
9+
}) {
10+
const execFileAsync = promisify(execFile);
11+
const { command, args, cwd } = cfg;
12+
return await execFileAsync(command, args, { cwd });
13+
}

tools/zod2md-jsdocs/README.md

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,9 @@ A comprehensive toolset for generating and enhancing TypeScript documentation fr
44

55
## What's Included
66

7-
This package provides two main components:
7+
This package provides the following components:
88

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
11-
12-
## Quick Start
13-
14-
### Using the Nx Plugin
15-
16-
Add the plugin to your `nx.json`:
17-
18-
```jsonc
19-
{
20-
"plugins": ["./tools/zod2md-jsdocs/src/nx-plugin.ts"],
21-
}
22-
```
23-
24-
Create a `zod2md.config.ts` in your project, and you'll automatically get a `generate-docs` target.
25-
26-
[Learn more about the Nx Plugin →](./docs/zod2md-jsdocs-nx-plugin.md)
27-
28-
### Using the TypeScript Transformer
29-
30-
1. Install ts-patch: `ts-patch install`
31-
2. Add to your `tsconfig.json`:
32-
33-
```json
34-
{
35-
"compilerOptions": {
36-
"plugins": [
37-
{
38-
"transform": "./tools/zod2md-jsdocs/dist/src",
39-
"afterDeclarations": true,
40-
"baseUrl": "https://github.com/code-pushup/cli/blob/main/packages/<PROJECT-NAME>/docs/models-reference.md"
41-
}
42-
]
43-
}
44-
}
45-
```
46-
47-
[Learn more about the TypeScript Transformer →](./docs/zod2md-jsdocs-ts-transformer.md)
9+
1. **[Nx Plugin](./src/lib/plugin/README.md)** - Automatically generates documentation targets for projects with Zod schemas
10+
2. **[Nx Configuration Generator](./src/lib/generators/configuration/README.md)** - Automatically generates documentation targets for projects with Zod schemas
11+
3. **[Nx Sync Zod2Md Setup Generator](./src/lib/generators/sync-zod2md-setup/README.md)** - Automatically generates documentation targets for projects with Zod schemas
12+
4. **[TypeScript Transformer](./src/lib/transformers/README.md)** - Enhances generated type definitions with JSDoc comments and schema metadata

tools/zod2md-jsdocs/docs/zod2md-jsdocs-nx-plugin.md

Lines changed: 0 additions & 80 deletions
This file was deleted.
Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,60 @@
1+
const tseslint = require('typescript-eslint');
12
const baseConfig = require('../../eslint.config.js').default;
23

3-
module.exports = [
4+
module.exports = tseslint.config(
45
...baseConfig,
6+
{
7+
files: ['**/*.ts'],
8+
languageOptions: {
9+
parserOptions: {
10+
projectService: true,
11+
tsconfigRootDir: __dirname,
12+
},
13+
},
14+
},
15+
{
16+
files: ['**/*.ts'],
17+
rules: {
18+
// Nx plugins don't yet support ESM: https://github.com/nrwl/nx/issues/15682
19+
'unicorn/prefer-module': 'off',
20+
// used instead of verbatimModuleSyntax tsconfig flag (requires ESM)
21+
'@typescript-eslint/consistent-type-imports': [
22+
'warn',
23+
{
24+
fixStyle: 'inline-type-imports',
25+
disallowTypeAnnotations: false,
26+
},
27+
],
28+
'@typescript-eslint/consistent-type-exports': [
29+
'warn',
30+
{ fixMixedExportsWithInlineTypeSpecifier: true },
31+
],
32+
// `import path from 'node:path'` incompatible with CJS runtime, prefer `import * as path from 'node:path'`
33+
'unicorn/import-style': [
34+
'warn',
35+
{ styles: { 'node:path': { namespace: true } } },
36+
],
37+
// `import { logger } from '@nx/devkit' is OK here
38+
'no-restricted-imports': 'off',
39+
},
40+
},
541
{
642
files: ['**/*.json'],
743
rules: {
844
'@nx/dependency-checks': 'error',
945
},
1046
},
11-
];
47+
// Nx compiles the sync generators on the fly with SWC and there the .js ending is not working
48+
{
49+
files: ['**/sync-*.ts'],
50+
rules: {
51+
'n/file-extension-in-import': 'off',
52+
},
53+
},
54+
{
55+
files: ['**/package.json', '**/generators.json'],
56+
rules: {
57+
'@nx/nx-plugin-checks': 'error',
58+
},
59+
},
60+
);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"generators": {
3+
"sync-zod2md-setup": {
4+
"factory": "./src/lib/generators/sync-zod2md-setup/sync-zod2md-setup",
5+
"schema": "./src/lib/generators/sync-zod2md-setup/schema.json",
6+
"description": "sync-zod2md-setup generator"
7+
},
8+
"configuration": {
9+
"factory": "./src/lib/generators/configuration/configuration",
10+
"schema": "./src/lib/generators/configuration/schema.json",
11+
"description": "configuration generator"
12+
},
13+
"sync-zod2md-docs": {
14+
"factory": "./src/lib/generators/sync-zod2md-docs/sync-zod2md-docs",
15+
"schema": "./src/lib/generators/sync-zod2md-docs/schema.json",
16+
"description": "sync-zod2md-docs generator"
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)