Skip to content

Commit 702cb43

Browse files
authored
feat: create metadata entries generator (#272)
* fix: resolve generic interface extension error * refactor: create metadata generator * fix: remove thread pool loop * fix: lint * refactor: make metadata generator internal * refactor: inline return * refactor: move slugger to metadata generator dir * refactor: nits * refactor: nits * refactor: fix import sorting
1 parent 8e1ee40 commit 702cb43

File tree

21 files changed

+233
-174
lines changed

21 files changed

+233
-174
lines changed

bin/commands/generate.mjs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,18 @@ export default {
135135
process.exit(1);
136136
}
137137

138-
const { runGenerators } = createGenerator(docs);
139138
const { getAllMajors } = createNodeReleases(opts.changelog);
140139

140+
const releases = await getAllMajors();
141+
142+
const { runGenerators } = createGenerator(docs);
143+
141144
await runGenerators({
142145
generators: opts.target,
143146
input: opts.input,
144147
output: opts.output && resolve(opts.output),
145148
version: coerce(opts.version),
146-
releases: await getAllMajors(),
149+
releases,
147150
gitRef: opts.gitRef,
148151
threads: parseInt(opts.threads, 10),
149152
});

bin/utils.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const parser = lazy(createMarkdownParser);
2424
* @param {string[]} input - Glob patterns for input files.
2525
* @param {string[]} [ignore] - Glob patterns to ignore.
2626
* @param {import('../src/linter/types').Linter} [linter] - Linter instance
27-
* @returns {Promise<ApiDocMetadataEntry[]>} - Parsed documentation objects.
27+
* @returns {Promise<Array<ParserOutput<import('mdast').Root>>>}
2828
*/
2929
export async function loadAndParse(input, ignore, linter) {
3030
const files = await loader().loadFiles(input, ignore);

src/generators.mjs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@ import { allGenerators } from './generators/index.mjs';
44
import WorkerPool from './threading/index.mjs';
55

66
/**
7-
* @typedef {{ ast: GeneratorMetadata<ApiDocMetadataEntry, ApiDocMetadataEntry>}} AstGenerator The AST "generator" is a facade for the AST tree and it isn't really a generator
8-
* @typedef {AvailableGenerators & AstGenerator} AllGenerators A complete set of the available generators, including the AST one
9-
* @param markdownInput
10-
* @param jsInput
11-
*
127
* This method creates a system that allows you to register generators
138
* and then execute them in a specific order, keeping track of the
149
* generation process, and handling errors that may occur from the
@@ -21,18 +16,20 @@ import WorkerPool from './threading/index.mjs';
2116
* Generators can also write to files. These would usually be considered
2217
* the final generators in the chain.
2318
*
24-
* @param {ApiDocMetadataEntry} markdownInput The parsed API doc metadata entries
25-
* @param {Array<import('acorn').Program>} parsedJsFiles
19+
* @typedef {{ ast: GeneratorMetadata<ParserOutput, ParserOutput>}} AstGenerator The AST "generator" is a facade for the AST tree and it isn't really a generator
20+
* @typedef {AvailableGenerators & AstGenerator} AllGenerators A complete set of the available generators, including the AST one
21+
*
22+
* @param {ParserOutput} input The API doc AST tree
2623
*/
27-
const createGenerator = markdownInput => {
24+
const createGenerator = input => {
2825
/**
2926
* We store all the registered generators to be processed
3027
* within a Record, so we can access their results at any time whenever needed
3128
* (we store the Promises of the generator outputs)
3229
*
3330
* @type {{ [K in keyof AllGenerators]: ReturnType<AllGenerators[K]['generate']> }}
3431
*/
35-
const cachedGenerators = { ast: Promise.resolve(markdownInput) };
32+
const cachedGenerators = { ast: Promise.resolve(input) };
3633

3734
const threadPool = new WorkerPool();
3835

src/generators/addon-verify/index.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export default {
3030
description:
3131
'Generates a file list from code blocks extracted from `doc/api/addons.md` to facilitate C++ compilation and JavaScript runtime validations',
3232

33-
dependsOn: 'ast',
33+
dependsOn: 'metadata',
3434

3535
/**
3636
* Generates a file list from code blocks.

src/generators/ast-js/index.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default {
2020

2121
description: 'Parses Javascript source files passed into the input.',
2222

23-
dependsOn: 'ast',
23+
dependsOn: 'metadata',
2424

2525
/**
2626
* @param {Input} _

src/generators/index.mjs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import legacyJson from './legacy-json/index.mjs';
1111
import legacyJsonAll from './legacy-json-all/index.mjs';
1212
import llmsTxt from './llms-txt/index.mjs';
1313
import manPage from './man-page/index.mjs';
14+
import metadata from './metadata/index.mjs';
1415
import oramaDb from './orama-db/index.mjs';
1516

1617
export const publicGenerators = {
@@ -27,9 +28,14 @@ export const publicGenerators = {
2728
'jsx-ast': jsxAst,
2829
};
2930

31+
// These are a bit special: we don't want them to run unless needed,
32+
// and we also don't want them publicly accessible via the CLI.
33+
const internalGenerators = {
34+
metadata,
35+
'ast-js': astJs,
36+
};
37+
3038
export const allGenerators = {
3139
...publicGenerators,
32-
// This one is a little special since we don't want it to run unless we need
33-
// it and we also don't want it to be publicly accessible through the CLI.
34-
'ast-js': astJs,
40+
...internalGenerators,
3541
};

src/generators/json-simple/index.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export default {
2626
description:
2727
'Generates the simple JSON version of the API docs, and returns it as a string',
2828

29-
dependsOn: 'ast',
29+
dependsOn: 'metadata',
3030

3131
/**
3232
* Generates the simplified JSON version of the API docs

src/generators/legacy-html/index.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export default {
4040
description:
4141
'Generates the legacy version of the API docs in HTML, with the assets and styles included as files',
4242

43-
dependsOn: 'ast',
43+
dependsOn: 'metadata',
4444

4545
/**
4646
* Generates the legacy version of the API docs in HTML

src/generators/legacy-json/index.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export default {
2626

2727
description: 'Generates the legacy version of the JSON API docs.',
2828

29-
dependsOn: 'ast',
29+
dependsOn: 'metadata',
3030

3131
/**
3232
* Generates a legacy JSON file.

src/generators/llms-txt/index.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default {
1919
description:
2020
'Generates a llms.txt file to provide information to LLMs at inference time',
2121

22-
dependsOn: 'ast',
22+
dependsOn: 'metadata',
2323

2424
/**
2525
* Generates a llms.txt file

0 commit comments

Comments
 (0)