Skip to content

Commit

Permalink
Update bundle.js
Browse files Browse the repository at this point in the history
  • Loading branch information
txthinking authored Apr 19, 2024
1 parent d651da0 commit 18a29c1
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ var dir = process.argv[2].endsWith("/") ? process.argv[2].slice(0, -1) : process
var output = process.argv.length >= 4 ? process.argv[3] : "bundle.js"

var f = await fs.open(output, 'w');
await fs.write(f, new TextEncoder().encode(`var m = {};\n`));
await f.write(new TextEncoder().encode(`var m = {};\n`));
var l = await fs.readdir(dir, { recursive: true, withFileTypes: true })
for (var v of l) {
if (v.isFile()) {
var k = dir + "/" + v.name
k = k.replace(dir, path.basename(dir))
await fs.write(f, new TextEncoder().encode(`m["${k}"] = new Uint8Array([`));
await f.write(new TextEncoder().encode(`m["${k}"] = new Uint8Array([`));
var b = new Uint8Array(await Bun.file(path.join(dir, v.name)).arrayBuffer());
for (var j = 0; j < b.length; j++) {
await fs.write(f, new TextEncoder().encode(`${b[j]},`));
await f.write(new TextEncoder().encode(`${b[j]},`));
}
await fs.write(f, new TextEncoder().encode(`]);\n`));
await f.write(new TextEncoder().encode(`]);\n`));
}
}
await fs.write(f, new TextEncoder().encode(`export default function(k){if(m[k]) return m[k]; throw 'NotFound';}\n`));
await fs.close(f)
await f.write(new TextEncoder().encode(`export default function(k){if(m[k]) return m[k]; throw 'NotFound';}\n`));
await f.close()

0 comments on commit 18a29c1

Please sign in to comment.