-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathgeneratePage.ts
53 lines (47 loc) · 1.16 KB
/
generatePage.ts
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
import { mkdirSync } from 'fs';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import webpack from 'webpack';
import webpackConfig from '../webpack.config';
import SentryScenarioGenerationPlugin from './generatePlugin';
export async function generatePage(
initPath: string,
subjectPath: string,
templatePath: string,
outPath: string,
outPageName: string = 'index.html',
): Promise<void> {
mkdirSync(outPath, { recursive: true });
await new Promise<void>((resolve, reject) => {
const compiler = webpack(
webpackConfig({
entry: {
init: initPath,
subject: subjectPath,
},
output: {
path: outPath,
filename: '[name].bundle.js',
},
plugins: [
new SentryScenarioGenerationPlugin(outPath),
new HtmlWebpackPlugin({
filename: outPageName,
template: templatePath,
inject: 'body',
}),
],
}),
);
compiler.run(err => {
if (err) {
reject(err);
}
compiler.close(err => {
if (err) {
reject(err);
}
resolve();
});
});
});
}