-
-
Notifications
You must be signed in to change notification settings - Fork 119
/
dev-runner.js
40 lines (33 loc) · 886 Bytes
/
dev-runner.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
const watch = require('node-watch');
const { spawn } = require('child_process');
const electron = require('electron-connect').server.create();
const watch_dir = './src';
const npm_command = /^win/.test(process.platform) ? 'npm.cmd' : 'npm';
function greeting() {
console.log(`Begin watching files in ${watch_dir}`);
}
function startApp() {
const build = spawn(npm_command, ['run', 'build']);
build.on('close', function() {
electron.start();
});
}
function startWatch() {
watch(watch_dir, { recursive: true }, function(evt, name) {
console.log("App updated, recompiling...");
const build = spawn(npm_command, ['run', 'build']);
build.on('close', function() {
electron.reload();
});
});
}
// stop if app closed
electron.on('closed', function(){
process.exit();
});
function start() {
startApp();
greeting();
startWatch();
}
start();