Skip to content

Commit a00a55a

Browse files
avivkellerflakey5
andcommitted
feat(json): add JSON generators
Co-Authored-By: flakey5 <73616808+flakey5@users.noreply.github.com> Signed-off-by: avivkeller <me@aviv.sh>
1 parent 2611469 commit a00a55a

68 files changed

Lines changed: 4474 additions & 563 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.changeset/json-generator.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@doc-kit/core': minor
3+
'@doc-kit/generator-react': patch
4+
'@node-core/doc-kit-legacy': patch
5+
---
6+
7+
feat: the `json` and `json-all` generators

.github/workflows/generate.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ jobs:
9494
- target: json-simple
9595
input: './node/doc/api/*.md'
9696

97+
- target: json
98+
input: './node/doc/api/*.md'
99+
compare: object-assertion
100+
97101
- target: legacy-json
98102
input: './node/doc/api/*.md'
99103
compare: object-assertion

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ www/out/
1616

1717
# Generated Files
1818
packages/core/src/generators/metadata/maps/mdn.json
19+
packages/core/src/generators/json/generated/
1920

2021
# The specification uses things that prettier would not
2122
# approve of, such as bullets with `*`

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,11 @@ Options:
6969
--config-file <path> Config file
7070
-i, --input <patterns...> Input file patterns (glob)
7171
-t, --target <generator...> Target generator(s): a built-in name
72-
(json-simple, legacy-html, legacy-html-all,
73-
man-page, legacy-json, legacy-json-all,
74-
addon-verify, api-links, orama-db, llms-txt,
75-
sitemap, html) or an import specifier for a
72+
(json, json-all, json-simple, legacy-html,
73+
legacy-html-all, man-page, legacy-json,
74+
legacy-json-all, addon-verify, api-links,
75+
orama-db, llms-txt, sitemap, html,
76+
section-pages) or an import specifier for a
7677
custom generator
7778
--ignore <patterns...> Ignore file patterns (glob)
7879
-o, --output <directory> The output directory

docs/generators.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ npx @doc-kit/cli generate -t html -t orama-db -t sitemap -i "docs/**/*.md" -o ou
2020

2121
### JSON ([`@doc-kit/core`](./packages/core.md))
2222

23-
| Target | Output |
24-
| -------------------------------------------- | -------------------------------------------------------- |
25-
| [`json-simple`](./generators/json-simple.md) | A simplified JSON rendering of the parsed documentation. |
23+
| Target | Output |
24+
| -------------------------------------------- | ------------------------------------------------------------------ |
25+
| [`json`](./generators/json.md) | One schema-described JSON document per source file. |
26+
| [`json-all`](./generators/json-all.md) | Those documents bundled into a single `all.json`. |
27+
| [`json-simple`](./generators/json-simple.md) | A dump of the parsed metadata entries, for debugging the pipeline. |
2628

2729
### Legacy ([`@node-core/doc-kit-legacy`](./packages/node-legacy.md))
2830

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"eslint-plugin-react-x": "5.18.6",
4545
"globals": "~17.7.0",
4646
"husky": "9.1.7",
47+
"json-schema-to-typescript": "^16.0.0",
4748
"lint-staged": "17.4.1",
4849
"prettier": "3.9.6"
4950
}

packages/core/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ The command-line interface lives in the companion
1010
## Generators
1111

1212
Output formats are provided by generators. This package ships the shared
13-
pipeline stages and `json-simple`; the rest come from companion packages:
13+
pipeline stages and the JSON generators (`json`, `json-all`, and the
14+
debugging-only `json-simple`); the rest come from companion packages:
1415

1516
| Package | Generators |
1617
| -------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- |

packages/core/package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
".": "./src/generators.mjs",
2121
"./ast": "./src/generators/ast/index.mjs",
2222
"./ast-js": "./src/generators/ast-js/index.mjs",
23+
"./json": "./src/generators/json/index.mjs",
24+
"./json-all": "./src/generators/json-all/index.mjs",
2325
"./json-simple": "./src/generators/json-simple/index.mjs",
2426
"./metadata": "./src/generators/metadata/index.mjs",
2527
"./package.json": "./package.json",
@@ -59,6 +61,8 @@
5961
"github-slugger": "^2.0.0",
6062
"glob-parent": "^6.0.2",
6163
"hastscript": "^9.0.1",
64+
"mdast-util-slice-markdown": "^2.0.1",
65+
"mdast-util-to-string": "^4.0.0",
6266
"piscina": "^5.3.1",
6367
"rehype-stringify": "^10.0.1",
6468
"remark-gfm": "^4.0.1",
@@ -79,13 +83,14 @@
7983
"yaml": "^2.9.0"
8084
},
8185
"devDependencies": {
86+
"ajv": "^8.20.0",
8287
"hast-util-to-html": "^9.0.5",
8388
"hast-util-to-string": "^3.0.1"
8489
},
8590
"peerDependencies": {
91+
"@doc-kit/generator-react": "workspace:>=0.1.0",
8692
"@node-core/doc-kit": "workspace:>=2.0.0",
87-
"@node-core/doc-kit-legacy": "workspace:>=1.0.0",
88-
"@doc-kit/generator-react": "workspace:>=0.1.0"
93+
"@node-core/doc-kit-legacy": "workspace:>=1.0.0"
8994
},
9095
"peerDependenciesMeta": {
9196
"@node-core/doc-kit": {

packages/core/src/generators/index.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
* which is how third-party generator packages are loaded.
1111
*/
1212
export const publicGenerators = {
13+
json: '@doc-kit/core/json',
14+
'json-all': '@doc-kit/core/json-all',
1315
'json-simple': '@doc-kit/core/json-simple',
1416
'legacy-html': '@node-core/doc-kit-legacy/legacy-html',
1517
'legacy-html-all': '@node-core/doc-kit-legacy/legacy-html-all',
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# `json-all` Generator
2+
3+
The `json-all` generator bundles the documents of the [`json`](./json.md)
4+
generator into a single `all.json` file.
5+
6+
```sh
7+
npx @doc-kit/cli generate -t json-all -i "doc/api/*.md" -o out --index doc/api/index.md
8+
```
9+
10+
```json
11+
{
12+
"$schema": "https://doc-kit.nodejs.org/schemas/api-doc-all/1.0.0.json",
13+
"documents": []
14+
}
15+
```
16+
17+
`documents` holds every document in the order of the configured `index`,
18+
then the rest by `id`. The bundle's schema, shipped as
19+
`@doc-kit/core/generators/json-all/schema.json`, refers to the `json`
20+
generator's schema for the documents.
21+
22+
## Configuring
23+
24+
- `output` {string} The directory where `all.json` will be written.
25+
- `minify` {boolean} Whether to minify the output. Inherited from `global`.
26+
**Default:** `true`.
27+
- `index` {Array} The `{ api }` objects defining the document order. Inherited
28+
from `global`.
29+
- `schemaURL` {string} Where the bundle's schema is published.
30+
`{schemaVersion}` is filled in. **Default:**
31+
`'https://doc-kit.nodejs.org/schemas/api-doc-all/{schemaVersion}.json'`.

0 commit comments

Comments
 (0)