-
Notifications
You must be signed in to change notification settings - Fork 110
/
bundle-web.ts
41 lines (36 loc) · 1.19 KB
/
bundle-web.ts
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
41
import { bundle } from "https://deno.land/x/[email protected]/mod.ts";
import { createCache } from "https://deno.land/x/[email protected]/mod.ts";
// Parse args
const [release, source = `https://deno.land/x/grammy@${release}/mod.ts`] =
Deno.args;
if (!release) throw new Error("No release specified!");
// Rewrite imports from .deno.ts to .web.ts
const cache = createCache();
const load = (specifier: string) => {
if (specifier.endsWith(".deno.ts")) {
const baseLength = specifier.length - ".deno.ts".length;
specifier = specifier.substring(0, baseLength) + ".web.ts";
}
return cache.load(specifier);
};
console.log(`Bundling version '${release}' from ${source} ...`);
// Bundle code
const { code: bundledCode } = await bundle(source, {
load,
compilerOptions: {
sourceMap: false,
inlineSources: false,
inlineSourceMap: false,
},
});
console.log("Emitting ...");
// Strip the huge inline source map which is somehow generated anyway
await Deno.writeTextFile(
"../out/web.mjs",
bundledCode.replace(/\/\/# sourceMappingURL=.*\n/, ""),
);
await Deno.writeTextFile(
"../out/web.d.ts",
'export * from "./mod";\n',
);
console.log("Done.");