@deftomat/opinionated
Version:
Opinionated tooling for JavaScript & TypeScript projects.
30 lines (29 loc) • 1.14 kB
JavaScript
import Configstore from 'configstore';
const incompleteChecksTTL = 60 * 60 * 1000;
const incompleteChecksKey = 'incompleteChecks';
const store = new Configstore('@deftomat/opinionated', { [incompleteChecksKey]: [] });
export function updateIncompleteChecks({ projectRoot }, checks) {
const now = Date.now();
const entries = store.get(incompleteChecksKey);
const index = entries.findIndex(entryFor(projectRoot, now));
const entry = { key: projectRoot, at: now, checks: Array.from(checks) };
if (index === -1) {
entries.push(entry);
}
else {
entries[index] = entry;
}
const valid = entries.filter(({ at }) => now <= at + incompleteChecksTTL);
store.set(incompleteChecksKey, valid);
}
export function getIncompleteChecks({ projectRoot }) {
const now = Date.now();
const incomplete = store.get(incompleteChecksKey);
const entry = incomplete.find(entryFor(projectRoot, now));
if (entry)
return new Set(entry.checks);
return new Set();
}
function entryFor(projectRoot, now) {
return ({ key, at }) => key === projectRoot && now <= at + incompleteChecksTTL;
}