Asset fixes

This commit is contained in:
Zef Hemel
2022-10-14 15:53:51 +02:00
parent 7d28b53b75
commit 3a3210ecac
6 changed files with 27 additions and 15 deletions
+18 -6
View File
@@ -6,13 +6,25 @@ export async function bundleAssets(
patterns: string[],
): Promise<AssetBundle> {
const bundle = new AssetBundle();
if (patterns.length === 0) {
return bundle;
}
const matchRegexes = patterns.map((pat) => globToRegExp(pat));
for await (
const file of walk(rootPath, {
match: patterns.map((pat) => globToRegExp(pat)),
})
const file of walk(rootPath)
) {
const cleanPath = file.path.substring("".length);
await bundle.writeFileSync(cleanPath, await Deno.readFile(file.path));
const cleanPath = file.path.substring(rootPath.length + 1);
let match = false;
// console.log("Considering", rootPath, file.path, cleanPath);
for (const matchRegex of matchRegexes) {
if (matchRegex.test(cleanPath)) {
match = true;
break;
}
}
if (match) {
bundle.writeFileSync(cleanPath, await Deno.readFile(file.path));
}
}
return bundle;
}
@@ -25,7 +37,7 @@ export async function bundleFolder(rootPath: string, bundlePath: string) {
) {
console.log("Bundling", filePath);
const cleanPath = filePath.substring(`${rootPath}/`.length);
await bundle.writeFileSync(cleanPath, await Deno.readFile(filePath));
bundle.writeFileSync(cleanPath, await Deno.readFile(filePath));
}
await Deno.writeTextFile(
bundlePath,
+4 -2
View File
@@ -26,13 +26,15 @@ export async function bundle(
}
// Dependencies
for (let [name, moduleSpec] of Object.entries(manifest.dependencies || {})) {
for (
const [name, moduleSpec] of Object.entries(manifest.dependencies || {})
) {
manifest.dependencies![name] = await sandboxCompileModule(moduleSpec);
}
// Assets
const assetsBundle = await bundleAssets(
rootPath,
path.resolve(rootPath),
manifest.assets as string[] || [],
);
manifest.assets = assetsBundle.toJSON();