-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod.ts
28 lines (27 loc) · 902 Bytes
/
mod.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
import { Command } from "https://deno.land/x/cliffy@v1.0.0-rc.3/command/mod.ts";
import { loadSwc, transform } from "~/minifier/swc.ts";
import type { Config } from "https://esm.sh/v135/@swc/types@0.1.6";
await new Command()
.name("minify-runner")
.arguments("<name@semver:string> <code:string>")
.action(async (_, nameWithSemver, code) => {
const [name, semver] = nameWithSemver.split("@");
switch (name) {
case "swc":
const swcModule = await loadSwc(semver);
const config = JSON.parse(
await Deno.readTextFile(new URL(".swcrc", import.meta.url)),
) as Config;
const { code: output } = transform({
code,
config,
filename: "tmp.js",
swc: swcModule,
});
console.log(output.trim());
return;
default:
throw "invalid minifier name";
}
})
.parse(Deno.args);