-
-
Notifications
You must be signed in to change notification settings - Fork 73
/
index.js
30 lines (25 loc) · 681 Bytes
/
index.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
import { spawn } from 'child_process'
import path from 'path'
import { fileURLToPath } from 'url'
import { watchFile, unwatchFile } from 'fs'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
console.log('Starting . . .')
function start() {
let args = [path.join(__dirname, "src", "hisoka.js"), ...process.argv.slice(2)]
let p = spawn(process.argv[0], args, { stdio: ['inherit', 'inherit', 'inherit', 'ipc'] })
.on('message', data => {
if (data == 'reset') {
console.log('Restarting...')
p.kill()
start()
}
})
.on("exit", (_, code) => {
if (code !== 0) start()
watchFile(args[0], () => {
unwatchFile(args[0])
start()
})
})
}
start()