-
Notifications
You must be signed in to change notification settings - Fork 98
Expand file tree
/
Copy pathindex.js
More file actions
64 lines (54 loc) · 1.64 KB
/
index.js
File metadata and controls
64 lines (54 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { readdir } from 'fs/promises';
import { join } from 'path';
const CACHE_DIR = '.docforge-cache';
const CACHE_TTL = 86400;
async function collectDigests(baseDir) {
const digests = [];
async function walk(dir) {
let entries;
try {
entries = await readdir(dir, { withFileTypes: true });
} catch (err) {
if (err.code === 'ENOENT') return;
throw err;
}
for (const entry of entries) {
const fullPath = join(dir, entry.name);
if (entry.isDirectory()) {
await walk(fullPath);
} else if (entry.isFile() && entry.name.endsWith('.yaml')) {
digests.push(fullPath);
}
}
}
await walk(baseDir);
return digests;
}
export const onPreBuild = async function ({ utils }) {
if (process.env.CONTEXT === 'production') {
console.log('Production build — skipping docforge cache (always fresh).');
return;
}
const restored = await utils.cache.restore(CACHE_DIR);
if (restored) {
console.log('Docforge cache restored from previous build.');
} else {
console.log('No docforge cache found — will be populated after this build.');
}
};
export const onPostBuild = async function ({ utils }) {
if (process.env.CONTEXT === 'production') {
console.log('Production build — not saving docforge cache.');
return;
}
const digests = await collectDigests('.docforge');
const saved = await utils.cache.save(CACHE_DIR, {
ttl: CACHE_TTL,
digests,
});
if (saved) {
console.log(`Docforge cache saved (TTL: 24h, tracking ${digests.length} digest files).`);
} else {
console.log('Docforge cache directory not found — nothing to save.');
}
};