Skip to content

Commit 71c56a7

Browse files
committed
tmp
1 parent 38649d3 commit 71c56a7

File tree

10 files changed

+331
-77
lines changed

10 files changed

+331
-77
lines changed

src/generators/json/generated.d.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ export type NodeJsAPIDocumentationSchema = DocumentRoot & (Module | Text);
1010
* A JavaScript module.
1111
*/
1212
export type Module = SectionBase & {
13-
type: "module";
13+
type: 'module';
1414
/**
1515
* https://jsdoc.app/tags-see
1616
*/
17-
"@see": string;
17+
'@see': string;
1818
/**
1919
* https://jsdoc.app/tags-module
2020
*/
21-
"@module": string;
21+
'@module': string;
2222
/**
2323
* Classes exported from this module.
2424
*/
@@ -39,8 +39,8 @@ export type Module = SectionBase & {
3939
*/
4040
export type NodeCoreVersion = string;
4141
export type Class = SectionBase & {
42-
type: "class";
43-
"@constructor"?: MethodSignature[];
42+
type: 'class';
43+
'@constructor'?: MethodSignature[];
4444
methods?: Method[];
4545
staticMethods?: Method[];
4646
properties?: Property[];
@@ -50,19 +50,19 @@ export type Class = SectionBase & {
5050
* A JavaScript function.
5151
*/
5252
export type Method = SectionBase & {
53-
type: "method";
53+
type: 'method';
5454
signatures: MethodSignature[];
5555
[k: string]: unknown;
5656
};
5757
/**
5858
* A property on a JavaScript object or class.
5959
*/
6060
export type Property = SectionBase & {
61-
type: "property";
61+
type: 'property';
6262
/**
6363
* JavaScript type of the property.
6464
*/
65-
"@type": string | [string, ...string[]];
65+
'@type': string | [string, ...string[]];
6666
/**
6767
* Is this property modifiable by user code?
6868
*/
@@ -88,23 +88,23 @@ export interface SectionBase {
8888
/**
8989
* Type of the section
9090
*/
91-
type: "module" | "class" | "method" | "property" | "text";
91+
type: 'module' | 'class' | 'method' | 'property' | 'text';
9292
/**
9393
* https://jsdoc.app/tags-name
9494
*/
95-
"@name": string;
95+
'@name': string;
9696
/**
9797
* Description of the section.
9898
*/
9999
description?: string;
100100
/**
101101
* https://jsdoc.app/tags-example
102102
*/
103-
"@example"?: string | string[];
103+
'@example'?: string | string[];
104104
/**
105105
* https://jsdoc.app/tags-deprecated
106106
*/
107-
"@deprecated"?: NodeCoreVersion[];
107+
'@deprecated'?: NodeCoreVersion[];
108108
stability?: Stability;
109109
/**
110110
* The changes this API has underwent.
@@ -113,7 +113,7 @@ export interface SectionBase {
113113
/**
114114
* https://jsdoc.app/tags-since
115115
*/
116-
"@since"?: NodeCoreVersion[];
116+
'@since'?: NodeCoreVersion[];
117117
/**
118118
* todo what does this describe lol
119119
*/
@@ -155,22 +155,22 @@ export interface MethodSignature {
155155
/**
156156
* The method signature's return type.
157157
*/
158-
"@returns"?: string | [string, ...string[]];
158+
'@returns'?: string | [string, ...string[]];
159159
[k: string]: unknown;
160160
}
161161
export interface MethodParameter {
162162
/**
163163
* Name of the parameter.
164164
*/
165-
"@name": string;
165+
'@name': string;
166166
/**
167167
* Type of the parameter
168168
*/
169-
"@type": string | [string, ...string[]];
169+
'@type': string | [string, ...string[]];
170170
description?: string;
171171
/**
172172
* The parameter's default value
173173
*/
174-
"@default"?: string;
174+
'@default'?: string;
175175
[k: string]: unknown;
176176
}

src/generators/json/index.mjs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ import { createSectionBuilder } from './utils/createSection.mjs';
2424
export default {
2525
name: 'json',
2626

27-
version: '1.0.0',
27+
// This should be kept in sync with the JSON schema version
28+
version: '2.0.0',
2829

2930
description: 'TODO',
3031

@@ -73,10 +74,10 @@ export default {
7374

7475
// Write it to the output file
7576
if (output) {
76-
// await writeFile(
77-
// join(output, `${node.api}.json`),
78-
// JSON.stringify(section)
79-
// );
77+
await writeFile(
78+
join(output, `${node.api}.json`),
79+
JSON.stringify(section)
80+
);
8081
}
8182
});
8283

src/generators/json/schema.jsonc

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2-
// TODO vscode doesn't support the latest schema https://github.com/microsoft/vscode/issues/155379
3-
// "$schema": "https://json-schema.org/draft/2020-12/schema",
2+
// TODO vscode doesn't support 2020-12 yet
3+
// https://github.com/microsoft/vscode/issues/165219
44
"$schema": "http://json-schema.org/draft-07/schema#",
5-
5+
"$id": "[email protected]", // This should be kept in sync with the generator version
66
"title": "Node.js API Documentation Schema",
77
"readOnly": true,
88

@@ -11,7 +11,7 @@
1111
{
1212
"oneOf": [
1313
{ "$ref": "#/definitions/Module" },
14-
{ "$ref": "#/definitions/Text" }
14+
{ "$ref": "#/definitions/Text" },
1515
],
1616
},
1717
],
@@ -48,6 +48,11 @@
4848
"type": "string",
4949
"description": "Description of the section.",
5050
},
51+
"text": {
52+
"type": "array",
53+
"description": "Sections that just hold further text on this section.",
54+
"items": { "$ref": "#/definitions/Text" },
55+
},
5156
"@example": {
5257
"description": "https://jsdoc.app/tags-example",
5358
"oneOf": [
@@ -136,11 +141,6 @@
136141
"type": "array",
137142
"items": { "$ref": "#/definitions/Property" },
138143
},
139-
"text": {
140-
"type": "array",
141-
"description": "Sections that just hold further text on this module.",
142-
"items": { "$ref": "#/definitions/Text" }
143-
}
144144
},
145145
// TODO what else to be required
146146
"required": ["type", "@module", "@see"],
@@ -175,7 +175,13 @@
175175
"items": { "$ref": "#/definitions/Property" },
176176
},
177177
},
178-
"required": ["type"],
178+
"required": [
179+
"type",
180+
"@constructor",
181+
"methods",
182+
"staticMethods",
183+
"properties",
184+
],
179185
},
180186
],
181187
},
@@ -307,9 +313,7 @@
307313
},
308314

309315
"Text": {
310-
"allOf": [
311-
{ "$ref": "#/definitions/SectionBase" },
312-
]
316+
"allOf": [{ "$ref": "#/definitions/SectionBase" }],
313317
},
314318

315319
"NodeCoreVersion": {

src/generators/json/types.d.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1-
import { Class, Method, Module, Property, SectionBase, Text } from './generated.d.ts';
1+
import {
2+
Class,
3+
Method,
4+
Module,
5+
Property,
6+
SectionBase,
7+
Text,
8+
} from './generated.d.ts';
29

3-
export type Section = SectionBase & (Module | Class | Method | Property | Text);
10+
export type Section = SectionBase &
11+
(Module | Class | Method | Property | Text) &
12+
GeneratorMetadata;
13+
14+
/**
15+
* This is metadata that's only relevant to the generator and should be removed
16+
* before the file is output.
17+
*/
18+
export type GeneratorMetadata = {
19+
parent?: Section;
20+
};
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// @ts-check
2+
'use strict';
3+
4+
import { findParentSection } from './findParentSection.mjs';
5+
6+
/**
7+
* @typedef {import('../../legacy-json/types.d.ts').HierarchizedEntry} HierarchizedEntry
8+
*/
9+
10+
export const createClassSectionBuilder = () => {
11+
/**
12+
* Adds the properties expected in a class section to an object.
13+
* @param {import('../generated.d.ts').Class} section The class section
14+
*/
15+
return section => {
16+
section['@constructor'] = [];
17+
18+
section.methods = [];
19+
20+
section.staticMethods = [];
21+
22+
section.properties = [];
23+
24+
const parent = findParentSection(section, 'module');
25+
26+
if (parent) {
27+
if (!Array.isArray(parent.classes)) {
28+
throw new TypeError(
29+
`expected parent.classes to be an array, got ${typeof parent.classes}`
30+
);
31+
}
32+
33+
parent.classes.push(section);
34+
}
35+
};
36+
};
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// @ts-check
2+
'use strict';
3+
4+
import { findParentSection } from './findParentSection.mjs';
5+
6+
/**
7+
* @typedef {import('../../legacy-json/types.d.ts').HierarchizedEntry} HierarchizedEntry
8+
*/
9+
10+
export const createMethodSectionBuilder = () => {
11+
/**
12+
* @param {HierarchizedEntry} entry The AST entry
13+
* @param {import('../generated.d.ts').Method} section The method section
14+
*/
15+
const parseSignatures = (entry, section) => {
16+
section.signatures = [];
17+
};
18+
19+
/**
20+
* Adds the properties expected in a method section to an object.
21+
* @param {HierarchizedEntry} entry The AST entry
22+
* @param {import('../generated.d.ts').Method} section The method section
23+
*/
24+
return (entry, section) => {
25+
parseSignatures(entry, section);
26+
27+
// TODO are there any other places that an exposed method can be defined?
28+
const parent = findParentSection(section, ['class', 'module']);
29+
30+
// Add this section to the parent if it exists
31+
if (parent) {
32+
if (!Array.isArray(parent.methods)) {
33+
throw new TypeError(
34+
`expected parent.methods to be an array, got type ${typeof parent.methods} instead (parent type=${parent.type})`
35+
);
36+
}
37+
38+
parent.methods.push(section);
39+
}
40+
};
41+
};
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// @ts-check
2+
'use strict';
3+
4+
import { DOC_NODE_VERSION } from '../../../constants.mjs';
5+
6+
/**
7+
* @typedef {import('../../legacy-json/types.d.ts').HierarchizedEntry} HierarchizedEntry
8+
*/
9+
10+
export const createModuleSectionBuilder = () => {
11+
/**
12+
* Adds the properties expected in a module section to an object.
13+
* @param {HierarchizedEntry} entry The AST entry
14+
* @param {import('../generated.d.ts').Module} section The module section
15+
*/
16+
return (entry, section) => {
17+
section['@see'] =
18+
`https://nodejs.org/dist/${DOC_NODE_VERSION}/doc/api/${entry.api}.html`;
19+
20+
section['@module'] = `node:${entry.api}`;
21+
22+
section.classes = [];
23+
24+
section.methods = [];
25+
26+
section.globals = [];
27+
28+
section.properties = [];
29+
};
30+
};

0 commit comments

Comments
 (0)