Files
anidev-design-system/scripts/vendor-terminal.mjs
T

37 lines
1.2 KiB
JavaScript

import { readFile, writeFile, mkdir } from "node:fs/promises";
const root = new URL("../", import.meta.url),
out = new URL("vendor/xterm/", root);
await mkdir(out, { recursive: true });
const packages = [
["@xterm/xterm", "xterm"],
["@xterm/addon-fit", "addon-fit"],
["@xterm/addon-search", "addon-search"],
];
const manifest = [];
for (const [pkg, name] of packages) {
const dir = new URL(`node_modules/${pkg}/`, root),
meta = JSON.parse(await readFile(new URL("package.json", dir), "utf8"));
const source = await readFile(new URL(meta.module, dir), "utf8");
await writeFile(
new URL(name + ".js", out),
source.replace(/^\/\/# sourceMappingURL=.*$/gm, ""),
);
await writeFile(
new URL(name + ".LICENSE", out),
await readFile(new URL("LICENSE", dir)),
);
manifest.push({ package: pkg, version: meta.version, license: meta.license });
}
await writeFile(
new URL("xterm.css", out),
await readFile(new URL("node_modules/@xterm/xterm/css/xterm.css", root)),
);
await writeFile(
new URL("manifest.json", out),
JSON.stringify(manifest, null, 2) + "\n",
);
console.log(
"Vendored terminal runtime:",
manifest.map((p) => `${p.package}@${p.version}`).join(", "),
);