| | |
| | | import serveHandler from "serve-handler" |
| | | import { WebSocketServer } from "ws" |
| | | import { randomUUID } from "crypto" |
| | | import { Mutex } from "async-mutex" |
| | | |
| | | const ORIGIN_NAME = "origin" |
| | | const UPSTREAM_NAME = "upstream" |
| | |
| | | ], |
| | | }) |
| | | |
| | | const buildMutex = new Mutex() |
| | | const timeoutIds = new Set() |
| | | const build = async (clientRefresh) => { |
| | | await buildMutex.acquire() |
| | | const result = await ctx.rebuild().catch((err) => { |
| | | console.error(`${chalk.red("Couldn't parse Quartz configuration:")} ${fp}`) |
| | | console.log(`Reason: ${chalk.grey(err)}`) |
| | |
| | | const { default: buildQuartz } = await import(cacheFile + `?update=${randomUUID()}`) |
| | | await buildQuartz(argv, clientRefresh) |
| | | clientRefresh() |
| | | buildMutex.release() |
| | | } |
| | | |
| | | const rebuild = (clientRefresh) => { |
| | | timeoutIds.forEach((id) => clearTimeout(id)) |
| | | timeoutIds.clear() |
| | | timeoutIds.add(setTimeout(() => build(clientRefresh), 250)) |
| | | } |
| | | |