1
0
silverbullet/scripts/generate_fs_list.js
2022-09-05 11:47:30 +02:00

30 lines
807 B
JavaScript

const { resolve } = require("path");
const { readdir } = require("fs").promises;
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;
})
);
return Array.prototype.concat(...files);
}
const rootDir = resolve("website_build/page");
getFiles(rootDir).then((files) => {
files = files
.map((file) => ({
name: file
.substring(rootDir.length + 1)
.replace(/\.md$/, "")
.replace(/\.plug\.json$/, ""),
lastModified: 0,
perm: "rw",
}))
.filter((pageMeta) => !pageMeta.name.startsWith("."));
console.log(JSON.stringify(files, null, 2));
});