Refactor of asset bundles

This commit is contained in:
Zef Hemel
2022-10-12 11:47:13 +02:00
parent 9dd94c5397
commit 4c19ab21f2
96 changed files with 6279 additions and 770 deletions
+34
View File
@@ -0,0 +1,34 @@
import { globToRegExp, path, walk } from "../deps.ts";
import { AssetBundle } from "./bundle.ts";
export async function bundleAssets(
rootPath: string,
patterns: string[],
): Promise<AssetBundle> {
const bundle = new AssetBundle();
for await (
const file of walk(rootPath, {
match: patterns.map((pat) => globToRegExp(pat)),
})
) {
const cleanPath = file.path.substring("".length);
await bundle.writeFileSync(cleanPath, await Deno.readFile(file.path));
}
return bundle;
}
export async function bundleFolder(rootPath: string, bundlePath: string) {
const bundle = new AssetBundle();
await Deno.mkdir(path.dirname(bundlePath), { recursive: true });
for await (
const { path: filePath } of walk(rootPath, { includeDirs: false })
) {
console.log("Bundling", filePath);
const cleanPath = filePath.substring(`${rootPath}/`.length);
await bundle.writeFileSync(cleanPath, await Deno.readFile(filePath));
}
await Deno.writeTextFile(
bundlePath,
JSON.stringify(bundle.toJSON(), null, 2),
);
}