-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildExamples.js
49 lines (43 loc) · 1.15 KB
/
buildExamples.js
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
const path = require('path');
const { fork } = require('child_process');
const { glob, signale } = require('@umijs/utils');
const UMI_SCRIPT = path.join(__dirname, '../packages/umi/bin/umi.js');
function build({ cwd }) {
return new Promise((resolve) => {
signale.pending(cwd);
const child = fork(UMI_SCRIPT, ['build'], {
env: {
...process.env,
BABEL_CACHE: 'none',
COMPRESS: 'none',
},
cwd,
stdio: 'ignore',
});
child.on('exit', (code) => {
if (code === 0) {
signale.complete(`success build ${cwd}`);
resolve();
return;
}
signale.fatal(cwd);
process.exit(code);
});
process.on('exit', () => {
child.kill('SIGINT');
});
});
}
async function buildExamples(customProjectPaths) {
const examples = glob.sync('examples/*', {
dot: false,
absolute: true,
cwd: path.join(__dirname, '..'),
});
const projects =
Array.isArray(customProjectPaths) && customProjectPaths.length > 0
? customProjectPaths
: examples;
await Promise.all(projects.map((project) => build({ cwd: project })));
}
module.exports = buildExamples;