2020-05-13 16:00:14 +00:00
|
|
|
#!/usr/bin/env -S deno run --allow-run --allow-net
|
2020-05-13 14:39:34 +00:00
|
|
|
// Automated bundle server
|
|
|
|
|
|
|
|
import { serve } from "https://deno.land/std/http/server.ts";
|
|
|
|
import { bool } from "https://code.thunderk.net/typescript/functional/raw/1.0.0/all.ts";
|
|
|
|
|
2020-05-13 16:00:14 +00:00
|
|
|
async function serveBundles() {
|
|
|
|
const listen = { hostname: "0.0.0.0", port: 8000 };
|
|
|
|
const server = serve(listen);
|
|
|
|
console.log(`Serving bundles on ${listen.hostname}:${listen.port} ...`);
|
|
|
|
for await (const req of server) {
|
|
|
|
const params = req.url.split("/").filter(bool);
|
|
|
|
const lib = params[0] || "all";
|
|
|
|
const version = params[1] || "master";
|
|
|
|
const file = params.length > 2 ? params.slice(2).join("/") : "all";
|
|
|
|
const path =
|
|
|
|
`https://code.thunderk.net/typescript/${lib}/raw/${version}/${file}.ts`;
|
2020-05-13 14:39:34 +00:00
|
|
|
|
2020-05-13 16:00:14 +00:00
|
|
|
try {
|
|
|
|
const process = Deno.run({
|
|
|
|
cmd: ["deno", "bundle", path],
|
|
|
|
stdout: "piped",
|
|
|
|
});
|
|
|
|
req.respond({ body: await process.output() });
|
|
|
|
} catch {
|
|
|
|
req.respond({ body: `console.error("Failed to bundle ${path}");` });
|
|
|
|
}
|
2020-05-13 14:39:34 +00:00
|
|
|
}
|
|
|
|
}
|
2020-05-13 16:00:14 +00:00
|
|
|
|
|
|
|
await serveBundles();
|