forked from patternfly/patternfly-org
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
104 lines (91 loc) · 2.51 KB
/
build.js
File metadata and controls
104 lines (91 loc) · 2.51 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
const path = require('path');
const { fork } = require('child_process');
const rspack = require('@rspack/core');
const { generate } = require('./generate');
const { getConfig } = require('./helpers');
async function buildWebpack(webpackConfig) {
let compiler;
try {
compiler = rspack(webpackConfig);
} catch (err) {
if (err.name === "WebpackOptionsValidationError") {
console.error(err.message);
process.exit(1);
}
throw err;
}
return new Promise((res, rej) =>
compiler.run((err, stats) => {
if (err) {
console.error(err.stack || err);
if (err.details) {
console.error(err.details);
}
rej();
}
const info = stats.toJson();
if (stats.hasErrors()) {
console.error(info.errors);
rej();
}
if (stats.hasWarnings()) {
console.warn(info.warnings.map(w => w.message || w).join('\n'));
}
res();
})
);
}
async function execFile(file, args) {
const start = new Date();
return new Promise((res, rej) => {
const child_argv = [JSON.stringify(args)];
const child_execArgv = [
'--max-old-space-size=4096'
];
if (args.legacySSL) {
child_execArgv.push('--openssl-legacy-provider')
}
const child = fork(path.join(__dirname, file), child_argv, { execArgv: child_execArgv });
function errorHandler(err) {
console.error(err);
process.exit(1);
};
function successHandler(code) {
if (code === 0) {
const duration = new Date() - start;
console.log('%s took %ss', file, duration / 1000);
res();
}
else {
process.exit(code);
}
}
child.on('error', errorHandler);
child.on('exit', successHandler);
});
}
async function build(cmd, options) {
generate(options);
const toBuild = cmd === 'all'
? ['server', 'client']
: cmd;
const config = getConfig(options);
config.analyze = options.analyze;
config.output = options.output;
config.legacySSL = options.legacySSL
// These get passed to `fork`ed builds
process.env.hasDesignGuidelines = config.hasDesignGuidelines;
// console.log('build', cmd, options.parent.cssconfig);
if (toBuild.includes('server')) {
// Need to fork since first webpack build puts pressure on GC
// Otherwise CircleCI will fail with 4GB RAM
await execFile('buildServer.js', config);
}
if (toBuild.includes('client')) {
await execFile('buildClient.js', config);
}
}
module.exports = {
build,
buildWebpack
};