Skip to content

Commit 49a67bd

Browse files
committed
tmp
Signed-off-by: flakey5 <[email protected]>
1 parent 97b3495 commit 49a67bd

23 files changed

+2796
-100
lines changed

package-lock.json

Lines changed: 210 additions & 99 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@
5555
"reading-time": "^1.5.0",
5656
"recma-jsx": "^1.0.0",
5757
"rehype-recma": "^1.0.0",
58+
"json-schema-to-typescript": "^15.0.4",
59+
"jsonc-parser": "^3.3.1",
5860
"rehype-stringify": "^10.0.1",
5961
"remark-gfm": "^4.0.1",
6062
"remark-parse": "^11.0.0",

src/generators/index.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import legacyJsonAll from './legacy-json-all/index.mjs';
1212
import llmsTxt from './llms-txt/index.mjs';
1313
import manPage from './man-page/index.mjs';
1414
import oramaDb from './orama-db/index.mjs';
15+
import json from './json/index.mjs';
16+
import jsonAll from './json-all/index.mjs';
1517

1618
export const publicGenerators = {
1719
'json-simple': jsonSimple,
@@ -25,6 +27,8 @@ export const publicGenerators = {
2527
'orama-db': oramaDb,
2628
'llms-txt': llmsTxt,
2729
'jsx-ast': jsxAst,
30+
json,
31+
'json-all': jsonAll,
2832
};
2933

3034
export const allGenerators = {

src/generators/json-all/index.mjs

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// @ts-check
2+
'use strict';
3+
4+
import { writeFile } from 'node:fs/promises';
5+
import { join } from 'node:path';
6+
import { DOC_NODE_VERSION } from '../../constants.mjs';
7+
import { generateJsonSchema } from './util/generateJsonSchema.mjs';
8+
9+
// TODO add test w/ https://www.npmjs.com/package/jsonschema
10+
11+
/**
12+
* TODO docs
13+
*
14+
* @typedef {Array<ApiDocMetadataEntry>} Input
15+
*
16+
* @type {GeneratorMetadata<Input, object>}
17+
*/
18+
export default {
19+
name: 'json-all',
20+
21+
// This should be kept in sync with the JSON schema version for this
22+
// generator AND the `json` generator
23+
version: '2.0.0',
24+
25+
description: 'TODO',
26+
27+
dependsOn: 'json',
28+
29+
/**
30+
* Generates a JSON file.
31+
*
32+
* @param {Input} input
33+
* @param {Partial<GeneratorOptions>} param1
34+
* @returns {Promise<object>}
35+
*/
36+
async generate(input, { output }) {
37+
const generatedValue = {
38+
$schema: `https://nodejs.org/docs/${DOC_NODE_VERSION}/api/node-doc-all-schema.jsonc`,
39+
modules: [],
40+
text: [],
41+
};
42+
43+
const propertiesToIgnore = ['$schema', 'source'];
44+
45+
input.forEach(section => {
46+
const copiedSection = {};
47+
48+
Object.keys(section).forEach(key => {
49+
if (!propertiesToIgnore.includes(key)) {
50+
copiedSection[key] = section[key];
51+
}
52+
});
53+
54+
switch (section.type) {
55+
case 'module':
56+
generatedValue.modules.push(copiedSection);
57+
break;
58+
case 'text':
59+
generatedValue.text.push(copiedSection);
60+
break;
61+
default:
62+
throw new TypeError(`unsupported root section type ${section.type}`);
63+
}
64+
});
65+
66+
if (output) {
67+
const schema = generateJsonSchema();
68+
69+
// Write the parsed JSON schema to the output directory
70+
await writeFile(
71+
join(output, 'node-doc-schema.json'),
72+
JSON.stringify(schema)
73+
);
74+
}
75+
76+
return generatedValue;
77+
},
78+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// @ts-check
2+
'use strict';
3+
4+
import { DOC_NODE_VERSION } from '../../../constants.mjs';
5+
6+
const JSON_SCHEMA_URL = `https://nodejs.org/docs/${DOC_NODE_VERSION}/api/node-doc-schema.json`;
7+
8+
export const generateJsonSchema = () => ({
9+
$schema: 'http://json-schema.org/draft-07/schema#',
10+
// This should be kept in sync with the generator version for this generator
11+
// AND the `json` generator and schema
12+
$id: '[email protected]', // This should be kept in sync with the generator version.
13+
title: 'Node.js API Documentation Schema (All)',
14+
readOnly: true,
15+
16+
properties: {
17+
modules: {
18+
type: 'array',
19+
items: { $ref: `${JSON_SCHEMA_URL}/#/definitions/Module` },
20+
},
21+
text: {
22+
type: 'array',
23+
items: { $ref: `${JSON_SCHEMA_URL}/#/definitions/Text` },
24+
},
25+
},
26+
});

src/generators/json/constants.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
'use strict';

0 commit comments

Comments
 (0)