Skip to content

Commit 299203b

Browse files
committed
refactor: setup sync generator
1 parent 1fc70d5 commit 299203b

35 files changed

+1266
-33
lines changed

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"]
1410
},
1511
"lint": {},
1612
"unit-test": {},

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { libraryGenerator } from '@nx/js';
1111
import type { LibraryGeneratorSchema } from '@nx/js/src/generators/library/schema';
1212
import 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,11 @@ export async function nxShowProjectJson<T extends ProjectConfiguration>(
9595
cwd: string,
9696
project: string,
9797
) {
98-
const { code, stderr, stdout } = await executeProcess({
98+
const { stderr, stdout } = await executeProcess({
9999
command: 'npx',
100100
args: ['nx', 'show', `project --json ${project}`],
101101
cwd,
102102
});
103103

104-
return { code, stderr, projectJson: JSON.parse(stdout) as T };
104+
return { stderr, projectJson: JSON.parse(stdout) as T };
105105
}

testing/test-utils/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ export * from './lib/utils/file-system.js';
1010
export * from './lib/utils/create-npm-workshpace.js';
1111
export * from './lib/utils/project-graph.js';
1212
export * from './lib/utils/test-folder-setup.js';
13+
export * from './lib/utils/execute-process.js';
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { execFile } from 'node:child_process';
2+
import { promisify } from 'node:util';
3+
4+
export async function executeProcess(cfg: {
5+
command: string;
6+
args: string[];
7+
cwd: string;
8+
}) {
9+
const execFileAsync = promisify(execFile);
10+
const { command, args, cwd } = cfg;
11+
return await execFileAsync(command, args, { cwd });
12+
}
Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,53 @@
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+
{
48+
files: ['**/package.json', '**/generators.json'],
49+
rules: {
50+
'@nx/nx-plugin-checks': 'error',
51+
},
52+
},
53+
);
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+
}

tools/zod2md-jsdocs/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
"type": "commonjs",
66
"main": "./src/index.js",
77
"dependencies": {
8+
"@nx/devkit": "22.3.3",
89
"ts-patch": "^3.3.0",
910
"typescript": "5.7.3",
10-
"@nx/devkit": "22.3.3"
11+
"zod2md": "^0.2.4"
1112
},
1213
"files": [
1314
"src"
14-
]
15+
],
16+
"generators": "./generators.json"
1517
}

tools/zod2md-jsdocs/project.json

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,53 @@
44
"sourceRoot": "tools/zod2md-jsdocs/src",
55
"projectType": "library",
66
"targets": {
7-
"lint": {},
8-
"build": {},
7+
"build": {
8+
"options": {
9+
"assets": [
10+
"{projectRoot}/*.md",
11+
{
12+
"input": "./tools/zod2md-jsdocs/src",
13+
"glob": "**/!(*.ts)",
14+
"output": "./src"
15+
},
16+
{
17+
"input": "./tools/zod2md-jsdocs/src",
18+
"glob": "**/*.d.ts",
19+
"output": "./src"
20+
},
21+
{
22+
"input": "./tools/zod2md-jsdocs",
23+
"glob": "generators.json",
24+
"output": "."
25+
},
26+
{
27+
"input": "./tools/zod2md-jsdocs",
28+
"glob": "executors.json",
29+
"output": "."
30+
}
31+
]
32+
}
33+
},
34+
"lint": {
35+
"options": {
36+
"lintFilePatterns": [
37+
"tools/zod2md-jsdocs/**/*.ts",
38+
"tools/zod2md-jsdocs/package.json",
39+
"tools/zod2md-jsdocs/generators.json"
40+
]
41+
}
42+
},
43+
"lint-report": {
44+
"options": {
45+
"lintFilePatterns": [
46+
"tools/zod2md-jsdocs/**/*.ts",
47+
"tools/zod2md-jsdocs/package.json",
48+
"tools/zod2md-jsdocs/generators.json"
49+
]
50+
}
51+
},
952
"unit-test": {},
53+
"int-test": {},
1054
"ts-patch": {
1155
"command": "ts-patch install",
1256
"cache": true,
@@ -17,5 +61,6 @@
1761
}
1862
]
1963
}
20-
}
64+
},
65+
"tags": ["scope:tooling", "type:feature", "publishable"]
2166
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Configuration Generator
2+
3+
#### @zod2md/nx-plugin:configuration
4+
5+
## Usage
6+
7+
`nx generate @zod2md/nx-plugin:configuration`
8+
9+
By default, the Nx plugin will search for existing configuration files. If they are not present it creates a `zod2md.config.ts` and adds a target to your `project.json` file.
10+
11+
You can specify the project explicitly as follows:
12+
13+
`nx g @zod2md/nx-plugin:configuration <project-name>`
14+
15+
```text
16+
Root/
17+
├── project-name/
18+
│ ├── project.json 👈 updated
19+
│ ├── zod2md.config.ts 👈 generated
20+
│ └── ...
21+
└── ...
22+
```
23+
24+
Show what will be generated without writing to disk:
25+
26+
`nx g configuration ... --dry-run`
27+
28+
## Options
29+
30+
| Name | type | description |
31+
| ----------------- | --------------------------- | ------------------------------------------------------ |
32+
| **--project** | `string` (REQUIRED) | The name of the project. |
33+
| **--targetName** | `string` (DEFAULT 'zod2md') | The id used to identify a target in your project.json. |
34+
| **--bin** | `string` | Path to Code PushUp CLI |
35+
| **--skipProject** | `boolean` (DEFAULT false) | Skip adding the target to `project.json`. |
36+
| **--skipConfig** | `boolean` (DEFAULT false) | Skip adding the `zod2md.config.ts` to project root. |

0 commit comments

Comments
 (0)