Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 52 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ Here's an example of it being used along with VSCode's eslint plugin, with auto-
- [Usage with eslint-plugin-markdown](#usage-with-eslint-plugin-markdown)
- [Presets](#presets)
- [custom](#custom)
- [copy](#copy)
- [excludeLines](#excludelines)
- [onlyIfExists](#onlyifexists)
- [comparison](#comparison)
- [barrel](#barrel)
- [markdownFromJsdoc](#markdownfromjsdoc)
- [monorepoTOC](#monorepotoc)
Expand Down Expand Up @@ -139,7 +143,7 @@ module.exports = {
### Presets

<!-- codegen:start {preset: markdownFromJsdoc, source: src/presets/custom.ts, export: custom} -->
#### [custom](./src/presets/custom.ts#L61)
#### [custom](./src/presets/custom.ts#L62)

Define your own codegen function, which will receive all options specified. Import the `Preset` type from this library to define a strongly-typed preset function:

Expand Down Expand Up @@ -284,6 +288,52 @@ module.exports.myGenerator = ({dependencies}) => {
##### Demo

![](./gifs/custom.gif)

<!-- codegen:start {preset: markdownFromJsdoc, source: src/presets/copy.ts, export: copy} -->
#### [copy](./src/presets/copy.ts#L53)

Copies a whole other file. Useful for "borrowing" an implementation of a simple utility from another project, without needing to publish it. Obviously this creates duplicated code, so use judiciously!

##### basic usage
```js
// codegen:start {preset: copy, source: ../../another-project/src/some-file.ts} import {z} from 'zod' export const MyObject = z.object({ foo: z.string() })
// codegen:end
```

#### excludeLines

```ts
import {z} from 'zod/v4' // in this project we use zod v4, but we're copying from a project that uses zod v3
// codegen:start {preset: copy, source: ../../another-project/src/some-file.ts, excludeLines: ['^import']}
export const MyObject = z.object({foo: z.string()})
// codegen:end
```

#### onlyIfExists
```js
// copy a file from a sibling project, but only if the sibling project actually exists
// in this case this will effectively skip the copying step on machines that don't have the sibling project installed
// e.g. on CI runners.
// codegen:start {preset: copy, source: ../../another-project/src/some-file.ts, onlyIfExists: ../../another-project/package.json}
import {z} from 'zod'

export const MyObject = z.object({foo: z.string()})
// codegen:end
```

#### comparison
```js
// by default, the content will perform a "simplified" comparison with existing content, so differences from tools like prettier
// are ignored. if you care about whitespace and similar differences, you can set the comparison option to `strict`.
// codegen:start {preset: copy, source: ../../another-project/src/some-file.ts, comparison: strict}
import {z} from 'zod'

export const MyObject = z.object({foo: z.string()})
// codegen:end
```
<!-- codegen:end -->


<!-- codegen:start {preset: markdownFromJsdoc, source: src/presets/barrel.ts, export: barrel} -->
#### [barrel](./src/presets/barrel.ts#L38)

Expand Down Expand Up @@ -315,7 +365,7 @@ export * from './some/path/module-c'
![](./gifs/barrel.gif)

<!-- codegen:start {preset: markdownFromJsdoc, source: src/presets/markdown-from-jsdoc.ts, export: markdownFromJsdoc} -->
#### [markdownFromJsdoc](./src/presets/markdown-from-jsdoc.ts#L20)
#### [markdownFromJsdoc](./src/presets/markdown-from-jsdoc.ts#L21)

Convert jsdoc for an es export from a javascript/typescript file to markdown.

Expand Down
17 changes: 10 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,21 @@
"e2e": "playwright test"
},
"dependencies": {
"@babel/core": "^7.11.6",
"@babel/generator": "~7.12.0",
"@babel/parser": "^7.11.5",
"@babel/traverse": "^7.11.5",
"@babel/core": "^7.27.1",
"@babel/generator": "^7.27.1",
"@babel/parser": "^7.27.1",
"@babel/traverse": "^7.27.1",
"@babel/types": "^7.27.1",
"@pnpm/deps.graph-sequencer": "^1.0.0",
"@types/babel__core": "^7.20.5",
"@types/babel__generator": "^7.27.0",
"@types/dedent": "0.7.0",
"@types/eslint": "^8.44.7",
"@types/glob": "7.1.3",
"@types/js-yaml": "3.12.5",
"@types/lodash": "^4.14.202",
"@types/node": "^20.0.0",
"arktype": "^2.1.20",
"cheerio": "^1.0.0",
"dedent": "^1.5.1",
"eslint-plugin-markdown": "^4.0.1",
Expand All @@ -59,13 +63,12 @@
"ms": "^2.1.3",
"read-pkg-up": "^7.0.1",
"safe-stringify": "^1.1.0",
"strip-ansi": "6.0.1"
"strip-ansi": "6.0.1",
"zod": "^3.25.48"
},
"devDependencies": {
"@babel/types": "7.12.11",
"@eslint/config-inspector": "^0.4.11",
"@playwright/test": "^1.40.0",
"@types/babel__generator": "7.6.2",
"@types/babel__traverse": "7.11.0",
"@types/dedent": "0.7.0",
"@types/glob": "7.1.3",
Expand Down
Loading