-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev.js
More file actions
54 lines (46 loc) · 1.26 KB
/
dev.js
File metadata and controls
54 lines (46 loc) · 1.26 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
const rollup = require('rollup');
const electron = require('electron');
const { spawn } = require('child_process');
const configs = require('./rollup.config');
let exampleProcess = null;
let nowWaiting = null;
let configStatus = {};
function hasError() {
return Object.values(configStatus).includes(false)
}
function startElectron() {
exampleProcess = spawn(electron, ['--enable-logging', './example/main.js']);
exampleProcess.stdout.on('data', (data) => {
console.log(data.toString());
})
}
function startExample() {
if (hasError()) return;
if (exampleProcess) {
process.kill(exampleProcess.pid);
nowWaiting = Math.random();
const waiting = nowWaiting;
setTimeout(() => {
if (nowWaiting === waiting) startElectron();
}, 300)
} else startElectron();
}
async function rollupBuild(options) {
const watcher = rollup.watch(options);
configStatus[options.input] = false;
watcher.on('event', (event) => {
switch (event.code) {
case 'END':
configStatus[options.input] = true;
if (!hasError()) {
startExample();
}
break;
case 'ERROR': console.log(event.error); configStatus[options.input] = false; break;
}
});
}
function start() {
configs.forEach(rollupBuild)
}
start();