fix rebuild debouncing

This commit is contained in:
Jacky Zhao 2023-08-17 01:58:11 -07:00
parent 07a327e05a
commit 0998bc355e
3 changed files with 42 additions and 37 deletions

View file

@ -355,6 +355,7 @@ See the [documentation](https://quartz.jzhao.xyz) for how to get started.
],
})
const timeoutIds = new Set()
const build = async (clientRefresh) => {
const result = await ctx.rebuild().catch((err) => {
console.error(`${chalk.red("Couldn't parse Quartz configuration:")} ${fp}`)
@ -380,6 +381,11 @@ See the [documentation](https://quartz.jzhao.xyz) for how to get started.
clientRefresh()
}
const rebuild = (clientRefresh) => {
timeoutIds.forEach((id) => clearTimeout(id))
timeoutIds.add(setTimeout(() => build(clientRefresh), 250))
}
if (argv.serve) {
const wss = new WebSocketServer({ port: 3001 })
const connections = []
@ -457,7 +463,7 @@ See the [documentation](https://quartz.jzhao.xyz) for how to get started.
})
.on("all", async () => {
console.log(chalk.yellow("Detected a source code change, doing a hard rebuild..."))
await build(clientRefresh)
rebuild(clientRefresh)
})
} else {
await build(() => {})