forked from kpverse/ArchGemini
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-release.js
54 lines (45 loc) · 1.32 KB
/
create-release.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const archiver = require("archiver");
const fs = require("fs");
const path = require("path");
// Create a writable stream for the zip file
const output = fs.createWriteStream("release.zip");
const archive = archiver("zip", {
zlib: { level: 9 }, // compression level
});
// Specify the files and folders to be included in the zip
const filesToZip = [
"back-end/bin/index.cjs.js",
"front-end/out/",
"LICENSE",
"package.json",
"README.md",
];
// Listen for all archive data to be written
output.on("close", () => {
console.log(`${archive.pointer()} total bytes`);
console.log(
"archiver has been finalized and the output file descriptor has closed."
);
});
archive.on("warning", (err) => {
if (err.code === "ENOENT") {
console.warn(err);
} else {
// throw error
throw err;
}
});
archive.on("error", (err) => {
throw err;
});
// Pipe archive data to the file
archive.pipe(output);
// Add files and folders to the archive
filesToZip.forEach((fileOrFolder) => {
const fullPath = path.resolve(__dirname, fileOrFolder);
const stats = fs.statSync(fullPath);
if (stats.isDirectory()) archive.directory(fullPath, fileOrFolder);
else archive.file(fullPath, { name: fileOrFolder });
});
// Finalize the archive (write the zip file)
archive.finalize();