-
-
Notifications
You must be signed in to change notification settings - Fork 840
Expand file tree
/
Copy pathtask-prerender.ts
More file actions
50 lines (39 loc) · 1.43 KB
/
task-prerender.ts
File metadata and controls
50 lines (39 loc) · 1.43 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
import { catchError } from '@utils';
import type { BuildResultsComponentGraph, Diagnostic, ValidatedConfig } from '../declarations';
import type { CoreCompiler } from './load-compiler';
import { startupCompilerLog } from './logs';
export const taskPrerender = async (coreCompiler: CoreCompiler, config: ValidatedConfig) => {
startupCompilerLog(coreCompiler, config);
const hydrateAppFilePath = config.flags.unknownArgs[0];
if (typeof hydrateAppFilePath !== 'string') {
config.logger.error(`Missing hydrate app script path`);
return config.sys.exit(1);
}
const srcIndexHtmlPath = config.srcIndexHtml;
const diagnostics = await runPrerenderTask(coreCompiler, config, hydrateAppFilePath, undefined, srcIndexHtmlPath);
config.logger.printDiagnostics(diagnostics);
if (diagnostics.some((d) => d.level === 'error')) {
return config.sys.exit(1);
}
};
export const runPrerenderTask = async (
coreCompiler: CoreCompiler,
config: ValidatedConfig,
hydrateAppFilePath?: string,
componentGraph?: BuildResultsComponentGraph,
srcIndexHtmlPath?: string,
) => {
const diagnostics: Diagnostic[] = [];
try {
const prerenderer = await coreCompiler.createPrerenderer(config);
const results = await prerenderer.start({
hydrateAppFilePath,
componentGraph,
srcIndexHtmlPath,
});
diagnostics.push(...results.diagnostics);
} catch (e: any) {
catchError(diagnostics, e);
}
return diagnostics;
};