-
-
Notifications
You must be signed in to change notification settings - Fork 106
/
delay.js
40 lines (34 loc) · 1.02 KB
/
delay.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
import fs from "fs-extra";
import path from "path";
let maxWait = 5000;
let interval = 1000;
let waitTime = 0;
let serverDataPath = path.join(process.cwd(), "database", "server.json");
let siteDataPath = path.join(process.cwd(), "database", "site.json");
let monitorsDataPath = path.join(process.cwd(), "database", "monitors.json");
function allFilesExist() {
return (
fs.existsSync(serverDataPath) &&
fs.existsSync(siteDataPath) &&
fs.existsSync(monitorsDataPath)
);
}
//use setTimeout to create a delay promise
function delay(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
let requiredFilesExist = allFilesExist();
//create anonymous function to call the init function
(async function init() {
while (!requiredFilesExist && waitTime < maxWait) {
await delay(1000);
requiredFilesExist = allFilesExist();
waitTime += interval;
}
if (!requiredFilesExist) {
console.error("Error loading site data");
process.exit(1);
} else {
console.log("✅ All files exist. Starting Frontend server...");
}
})();