silverbullet/scripts/generate_fs_list.ts

33 lines
915 B
TypeScript
Raw Normal View History

2024-07-30 23:24:17 +08:00
import { walk } from "@std/fs/walk";
import { resolve } from "@std/path";
import { mime } from "mimetypes";
2024-07-30 23:33:33 +08:00
import type { FileMeta } from "../plug-api/types.ts";
2022-10-29 22:27:16 +08:00
const rootDir = resolve("website_build");
const lastModifiedTimestamp = +Deno.env.get("LAST_MODIFIED_TIMESTAMP")! ||
Date.now();
2022-10-29 22:27:16 +08:00
const allFiles: FileMeta[] = [];
for await (
const file of walk(rootDir, {
includeDirs: false,
// Exclude hidden files
skip: [
/^.*\/(\..+|_redirects|_headers|service_worker\.js.*|index\.json|_client\/.*)$/,
],
2022-10-29 22:27:16 +08:00
})
) {
const fullPath = file.path;
const s = await Deno.stat(fullPath);
allFiles.push({
name: fullPath.substring(rootDir.length + 1),
lastModified: lastModifiedTimestamp,
created: lastModifiedTimestamp,
2022-10-29 22:27:16 +08:00
contentType: mime.getType(fullPath) || "application/octet-stream",
size: s.size,
perm: "rw",
});
}
console.log(JSON.stringify(allFiles, null, 2));