-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathwatchChanges.js
80 lines (74 loc) · 2.08 KB
/
watchChanges.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
77
78
79
80
{ require("./other/patchConsoleLog"); require("./config"); };
const chokidar = require('chokidar');
const { resolve } = require('path');
const { makeSureFolderExists, execAsync } = require('stuffs');
class FunctionQueue {
/**
*
* @param {Number} interval
* @param {Function} cb
*/
constructor(interval, cb) {
this.interval = interval;
this.cb = cb;
this.lastCall = 0;
this.willTrigger = false;
}
async trigger(...args) {
let now = Date.now();
if (this.lastCall < now) {
this.lastCall = now + this.interval;
await this.cb(...args);
} else {
if (this.lastCall < now - 1500) return;
if (!this.willTrigger) {
this.willTrigger = true;
setTimeout(async () => {
this.lastCall = Date.now() + this.interval;
this.willTrigger = false;
await this.cb(...args);
}, this.lastCall - now);
}
}
}
};
let TypeQueue = new FunctionQueue(15000, async () => {
let { stderr, stdout } = await execAsync("yarn tipler", process.cwd());
console.log(stdout.toLowerCase().includes("[hata]") ? stdout : "Tipler yüklendi.");
});
let wait = (s) => new Promise((resolve => setTimeout(() => resolve(true), s)));
(async () => {
await wait(1000);
[
{
path: "./events",
name: "Events",
text: "Eventler izleniyor.",
},
{
path: "./interactions",
name: "Interactions",
text: 'Interaksiyonlar izleniyor',
},
{
path: "./plugins",
name: "Plugins",
text: 'Pluginler izleniyor',
},
{
path: "./locales",
name: "Locales",
text: 'Dil dosyaları izleniyor',
}
].forEach(async (ctx) => {
let path = resolve(ctx.path);
await makeSureFolderExists(path);
const theWatcher = chokidar.watch(path, { persistent: true });
theWatcher
.on('add', () => TypeQueue.trigger())
.on('change', () => TypeQueue.trigger())
.on('unlink', () => TypeQueue.trigger())
.on('error', error => console.log(`${ctx.name} Watcher Error: ${error}`))
.on('ready', () => console.log(ctx.text))
});
})();