-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.js
67 lines (62 loc) · 1.7 KB
/
ui.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const { fork } = require('child_process');
const signale = require('signale');
const { join } = require('path');
const { uiPlugins } = require('./uiPlugins');
const UMI_BIN = join(__dirname, '../packages/umi/bin/umi.js');
const FATHER_BUILD_BIN = require.resolve('father-build/bin/father-build.js');
const watch = process.argv.includes('-w') || process.argv.includes('--watch');
const opts = {
watch,
};
const uiApp = () => {
signale.pending('UI App building');
const { watch } = opts;
return new Promise((resolve, reject) => {
try {
const child = fork(UMI_BIN, [watch ? 'dev' : 'build', ...(watch ? ['--watch'] : [])], {
env: {
APP_ROOT: './packages/umi-ui/client',
UMI_UI: 'none',
UMI_UI_SERVER: 'none',
},
});
child.on('exit', code => {
if (code === 1) {
signale.fatal('UI App build error');
process.exit(1);
}
signale.complete('UI App done');
resolve(child);
});
} catch (e) {
reject(e);
}
});
};
const buildPlugin = plugin => {
const { watch } = opts;
return new Promise((resolve, reject) => {
try {
const pluginProcess = fork(FATHER_BUILD_BIN, watch ? ['--watch'] : [], {
cwd: join(__dirname, '..', plugin),
});
pluginProcess.on('exit', code => {
if (code === 1) {
process.exit(1);
}
resolve(pluginProcess);
});
} catch (e) {
reject(e);
}
});
};
(async () => {
// exit by Ctrl/Cmd + C
process.on('SIGINT', () => {
signale.info('exit build by user');
process.exit(0);
});
const buildQueue = [uiApp(), ...uiPlugins.map(buildPlugin)];
await Promise.all(buildQueue);
})();