-
Notifications
You must be signed in to change notification settings - Fork 0
/
zip.js
37 lines (30 loc) · 875 Bytes
/
zip.js
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
const { loadConfig, createRsbuild, logger } = require("@rsbuild/core");
const fs = require("fs");
const archiver = require("archiver");
async function zip() {
const { content } = await loadConfig();
const rsbuild = await createRsbuild({
rsbuildConfig: content,
});
await rsbuild.build();
const sourceDir = "./dist";
const outputFile = "./widget.zip";
const output = fs.createWriteStream("./widget.zip");
const archive = archiver("zip", {
zlib: { level: 9 },
});
output.on("close", () =>
console.info(
`Archive created at ${outputFile}, with ${archive.pointer()} total bytes.`
)
);
archive.on("error", (err) => console.error(err));
archive.pipe(output);
archive.directory(sourceDir, "widget");
archive.finalize();
}
zip().catch((e) => {
logger.error("Failed to build.");
logger.error(err);
process.exit(1);
});