forked from amiruldev20/mywabot-baileys
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
61 lines (52 loc) · 1.89 KB
/
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
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
/*
terimakasih telah menggunakan source code saya. apabila ada masalah, silahkan hubungi saya
•
Thank you for using my source code. If there is a problem, please contact me
- Facebook: fb.com/amiruldev.ci
- Instagram: instagram.com/amirul.dev
- Telegram: t.me/amiruldev20
- Github: @amiruldev20
- WhatsApp: 085157489446
*/
/* module external */
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))
let childProcess = null
function start(file) {
if (childProcess) {
console.log("Restarting due to file changes...")
childProcess.kill()
childProcess = null
}
const scriptPath = path.join(__dirname, file)
const args = [scriptPath, "d=Datenow", ...process.argv.slice(2)]
childProcess = spawn(process.argv[0], args, { stdio: ["inherit", "inherit", "inherit", "ipc"] })
childProcess.on("message", data => {
if (data === "reset") {
console.log("Reset command received, restarting process...")
start(file)
} else if (data === "uptime") {
childProcess.send(process.uptime())
}
})
childProcess.on("exit", code => {
if (code !== 0) {
console.log(`Process exited with code ${code}. Watching for changes...`)
watchFile(scriptPath, (curr, prev) => {
if (curr.mtime !== prev.mtime) {
console.log(`File ${file} changed. Restarting...`)
unwatchFile(scriptPath)
start(file)
}
})
} else {
console.log("Process exited successfully. Unwatching file.")
unwatchFile(scriptPath)
childProcess = null
}
})
}
start("client.js")