silverbullet/common/json_bundle.ts

13 lines
552 B
TypeScript
Raw Normal View History

2022-10-07 22:27:47 +08:00
import { walk } from "https://deno.land/std@0.159.0/fs/mod.ts";
2022-10-08 22:47:55 +08:00
import { base64Encode } from "./base64.ts";
2022-10-07 22:27:47 +08:00
export async function bundleFolder(path: string, bundlePath: string) {
const bundle: Record<string, string> = {};
for await (const { path: filePath } of walk(path, { includeDirs: false })) {
console.log("Bundling", filePath);
2022-10-08 21:46:56 +08:00
const b64content = base64Encode(await Deno.readFile(filePath));
2022-10-08 22:47:55 +08:00
bundle[filePath.substring(path.length + 1)] = b64content;
2022-10-07 22:27:47 +08:00
}
await Deno.writeTextFile(bundlePath, JSON.stringify(bundle, null, 2));
}