Skip to content

Commit b88e660

Browse files
committedMar 9, 2024
add monorepoTOC filter docs
1 parent 3a31e2d commit b88e660

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed
 

‎README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ Convert jsdoc for an es export from a javascript/typescript file to markdown.
223223
<!-- codegen:end -->
224224
225225
<!-- codegen:start {preset: markdownFromJsdoc, source: src/presets/monorepo-toc.ts, export: monorepoTOC} -->
226-
#### [monorepoTOC](./src/presets/monorepo-toc.ts#L30)
226+
#### [monorepoTOC](./src/presets/monorepo-toc.ts#L37)
227227
228228
Generate a table of contents for a monorepo.
229229
@@ -237,11 +237,11 @@ Generate a table of contents for a monorepo.
237237
238238
##### Params
239239
240-
|name |description |
241-
|--------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
242-
|repoRoot|[optional] the relative path to the root of the git repository. By default, searches parent directories for a package.json to find the "root". |
243-
|filter |[optional] a dictionary of filter rules to whitelist packages. Filters can be applied based on package.json keys,<br />e.g. `filter: { package.name: someRegex, path: some/relative/path }`|
244-
|sort |[optional] sort based on package properties (see `filter`), or readme length. Use `-` as a prefix to sort descending.<br />e.g. `sort: -readme.length` |
240+
|name |description |
241+
|--------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
242+
|repoRoot|[optional] the relative path to the root of the git repository. By default, searches parent directories for a package.json to find the "root". |
243+
|filter |[optional] a dictionary of filter rules to whitelist packages. Filters can be applied based on package.json keys,<br /><br />examples:<br />- `filter: '@myorg/.*-lib'` (match packages with names matching this regex)<br />- `filter: { package.name: '@myorg/.*-lib' }` (equivalent to the above)<br />- `filter: { package.version: '^[1-9].*' }` (match packages with versions starting with a non-zero digit, i.e. 1.0.0+)<br />- `filter: '^(?!.*(internal$))'` (match packages that do not contain "internal" anywhere (using [negative lookahead](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Lookahead_assertion)))<br />- `filter: { package.name: '@myorg', path: 'libraries' }` (match packages whose name contains "@myorg" and whose path matches "libraries")<br />- `filter: { readme: 'This is production-ready' }` (match packages whose readme contains the string "This is production-ready")|
244+
|sort |[optional] sort based on package properties (see `filter`), or readme length. Use `-` as a prefix to sort descending.<br />e.g. `sort: -readme.length` |
245245
<!-- codegen:end -->
246246
247247
##### Demo

‎src/presets/monorepo-toc.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,14 @@ import {relative} from './util/path'
2222
* [optional] the relative path to the root of the git repository. By default, searches parent directories for a package.json to find the "root".
2323
* @param filter
2424
* [optional] a dictionary of filter rules to whitelist packages. Filters can be applied based on package.json keys,
25-
* e.g. `filter: { package.name: someRegex, path: some/relative/path }`
25+
*
26+
* examples:
27+
* - `filter: '@myorg/.*-lib'` (match packages with names matching this regex)
28+
* - `filter: { package.name: '@myorg/.*-lib' }` (equivalent to the above)
29+
* - `filter: { package.version: '^[1-9].*' }` (match packages with versions starting with a non-zero digit, i.e. 1.0.0+)
30+
* - `filter: '^(?!.*(internal$))'` (match packages that do not contain "internal" anywhere (using [negative lookahead](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Lookahead_assertion)))
31+
* - `filter: { package.name: '@myorg', path: 'libraries' }` (match packages whose name contains "@myorg" and whose path matches "libraries")
32+
* - `filter: { readme: 'This is production-ready' }` (match packages whose readme contains the string "This is production-ready")
2633
* @param sort
2734
* [optional] sort based on package properties (see `filter`), or readme length. Use `-` as a prefix to sort descending.
2835
* e.g. `sort: -readme.length`
@@ -41,7 +48,7 @@ export const monorepoTOC: Preset<{
4148
const readme = [readmePath && fs.readFileSync(readmePath).toString(), leafPkg.description]
4249
.filter(Boolean)
4350
.join(os.EOL + os.EOL)
44-
return {package: leafPkg, leafPath, readme}
51+
return {package: leafPkg, path: leafPath, readme}
4552
})
4653
.filter(props => {
4754
const filter = typeof options.filter === 'object' ? options.filter : {'package.name': options.filter!}
@@ -60,7 +67,7 @@ export const monorepoTOC: Preset<{
6067
const comp = a < b ? -1 : a > b ? 1 : 0
6168
return comp * multiplier
6269
})
63-
.map(props => ({leafPath: props.leafPath, leafPkg: props.package, readme: props.readme}))
70+
.map(props => ({leafPath: props.path, leafPkg: props.package, readme: props.readme}))
6471
.map(({leafPath, leafPkg, readme}) => {
6572
const description = (() => {
6673
return readme

0 commit comments

Comments
 (0)
Please sign in to comment.