1
0
silverbullet/scripts/generate_fs_list.js

30 lines
818 B
JavaScript
Raw Normal View History

2022-07-15 09:51:54 +00:00
const { resolve } = require("path");
const { readdir } = require("fs").promises;
2022-09-13 06:57:04 +00:00
const mime = require("mime-types");
2022-07-15 09:51:54 +00:00
async function getFiles(dir) {
const dirents = await readdir(dir, { withFileTypes: true });
const files = await Promise.all(
dirents.map((dirent) => {
const res = resolve(dir, dirent.name);
return dirent.isDirectory() ? getFiles(res) : res;
2022-10-12 09:47:13 +00:00
}),
2022-07-15 09:51:54 +00:00
);
return Array.prototype.concat(...files);
}
2022-09-13 06:46:30 +00:00
const rootDir = resolve("website_build/fs");
2022-07-15 09:51:54 +00:00
getFiles(rootDir).then((files) => {
2022-07-15 10:57:05 +00:00
files = files
.map((file) => ({
2022-09-13 06:46:30 +00:00
name: file.substring(rootDir.length + 1),
2022-07-15 10:57:05 +00:00
lastModified: 0,
2022-09-13 06:57:04 +00:00
contentType: mime.lookup(file),
size: 0,
2022-07-15 12:30:43 +00:00
perm: "rw",
2022-07-15 10:57:05 +00:00
}))
.filter((pageMeta) => !pageMeta.name.startsWith("."));
2022-07-15 09:51:54 +00:00
console.log(JSON.stringify(files, null, 2));
});