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
33
34
35
36
37
38
39
40
import { extractValInfo } from "https://esm.town/v/pomdtr/extractValInfo";
import { gfm } from "https://esm.town/v/pomdtr/gfm";
import { readme } from "https://esm.town/v/pomdtr/readme";
import { Hono } from "npm:hono@3.11.11";
const script = (esmUrl) =>
`#!/bin/sh
# check if deno is installed
if ! command -v deno >/dev/null; then
echo "Please install deno first: https://deno.land/#installation"
exit 1
fi
exec deno eval --quiet --reload=https://esm.town/v/ '(await import("${esmUrl}")).default()' "$@"
`;
const app = new Hono();
app.get("/", async c => {
const html = await gfm(await readme());
return c.html(html);
});
app.get("/v/:author/:name", c => {
const { author, name } = c.req.param();
const { version } = c.req.query();
let esmUrl = `https://esm.town/v/${author}/${name}`;
if (version) {
esmUrl = `${esmUrl}?version=${version}`;
}
return new Response(script(esmUrl));
});
export default app.fetch;
// #cli