Skip to content

Commit 2f1cb75

Browse files
committed
refactor: create metadata generator
1 parent c4256bc commit 2f1cb75

File tree

17 files changed

+224
-175
lines changed

17 files changed

+224
-175
lines changed

bin/commands/generate.mjs

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

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

141-
await runGenerators({
142-
generators: opts.target,
143-
input: opts.input,
144-
output: opts.output && resolve(opts.output),
145-
version: coerce(opts.version),
146-
releases: await getAllMajors(),
147-
gitRef: opts.gitRef,
148-
threads: parseInt(opts.threads, 10),
149-
});
140+
const releases = await getAllMajors();
141+
142+
await Promise.all(
143+
docs.map(async doc => {
144+
const { runGenerators } = createGenerator(doc);
145+
146+
await runGenerators({
147+
generators: opts.target,
148+
input: opts.input,
149+
output: opts.output && resolve(opts.output),
150+
version: coerce(opts.version),
151+
releases,
152+
gitRef: opts.gitRef,
153+
threads: parseInt(opts.threads, 10),
154+
});
155+
})
156+
);
150157
},
151158
};

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<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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ import apiLinks from './api-links/index.mjs';
1111
import oramaDb from './orama-db/index.mjs';
1212
import astJs from './ast-js/index.mjs';
1313
import llmsTxt from './llms-txt/index.mjs';
14+
import metadata from './metadata/index.mjs';
1415

1516
export const publicGenerators = {
17+
metadata: metadata,
1618
'json-simple': jsonSimple,
1719
'legacy-html': legacyHtml,
1820
'legacy-html-all': legacyHtmlAll,

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
@@ -41,7 +41,7 @@ export default {
4141
description:
4242
'Generates the legacy version of the API docs in HTML, with the assets and styles included as files',
4343

44-
dependsOn: 'ast',
44+
dependsOn: 'metadata',
4545

4646
/**
4747
* 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
@@ -25,7 +25,7 @@ export default {
2525

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

28-
dependsOn: 'ast',
28+
dependsOn: 'metadata',
2929

3030
/**
3131
* 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)