alinea
Version:
Headless git-based CMS
40 lines (38 loc) • 893 B
JavaScript
import {
pLimit
} from "../../chunks/chunk-C53YJRET.js";
import "../../chunks/chunk-NZLE2WMY.js";
// src/cli/generate/FillCache.ts
import { createEmitter } from "../util/Emitter.js";
import { reportError } from "../util/Report.js";
import { createWatcher } from "../util/Watcher.js";
function fillCache(db, fix) {
let canceled = false;
let stopWatching = () => {
canceled = true;
};
const results = createEmitter({
onReturn() {
stopWatching();
}
});
const limit = pLimit(1);
const run = () => limit(cache).then(results.emit, reportError);
const cache = async () => {
await db.sync();
if (fix) await db.fix();
return db;
};
createWatcher({
watchFiles: db.watchFiles.bind(db),
onChange: run
}).then((cancel) => {
if (canceled) cancel();
else stopWatching = cancel;
});
run();
return results;
}
export {
fillCache
};