-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-cache-list.js
34 lines (29 loc) · 908 Bytes
/
generate-cache-list.js
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
const fs = require("fs");
const path = require("path");
const publicDir = path.join(__dirname, "public");
const cacheList = [];
function shouldCache(filePath) {
const fileName = path.basename(filePath);
const excludePatterns = [".DS_Store"];
return !excludePatterns.includes(fileName);
}
function walkDir(dir, callback) {
fs.readdirSync(dir).forEach((f) => {
const dirPath = path.join(dir, f);
const isDirectory = fs.statSync(dirPath).isDirectory();
if (isDirectory) {
walkDir(dirPath, callback);
} else if (shouldCache(dirPath)) {
callback(path.join(dir, f));
}
});
}
walkDir(publicDir, (filePath) => {
const relativePath = path.relative(publicDir, filePath).replace(/\\/g, "/");
cacheList.push("/" + relativePath);
});
fs.writeFileSync(
"public/urls-to-cache.json",
JSON.stringify(cacheList, null, 2)
);
console.log("Generated 'urls-to-cache.json`");