Skip to content

Commit 14a0135

Browse files
committed
tmp
Signed-off-by: flakey5 <[email protected]>
1 parent 9be11fd commit 14a0135

24 files changed

+3788
-9
lines changed

package-lock.json

Lines changed: 120 additions & 8 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
@@ -46,6 +46,8 @@
4646
"hast-util-to-string": "^3.0.1",
4747
"hastscript": "^9.0.1",
4848
"html-minifier-terser": "^7.2.0",
49+
"json-schema-to-typescript": "^15.0.4",
50+
"jsonc-parser": "^3.3.1",
4951
"rehype-stringify": "^10.0.1",
5052
"remark-gfm": "^4.0.1",
5153
"remark-parse": "^11.0.0",

src/generators/index.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import legacyJsonAll from './legacy-json-all/index.mjs';
99
import addonVerify from './addon-verify/index.mjs';
1010
import apiLinks from './api-links/index.mjs';
1111
import oramaDb from './orama-db/index.mjs';
12+
import json from './json/index.mjs';
1213

1314
export default {
1415
'json-simple': jsonSimple,
@@ -20,4 +21,5 @@ export default {
2021
'addon-verify': addonVerify,
2122
'api-links': apiLinks,
2223
'orama-db': oramaDb,
24+
json: json,
2325
};

src/generators/json-all/index.mjs

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// @ts-check
2+
'use strict';
3+
4+
import { writeFile, readFile } from 'node:fs/promises';
5+
import { join } from 'node:path';
6+
import { parse as jsoncParse } from 'jsonc-parser';
7+
8+
// TODO add test w/ https://www.npmjs.com/package/jsonschema
9+
10+
/**
11+
* TODO docs
12+
*
13+
* @typedef {Array<ApiDocMetadataEntry>} Input
14+
*
15+
* @type {GeneratorMetadata<Input, Array<import('./generated.d.ts').NodeJsAPIDocumentationSchema>>}
16+
*/
17+
export default {
18+
name: 'json-all',
19+
20+
// This should be kept in sync with the JSON schema version
21+
version: '2.0.0',
22+
23+
description: 'TODO',
24+
25+
dependsOn: 'json',
26+
27+
/**
28+
* Generates a JSON file.
29+
*
30+
* @param {Input} input
31+
* @param {Partial<GeneratorOptions>} param1
32+
* @returns {Promise<any>}
33+
*/
34+
async generate(input, { output }) {
35+
const generatedValue = {
36+
$schema: './node-doc-all-schema.jsonc',
37+
modules: [],
38+
text: [],
39+
};
40+
41+
const propertiesToIgnore = ['$schema', 'source'];
42+
43+
input.forEach(section => {
44+
const copiedSection = {};
45+
46+
Object.keys(section).forEach(key => {
47+
if (!propertiesToIgnore.includes(key)) {
48+
copiedSection[key] = section[key];
49+
}
50+
});
51+
52+
switch (section.type) {
53+
case 'module':
54+
generatedValue.modules.push(copiedSection);
55+
break;
56+
case 'text':
57+
generatedValue.text.push(copiedSection);
58+
break;
59+
default:
60+
throw new TypeError(`unsupported root section type ${section.type}`);
61+
}
62+
});
63+
64+
if (output) {
65+
// Current directory path relative to the `index.mjs` file
66+
const baseDir = import.meta.dirname;
67+
68+
// Read the contents of the JSON schema
69+
const schemaString = await readFile(
70+
join(baseDir, 'schema.jsonc'),
71+
'utf8'
72+
);
73+
74+
// Parse the JSON schema into an object
75+
const schema = await jsoncParse(schemaString);
76+
77+
// Write the parsed JSON schema to the output directory
78+
// await writeFile(
79+
// join(output, 'node-doc-schema.json'),
80+
// JSON.stringify(schema)
81+
// );
82+
}
83+
84+
return generatedValue;
85+
},
86+
};

src/generators/json-all/schema.jsonc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"$id": "[email protected]", // This should be kept in sync with the generator version.
4+
"title": "Node.js API Documentation Schema (All)",
5+
"readOnly": true,
6+
7+
"properties": {
8+
"modules": {
9+
"type": "array",
10+
"items": { "$ref": "../json/schema.jsonc/#/definitions/Module" },
11+
},
12+
"text": {
13+
"type": "array",
14+
"items": { "$ref": "../json/schema.jsonc/#/definitions/Text" },
15+
},
16+
},
17+
}

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)