Skip to content

Commit 9811790

Browse files
committed
review + some formatting
Signed-off-by: flakey5 <[email protected]>
1 parent 1bcf93d commit 9811790

26 files changed

+411
-541
lines changed

src/generators/index.mjs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ export const publicGenerators = {
2929
'orama-db': oramaDb,
3030
'llms-txt': llmsTxt,
3131
web,
32-
'jsx-ast': jsxAst,
33-
metadata,
3432
json,
3533
'json-all': jsonAll,
3634
};

src/generators/json-all/index.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import { writeFile } from 'node:fs/promises';
55
import { join } from 'node:path';
66

7-
import { DOC_NODE_VERSION } from '../../constants.mjs';
7+
import { BASE_URL, DOC_NODE_VERSION } from '../../constants.mjs';
88
import { generateJsonSchema } from './util/generateJsonSchema.mjs';
99

1010
/**
@@ -36,7 +36,7 @@ export default {
3636
*/
3737
async generate(input, { version, output }) {
3838
const generatedValue = {
39-
$schema: `https://nodejs.org/docs/${DOC_NODE_VERSION}/api/node-doc-all-schema.jsonc`,
39+
$schema: `${BASE_URL}/docs/${DOC_NODE_VERSION}/api/node-doc-all-schema.jsonc`,
4040
modules: [],
4141
text: [],
4242
};

src/generators/json-all/util/generateJsonSchema.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
'use strict';
22

3+
import { BASE_URL } from '../../../constants.mjs';
34
import jsonAll from '../index.mjs';
45

56
/**
67
* @param {string} version
78
*/
89
export function generateJsonSchema(version) {
9-
const jsonSchemaUrl = `https://nodejs.org/docs/${version}/api/node-doc-schema.json`;
10+
const jsonSchemaUrl = `${BASE_URL}/docs/${version}/api/node-doc-schema.json`;
1011

1112
return {
1213
$schema: 'http://json-schema.org/draft-07/schema#',

src/generators/json/__tests__/index.test.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import assert from 'node:assert';
2+
import { readFile } from 'node:fs/promises';
23
import { join } from 'node:path';
34
import { describe, test, before } from 'node:test';
45

5-
import { Validator } from 'jsonschema';
66
import { parse as jsoncParse } from 'jsonc-parser';
7+
import { Validator } from 'jsonschema';
78
import { SemVer } from 'semver';
89

910
import createGenerator from '../../../generators.mjs';
1011
import createMarkdownLoader from '../../../loaders/markdown.mjs';
1112
import createMarkdownParser from '../../../parsers/markdown.mjs';
12-
import { parseSchema } from '../utils/parseSchema.mjs';
13-
import { readFile } from 'node:fs/promises';
1413
import json from '../index.mjs';
14+
import { parseSchema } from '../utils/parseSchema.mjs';
1515

1616
const FIXTURES_DIR = join(import.meta.dirname, 'fixtures');
1717

src/generators/json/constants.mjs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,32 @@ export const METHOD_RETURN_TYPE_EXTRACTOR = /^Returns(:?) {(.*)}( .*)?$/;
1919
// Grabs the parameters from a method's signature
2020
// ex/ 'new buffer.Blob([sources[, options]])'.match(PARAM_EXPRESSION) === ['([sources[, options]])', '[sources[, options]]']
2121
export const METHOD_PARAM_EXPRESSION = /\((.+)\);?$/;
22+
23+
/**
24+
* Mapping of {@link HeadingMetadataEntry['type']} to types defined in the
25+
* JSON schema.
26+
*/
27+
export const ENTRY_TO_SECTION_TYPE = /** @type {const} */ ({
28+
var: 'property',
29+
global: 'property',
30+
module: 'module',
31+
class: 'class',
32+
ctor: 'method',
33+
method: 'method',
34+
classMethod: 'method',
35+
property: 'property',
36+
event: 'event',
37+
misc: 'text',
38+
text: 'text',
39+
example: 'text',
40+
});
41+
42+
/**
43+
* Some types in the docs have different capitalization than what exists in JS
44+
* @type {Record<string, string>}
45+
*/
46+
export const DOC_TYPE_TO_CORRECT_JS_TYPE_MAP = {
47+
integer: 'number',
48+
bigint: 'BigInt',
49+
symbol: 'Symbol',
50+
};

src/generators/json/index.mjs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
// @ts-check
21
'use strict';
32

43
import { writeFile } from 'node:fs/promises';
54
import { join } from 'node:path';
65

7-
import { createSectionBuilder } from './utils/createSection.mjs';
86
import { parseSchema } from './utils/parseSchema.mjs';
7+
import { createSection } from './utils/sections/index.mjs';
98
import { groupNodesByModule } from '../../utils/generators.mjs';
109

1110
/**
@@ -42,8 +41,6 @@ export default {
4241
async generate(input, { output }) {
4342
const groupedModules = groupNodesByModule(input);
4443

45-
const buildSection = createSectionBuilder();
46-
console.log('json in', input);
4744
/**
4845
* @param {ApiDocMetadataEntry} head
4946
* @returns {import('./generated.d.ts').NodeJsAPIDocumentationSchema}
@@ -54,7 +51,7 @@ export default {
5451
throw new TypeError(`no grouped nodes found for ${head.api}`);
5552
}
5653

57-
const section = buildSection(head, nodes);
54+
const section = createSection(head, nodes);
5855

5956
return section;
6057
};

src/generators/json/utils/__tests__/createModuleSection.test.mjs

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/generators/json/utils/createClassSection.mjs

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/generators/json/utils/createModuleSection.mjs

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/generators/json/utils/createParameterGroupings.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ import { ParameterTree } from './parameter-tree.mjs';
1919
*
2020
* For instance, using the above signature, we want to create four method
2121
* signatures for it:
22-
* 1. For `something()`
23-
* 2. For `something(sources)
24-
* 3. For `something(sources, options, flag)
25-
* 4. For `something(sources, options, flag, abc)
22+
* 1. For `something()`
23+
* 2. For `something(sources)
24+
* 3. For `something(sources, options, flag)
25+
* 4. For `something(sources, options, flag, abc)
2626
*
2727
* This method does just that given an array of the parameter names split by
2828
* commas.

0 commit comments

Comments
 (0)