-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathgenerate.mjs
More file actions
38 lines (31 loc) · 1.06 KB
/
generate.mjs
File metadata and controls
38 lines (31 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
'use strict';
import { parseApiDoc } from './utils/parse.mjs';
import { parseTypeMap } from '../../parsers/json.mjs';
import getConfig from '../../utils/configuration/index.mjs';
/**
* Process a chunk of API doc files in a worker thread.
* Called by chunk-worker.mjs for parallel processing.
*
* @type {import('./types').Generator['processChunk']}
*/
export async function processChunk(fullInput, itemIndices, typeMap) {
const results = [];
for (const idx of itemIndices) {
results.push(...parseApiDoc(fullInput[idx], typeMap));
}
return results;
}
/**
* Generates a flattened list of metadata entries from API docs.
*
* @type {import('./types').Generator['generate']}
*/
export async function* generate(inputs, worker) {
const { metadata: config } = getConfig();
const typeMap = await parseTypeMap(config.typeMap);
// Stream chunks as they complete - allows dependent generators
// to start collecting/preparing while we're still processing
for await (const chunkResult of worker.stream(inputs, typeMap)) {
yield chunkResult.flat();
}
}