2022-11-04 16:11:33 +00:00
|
|
|
import fs from "fs/promises";
|
|
|
|
import path from "path";
|
2024-06-13 18:03:58 +00:00
|
|
|
import url from "url";
|
2022-11-04 16:11:33 +00:00
|
|
|
import archiver from "archiver";
|
2021-03-09 19:11:46 +00:00
|
|
|
|
2024-06-08 22:48:01 +00:00
|
|
|
async function zip(source: string, destination: string) {
|
2022-11-04 16:11:33 +00:00
|
|
|
await fs.mkdir(path.dirname(destination), { recursive: true });
|
|
|
|
const output = (await fs.open(destination, "w")).createWriteStream();
|
|
|
|
const archive = archiver("zip");
|
2021-03-09 19:11:46 +00:00
|
|
|
|
|
|
|
output.on("close", () => {
|
|
|
|
console.log(
|
2023-07-20 11:19:39 +00:00
|
|
|
`Extension is ${archive.pointer()} total bytes when packaged.`,
|
2021-03-09 19:11:46 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2022-11-04 16:11:33 +00:00
|
|
|
archive.on("error", (error) => {
|
|
|
|
throw error;
|
2021-03-09 19:11:46 +00:00
|
|
|
});
|
|
|
|
|
2022-11-04 16:11:33 +00:00
|
|
|
archive.on("warning", (error) => {
|
|
|
|
if (error.code === "ENOENT") {
|
|
|
|
console.warn(`Warning whilst zipping extension: ${error}`);
|
2021-03-09 19:11:46 +00:00
|
|
|
} else {
|
2022-11-04 16:11:33 +00:00
|
|
|
throw error;
|
2021-03-09 19:11:46 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
archive.pipe(output);
|
|
|
|
|
|
|
|
archive.directory(source, "");
|
|
|
|
|
|
|
|
await archive.finalize();
|
|
|
|
}
|
2024-06-13 18:03:58 +00:00
|
|
|
const assets = url.fileURLToPath(new URL("../assets/", import.meta.url));
|
|
|
|
zip(assets, process.argv[2] ?? "").catch(console.error);
|