-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathindex.mjs
More file actions
68 lines (60 loc) · 1.81 KB
/
index.mjs
File metadata and controls
68 lines (60 loc) · 1.81 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import {
getCompatibleVersions,
groupNodesByModule,
} from '../../utils/generators.mjs';
import buildContent from './utils/buildContent.mjs';
import { getRemarkRecma } from '../../utils/remark.mjs';
import { buildSideBarDocPages } from './utils/buildBarProps.mjs';
/**
* This generator generates a JSX AST from an input MDAST
*
* @typedef {Array<ApiDocMetadataEntry>} Input
*
* @type {GeneratorMetadata<Input, string>}
*/
export default {
name: 'jsx',
version: '1.0.0',
description: 'Generates JSX from the input AST',
dependsOn: 'ast',
/**
* Generates a JSX AST
*
* @param {Input} entries
* @param {Partial<GeneratorOptions>} options
* @returns {Promise<Array<string>>} Array of generated content
*/
async generate(entries, { releases, version }) {
const remarkRecma = getRemarkRecma();
const groupedModules = groupNodesByModule(entries);
// Get sorted primary heading nodes
const headNodes = entries
.filter(node => node.heading.depth === 1)
.sort((a, b) => a.heading.data.name.localeCompare(b.heading.data.name));
// Generate table of contents
const docPages = buildSideBarDocPages(groupedModules, headNodes);
// Process each head node and build content
const results = await Promise.all(
headNodes.map(entry => {
const versions = getCompatibleVersions(
entry.introduced_in,
releases,
true
);
const sideBarProps = {
versions: versions.map(({ version }) => `v${version.version}`),
currentVersion: `v${version.version}`,
currentPage: `${entry.api}.html`,
docPages,
};
return buildContent(
groupedModules.get(entry.api),
entry,
sideBarProps,
remarkRecma
);
})
);
return results;
},
};