forked from SlavyanDesu/BocchiBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloader.js
More file actions
40 lines (36 loc) · 1.04 KB
/
Copy pathloader.js
File metadata and controls
40 lines (36 loc) · 1.04 KB
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
const fs = require('fs-extra')
const { color } = require('../tools')
const getAllDirFiles = (dirPath, arrayOfFiles) => {
const files = fs.readdirSync(dirPath)
arrayOfFiles = arrayOfFiles || []
files.forEach((f) => {
if (fs.statSync(dirPath + '/' + f).isDirectory()) {
arrayOfFiles = getAllDirFiles(dirPath + '/' + f, arrayOfFiles)
} else {
arrayOfFiles.push(f)
}
})
return arrayOfFiles
}
const uncache = (module = '.') => {
return new Promise((resolve, reject) => {
try {
delete require.cache[require.resolve(module)]
resolve()
} catch (err) {
reject(err)
}
})
}
const nocache = (module, call = () => { }) => {
console.log(color('[WATCH]', 'orange'), color(`=> '${module}'`, 'yellow'), 'file is now being watched by me!')
fs.watchFile(require.resolve(module), async () => {
await uncache(require.resolve(module))
call(module)
})
}
module.exports = {
getAllDirFiles,
uncache,
nocache
}