-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathzip.js
More file actions
28 lines (23 loc) · 786 Bytes
/
zip.js
File metadata and controls
28 lines (23 loc) · 786 Bytes
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 archiver from "archiver";
import { createWriteStream, readFileSync, rmSync, existsSync } from "fs";
import { join } from "path";
const { name } = JSON.parse(readFileSync("./package.json"));
const cwd = process.cwd();
const zipPath = join(cwd, `${name}-submission.zip`);
const output = createWriteStream(zipPath);
const archive = archiver("zip", {
zlib: { level: 9 },
});
archive.pipe(output);
archive.directory("src/", "ts/");
if (existsSync('out/src')) {
archive.glob("*.js", { cwd: join(".", "out", "src") }, { prefix: "js/" })
} else {
archive.directory("out/", "js/")
}
archive.on("finish", () => {
output.close();
rmSync(join(".", "out"), { recursive: true, force: true });
console.log("Successfully zipped submission: " + zipPath);
});
archive.finalize();