-
Notifications
You must be signed in to change notification settings - Fork 15
chore: add zod2md-nx-plugin #1162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
BioPhoton
wants to merge
52
commits into
main
Choose a base branch
from
chore/add-zod2md-nx-plugin
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
867c80d
refactor: move models-transformers into tools
594f451
refactor: add zod2md-nx-plugin
00256ee
refactor: wip
9112bf0
refactor: adjust plugin code
c7882cb
refactor: wip
1cf9a7a
refactor: wip
12a12d5
refactor: wip
4d629f4
refactor: wip
fb004e1
refactor: wip
8253323
Update tools/zod2md-nx-plugin/eslint.config.js
BioPhoton 670b232
Update tools/zod2md-nx-plugin/README.md
BioPhoton a4cf4b9
refactor: wip
b02a6a0
refactor: wip
4d6c335
refactor: wip
ce500c7
refactor: wip
1a158f1
Merge branch 'main' into chore/add-zod2md-nx-plugin
25c79f4
Merge remote-tracking branch 'origin/main' into chore/add-zod2md-nx-p…
1daa238
Merge branch 'main' into chore/add-zod2md-nx-plugin
9068301
refactor: wip
c0385c4
refactor: wip
df9cdd2
refactor: wip
765ff26
refactor: wip
c332127
refactor: wip
551b791
refactor: wip
7f32330
refactor: wip
3598f8a
refactor: wip
8d90f87
refactor: wip
0180436
Update eslint.config.js
BioPhoton e4a4864
Update tools/zod2md-jsdocs/docs/zod2md-jsdocs-ts-transformer.md
BioPhoton 880e997
refactor: remove disabled rules
8db0605
refactor: use esm syntax
0afd552
Merge branch 'refs/heads/main' into chore/add-zod2md-nx-plugin
c022da1
refactor: add back input rule for zod2md config
3fc4b33
refactor: fix README.md
806c743
refactor: remove deps
c0f0423
refactor: move ts-patch target to zod2md-jsdocs
df99141
refactor: adjust exports
a5e0547
refactor: fix plugin in ts format npm issues
35df593
refactor: fix typing
b2c3729
refactor: fix docs
14649d8
refactor: fix docs
3b16810
Merge branch 'main' into chore/add-zod2md-nx-plugin
0064e04
refactor: wip
f918b5c
refactor: wip
918fa8d
refactor: lock versions
e5b8c2c
refactor: revert lock versions
34eed75
refactor: update nx versions
c9d546d
refactor: update nx versions 2
3fc54f6
refactor: update nx versions 2
ff6c610
refactor: fix Nx update
fa94f93
refactor: fix Nx update unit tests
e88d62d
refactor: fix Nx update lint
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| # @code-pushup/zod2md-nx-plugin | ||
|
|
||
| The Nx Plugin for [zod2md](https://github.com/code-pushup/zod2md), a tool for generating documentation from Zod schemas. | ||
|
|
||
| Why should you use this plugin? | ||
|
|
||
| - Zero setup cost. Just add a `zod2md.config.ts` file and you're good to go. | ||
| - Automatic target generation | ||
| - Minimal configuration | ||
| - Automated caching and dependency tracking | ||
|
|
||
| ## Usage | ||
|
|
||
| ```jsonc | ||
| // nx.json | ||
| { | ||
| //... | ||
| "plugins": ["./tools/zod2md-nx-plugin/src/lib/plugin.js"], | ||
| } | ||
| ``` | ||
|
|
||
| or with options: | ||
|
|
||
| ```jsonc | ||
| // nx.json | ||
| { | ||
| //... | ||
| "plugins": [ | ||
| { | ||
| "plugin": "./tools/zod2md-nx-plugin/src/lib/plugin.js", | ||
| "options": { | ||
| "targetName": "zod-docs", | ||
| }, | ||
| }, | ||
| ], | ||
| } | ||
| ``` | ||
|
|
||
| Now every project with a `zod2md.config.ts` file will have a `generate-docs` target automatically created. | ||
|
|
||
| - `nx run <project-name>:generate-docs` | ||
|
|
||
| Run it and the project will automatically generate documentation from your Zod schemas. | ||
|
|
||
| ```text | ||
| Root/ | ||
| ├── project-name/ | ||
| │ ├── zod2md.config.ts | ||
| │ ├── docs/ | ||
| │ │ └── project-name-reference.md 👈 generated | ||
| │ └── ... | ||
| └── ... | ||
| ``` | ||
|
|
||
| The generated target: | ||
|
|
||
| 1. Runs `zod2md` with the project's configuration | ||
| 2. Formats the generated markdown with Prettier | ||
| 3. Caches the result for better performance | ||
|
|
||
| ### Passing zod2md options | ||
|
|
||
| You can override the config and output paths when running the target: | ||
|
|
||
| ```bash | ||
| # Use custom output file | ||
| nx generate-docs my-project --output=docs/custom-api.md | ||
|
|
||
| # Use custom config file | ||
| nx generate-docs my-project --config=custom-zod2md.config.ts | ||
|
|
||
| # Use both | ||
| nx generate-docs my-project --config=custom.config.ts --output=docs/api.md | ||
| ``` | ||
|
|
||
| Default values: | ||
|
|
||
| - `config`: `{projectRoot}/zod2md.config.ts` | ||
| - `output`: `{projectRoot}/docs/{projectName}-reference.md` | ||
|
|
||
| ## Options | ||
|
|
||
| | Name | type | description | | ||
| | -------------- | ---------------------------------- | ------------------------------------------------------ | | ||
| | **targetName** | `string` (DEFAULT 'generate-docs') | The id used to identify a target in your project.json. | | ||
|
|
||
| All options are optional and provided in the `nx.json` file. | ||
|
|
||
| ```jsonc | ||
| // nx.json | ||
| { | ||
| //... | ||
| "plugins": [ | ||
| { | ||
| "plugin": "./tools/zod2md-nx-plugin/src/lib/plugin.js", | ||
| "options": { | ||
| "targetName": "docs", | ||
| }, | ||
| }, | ||
| ], | ||
| } | ||
| ``` | ||
|
|
||
| ## Configuration | ||
|
|
||
| Create a `zod2md.config.ts` file in your project: | ||
|
|
||
| ```ts | ||
| import type { Config } from 'zod2md'; | ||
|
|
||
| export default { | ||
| entry: 'packages/models/src/index.ts', | ||
| tsconfig: 'packages/models/tsconfig.lib.json', | ||
| format: 'esm', | ||
| title: 'Models reference', | ||
| output: 'packages/models/docs/models-reference.md', | ||
| } satisfies Config; | ||
| ``` | ||
|
|
||
| For a full list of configuration options visit the [zod2md documentation](https://github.com/matejchalk/zod2md?tab=readme-ov-file#configuration). | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import tseslint from 'typescript-eslint'; | ||
| import baseConfig from '../../eslint.config.js'; | ||
|
|
||
| export default tseslint.config( | ||
| ...baseConfig, | ||
| { | ||
| files: ['**/*.ts'], | ||
| languageOptions: { | ||
| parserOptions: { | ||
| projectService: true, | ||
| tsconfigRootDir: import.meta.dirname, | ||
| }, | ||
| }, | ||
| }, | ||
| { | ||
| files: ['**/*.json'], | ||
| rules: { | ||
| '@nx/dependency-checks': ['error', { ignoredDependencies: [] }], | ||
| }, | ||
| }, | ||
BioPhoton marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| { | ||
| "name": "@code-pushup/zod2md-nx-plugin", | ||
| "version": "0.0.0", | ||
| "license": "MIT", | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
BioPhoton marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "type": "module", | ||
| "engines": { | ||
| "node": ">=17.0.0" | ||
| }, | ||
| "dependencies": {}, | ||
| "files": [ | ||
| "src", | ||
| "!**/*.tsbuildinfo" | ||
| ] | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "name": "zod2md-nx-plugin", | ||
| "$schema": "../../node_modules/nx/schemas/project-schema.json", | ||
| "sourceRoot": "tools/zod2md-nx-plugin/src", | ||
| "projectType": "library", | ||
| "targets": { | ||
| "lint": {} | ||
| }, | ||
| "tags": ["scope:shared", "type:util"] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import { dirname } from 'node:path'; | ||
|
|
||
| export const createNodesV2 = [ | ||
| `**/zod2md.config.ts`, | ||
| async (zod2MdConfigurationFiles, createNodesOptions, context) => { | ||
BioPhoton marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const options = createNodesOptions ?? {}; | ||
| const targetName = options.targetName ?? 'generate-docs'; | ||
|
|
||
| return Promise.all( | ||
| zod2MdConfigurationFiles.map(async zod2MdConfigurationFile => { | ||
| const projectRoot = dirname(zod2MdConfigurationFile); | ||
| const normalizedProjectRoot = projectRoot === '.' ? '' : projectRoot; | ||
| const result = { | ||
| projects: { | ||
| [normalizedProjectRoot]: { | ||
| targets: { | ||
| [targetName]: { | ||
| executor: 'nx:run-commands', | ||
| options: { | ||
| commands: [ | ||
| 'zod2md --config {args.config} --output {args.output}', | ||
| 'prettier --write {args.output}', | ||
| ], | ||
| parallel: false, | ||
| config: '{projectRoot}/zod2md.config.ts', | ||
| output: '{projectRoot}/docs/{projectName}-reference.md', | ||
| }, | ||
| cache: true, | ||
| inputs: [ | ||
| 'production', | ||
| '^production', | ||
| '{projectRoot}/zod2md.config.ts', | ||
| ], | ||
| outputs: ['{projectRoot}/docs/{outputFile}'], | ||
BioPhoton marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| return [zod2MdConfigurationFile, result]; | ||
| }), | ||
| ); | ||
| }, | ||
| ]; | ||
|
|
||
| // default export for nx.json#plugins | ||
| const plugin = { | ||
| name: 'zod2md-nx-plugin', | ||
| createNodesV2, | ||
| }; | ||
|
|
||
| export default plugin; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.