mirror of
https://github.com/ragestudio/linebridge.git
synced 2025-06-09 10:34:17 +00:00
30 lines
672 B
JavaScript
30 lines
672 B
JavaScript
const chokidar = require("chokidar")
|
|
const { minimatch } = require("minimatch")
|
|
|
|
const defaultIgnored = [
|
|
"**/.cache/**",
|
|
"**/node_modules/**",
|
|
"**/dist/**",
|
|
"**/build/**",
|
|
]
|
|
|
|
module.exports = async (fromPath, { onReload }) => {
|
|
console.log("[WATCHER] Starting watching path >", fromPath)
|
|
|
|
global._watcher = chokidar.watch(fromPath, {
|
|
ignored: (path) =>
|
|
defaultIgnored.some((pattern) => minimatch(path, pattern)),
|
|
persistent: true,
|
|
ignoreInitial: true,
|
|
awaitWriteFinish: true,
|
|
})
|
|
|
|
global._watcher.on("all", (event, filePath) => {
|
|
console.log(`[WATCHER] Event [${event}] > ${filePath}`)
|
|
|
|
if (typeof onReload === "function") {
|
|
onReload()
|
|
}
|
|
})
|
|
}
|