Skip to content

Commit

Permalink
chore(watch): add a debounce for watch script
Browse files Browse the repository at this point in the history
  • Loading branch information
fu050409 committed Aug 2, 2024
1 parent e720067 commit a08fb1b
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions scripts/watch.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ tryBuild('yarn build:examples', 'Building examples...')
console.log('[Archons] Build complete.\n')
console.log(`[Archons] Watching on ${dirPath} for changes...`)

let lastBuild = Date.now()
fs.watch(dirPath, { recursive: true }, (eventType, filename) => {
// debounce
if (Date.now() - lastBuild < 1000) {
return
}
if (filename && !isIgnored(filename)) {
console.log(`[Archons] File ${filename} was ${eventType}d, rebuilding...`)
if (filename.endsWith('.rs') || filename.endsWith('.toml')) {
Expand All @@ -40,5 +45,6 @@ fs.watch(dirPath, { recursive: true }, (eventType, filename) => {
tryBuild('yarn build:examples', 'Rebuilding examples...')
console.log('[Archons] Build complete.\n')
console.log('[Archons] Watching for changes...')
lastBuild = Date.now()
}
})

0 comments on commit a08fb1b

Please sign in to comment.