forked from nodejs/doc-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate.mjs
More file actions
48 lines (37 loc) · 1.37 KB
/
Copy pathgenerate.mjs
File metadata and controls
48 lines (37 loc) · 1.37 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
'use strict';
import { readFile } from 'node:fs/promises';
import { join } from 'node:path';
import { copyStaticAssets } from './utils/copying.mjs';
import { processJSXEntries } from './utils/processing.mjs';
import getConfig from '../../utils/configuration/index.mjs';
import { writeFile } from '../../utils/file.mjs';
/**
* Main generation function that processes JSX AST entries into web bundles.
*
* Bundles all JSX AST entries in a single pass so shared component chunks and
* CSS are produced once.
*
* @type {import('./types').Generator['generate']}
*/
export async function generate(input) {
const config = getConfig('web');
const template = await readFile(config.templatePath, 'utf-8');
// Sidebar lists only the real module pages.
const sidebarEntries = input.filter(entry => entry.data.synthetic !== true);
const { results, css, chunks } = await processJSXEntries(
input,
template,
sidebarEntries
);
if (config.output) {
for (const { html, path } of results) {
await writeFile(join(config.output, `${path}.html`), html, 'utf-8');
}
for (const chunk of chunks) {
await writeFile(join(config.output, chunk.fileName), chunk.code, 'utf-8');
}
await writeFile(join(config.output, 'styles.css'), css, 'utf-8');
await copyStaticAssets(config);
}
return results.map(({ html }) => ({ html: html.toString(), css }));
}