-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
76 lines (65 loc) · 2.03 KB
/
cli.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
68
69
70
71
72
73
74
75
76
#!/usr/bin/env node
import chokidar from 'chokidar'
import { exec } from 'child_process'
import * as fs from 'fs'
import process from 'process'
const chokidarPaths = [
'src/electron/main.ts',
'src/electron/renderer/renderer.ts',
'src/electron/renderer/*.ts',
'src/electron/renderer/**/*.ts',
'src/electron/preload/preload.mts',
'src/electron/preload/preload.d.ts',
'index.html',
'src/electron/expose-api/*.d.ts',
'src/electron/expose-api/**/*.d.ts',
'src/electron/expose-api/*.mts',
'src/electron/expose-api/**/*.mts',
'src/electron/**/*.ts',
'src/electron/**/*.mts',
'src/electron/**/*.d.ts',
'src/electron/**/*.html',
'src/electron/**/*',
'src/**/*',
'src/assets/*.css',
'src/assets/*.scss'
];
const chokidarPathsIgnore = []
const chokidarDev = () => {
try {
fs.open('.hmr_pid.txt', 'w', (err, fd) => {
if (err) {
throw err;
}
fs.close(fd, (err) => {
if (err) {
throw err;
}
})
})
} catch (e) {
console.error(e);
}
console.log("HMR is active");
chokidar.watch(chokidarPaths, { ignored: chokidarPathsIgnore }).on('all', (event, path) => {
if(event === 'change' && path !== null && path !== undefined) {
console.log("File changed: " + path);
console.log("Rebuilding files...");
try {
exec('npm run build').on('exit', () => {
fs.readFile('.hmr_pid.txt', { encoding: 'utf-8' }, (err, data) => {
if (err) {
throw err;
}
process.kill(data);
})
console.log("Restarting Electron process...");
exec('npm run electron');
});
} catch (e) {
console.error(e);
}
}
})
}
chokidarDev();