Skip to content

Commit 594f451

Browse files
author
John Doe
committed
refactor: add zod2md-nx-plugin
1 parent 867c80d commit 594f451

8 files changed

Lines changed: 152 additions & 14 deletions

File tree

nx.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@
337337
"releaseTagPattern": "v{version}"
338338
},
339339
"plugins": [
340+
"./tools/zod2md-nx-plugin/src/lib/plugin.js",
340341
{
341342
"plugin": "@push-based/nx-verdaccio",
342343
"options": {

packages/models/project.json

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,6 @@
44
"sourceRoot": "packages/models/src",
55
"projectType": "library",
66
"targets": {
7-
"generate-docs": {
8-
"executor": "nx:run-commands",
9-
"options": {
10-
"commands": [
11-
"zod2md --config {projectRoot}/zod2md.config.ts",
12-
"prettier --write {projectRoot}/docs/models-reference.md"
13-
],
14-
"parallel": false
15-
},
16-
"cache": true,
17-
"inputs": ["production", "^production", "{projectRoot}/zod2md.config.ts"],
18-
"outputs": ["{projectRoot}/docs/models-reference.md"]
19-
},
207
"build": {
218
"dependsOn": [
229
"^build",

tools/zod2md-nx-plugin/README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# @code-pushup/zod2md-nx-plugin
2+
3+
[![npm](https://img.shields.io/npm/v/%40code-pushup%2Futils.svg)](https://www.npmjs.com/package/@code-pushup/zod2md-nx-plugin)
4+
[![downloads](https://img.shields.io/npm/dm/%40code-pushup%2Futils)](https://npmtrends.com/@code-pushup/zod2md-nx-plugin)
5+
[![dependencies](https://img.shields.io/librariesio/release/npm/%40code-pushup/utils)](https://www.npmjs.com/package/@code-pushup/zod2md-nx-plugin?activeTab=dependencies)
6+
7+
Low-level **utilities** (helper functions, etc.) used by [Code PushUp CLI](../cli/README.md).
8+
9+
## Setup
10+
11+
If you've already installed another `@code-pushup/*` package, then you may have already installed `@code-pushup/zod2md-nx-plugin` indirectly.
12+
13+
If not, you can always install it separately:
14+
15+
```sh
16+
npm install --save-dev @code-pushup/zod2md-nx-plugin
17+
```
18+
19+
```sh
20+
yarn add --dev @code-pushup/zod2md-nx-plugin
21+
```
22+
23+
```sh
24+
pnpm add --save-dev @code-pushup/zod2md-nx-plugin
25+
```
26+
27+
## Usage
28+
29+
```ts
30+
import { executeProcess, readJsonFile, slugify } from '@code-pushup/zod2md-nx-plugin';
31+
32+
await executeProcess({
33+
command: 'npx',
34+
args: ['eslint', '--format=json', '--output-file=output.json', '**/*.js'],
35+
});
36+
37+
const data = await readJsonFile('output.json');
38+
39+
const slug = slugify('Hello, world!'); // "hello-world"
40+
```
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import tseslint from 'typescript-eslint';
2+
import baseConfig from '../../eslint.config.js';
3+
4+
export default tseslint.config(
5+
...baseConfig,
6+
{
7+
files: ['**/*.ts'],
8+
languageOptions: {
9+
parserOptions: {
10+
projectService: true,
11+
tsconfigRootDir: import.meta.dirname,
12+
},
13+
},
14+
},
15+
{
16+
files: ['**/*.json'],
17+
rules: {
18+
'@nx/dependency-checks': ['error', { ignoredDependencies: [] }],
19+
},
20+
},
21+
);
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "@code-pushup/zod2md-nx-plugin",
3+
"version": "0.0.0",
4+
"license": "MIT",
5+
"homepage": "https://github.com/code-pushup/cli/tree/main/tools/zod2md-nx-plugin#readme",
6+
"publishConfig": {
7+
"access": "public"
8+
},
9+
"type": "module",
10+
"engines": {
11+
"node": ">=17.0.0"
12+
},
13+
"dependencies": {
14+
"@code-pushup/models": "0.92.0",
15+
"ansis": "^3.3.0",
16+
"build-md": "^0.4.2",
17+
"bundle-require": "^5.1.0",
18+
"esbuild": "^0.25.2",
19+
"ora": "^9.0.0",
20+
"semver": "^7.6.0",
21+
"simple-git": "^3.20.0",
22+
"string-width": "^8.1.0",
23+
"wrap-ansi": "^9.0.2",
24+
"zod": "^4.0.5"
25+
},
26+
"files": [
27+
"src",
28+
"!**/*.tsbuildinfo"
29+
]
30+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "zod2md-nx-plugin",
3+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
4+
"sourceRoot": "tools/zod2md-nx-plugin/src",
5+
"projectType": "library",
6+
"targets": {
7+
"lint": {}
8+
},
9+
"tags": ["scope:shared", "type:util", "publishable"]
10+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { dirname } from 'node:path';
2+
3+
export const createNodesV2 = [
4+
`**/zod2md.config.ts`,
5+
async (zod2MdConfigurationFiles, createNodesOptions, context) => {
6+
return Promise.all(
7+
zod2MdConfigurationFiles.map(async zod2MdConfigurationFile => {
8+
const projectRoot = dirname(zod2MdConfigurationFile);
9+
const normalizedProjectRoot = projectRoot === '.' ? '' : projectRoot;
10+
const result = {
11+
projects: {
12+
[normalizedProjectRoot]: {
13+
targets: {
14+
'generate-docs': {
15+
executor: 'nx:run-commands',
16+
options: {
17+
commands: [
18+
'zod2md --config {projectRoot}/zod2md.config.ts',
19+
'prettier --write {projectRoot}/docs/{projectName}-reference.md',
20+
],
21+
parallel: false,
22+
},
23+
cache: true,
24+
inputs: [
25+
'production',
26+
'^production',
27+
'{projectRoot}/zod2md.config.ts',
28+
],
29+
outputs: ['{projectRoot}/docs/{projectName}-reference.md'],
30+
},
31+
},
32+
},
33+
},
34+
};
35+
36+
return [zod2MdConfigurationFile, result];
37+
}),
38+
);
39+
},
40+
];
41+
42+
// default export for nx.json#plugins
43+
const plugin = {
44+
name: 'zod2md-nx-plugin',
45+
createNodesV2,
46+
};
47+
48+
export default plugin;

tsconfig.base.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@
4747
"@code-pushup/typescript-plugin": [
4848
"packages/plugin-typescript/src/index.ts"
4949
],
50-
"@code-pushup/utils": ["packages/utils/src/index.ts"]
50+
"@code-pushup/utils": ["packages/utils/src/index.ts"],
51+
"@code-pushup/zod2md-nx-plugin": ["tools/zod2md-nx-plugin/src/index.ts"]
5152
}
5253
},
5354
"exclude": ["node_modules", "tmp"]

0 commit comments

Comments
 (0)