forked from yt-dlp/ejs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.mjs
More file actions
32 lines (29 loc) · 861 Bytes
/
build.mjs
File metadata and controls
32 lines (29 loc) · 861 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import * as esbuild from "esbuild";
const buildConfig = await stdinJSON();
const result = await esbuild.build(buildConfig);
console.log(JSON.stringify(result.metafile ?? null));
await esbuild.stop();
async function stdinJSON() {
const chunks = [];
if (globalThis.Deno) {
for await (const chunk of globalThis.Deno.stdin.readable) {
chunks.push(chunk);
}
const length = chunks.reduce(
(previous, chunk) => previous + chunk.length,
0,
);
const buffer = new Uint8Array(length);
let offset = 0;
for (const chunk of chunks) {
buffer.set(chunk, offset);
offset += chunk.length;
}
return JSON.parse(new TextDecoder().decode(buffer));
}
for await (const chunk of process.stdin) {
chunks.push(chunk);
}
const text = Buffer.concat(chunks).toString("utf-8");
return JSON.parse(text);
}