-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzipit.js
More file actions
69 lines (54 loc) · 1.57 KB
/
zipit.js
File metadata and controls
69 lines (54 loc) · 1.57 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// zipit.js
// Usage: node zipit.js
// Creates: projectName_MMDDYY_HHMMam.zip (e.g. projectName_020426_0130pm.zip)
const fs = require("fs");
const path = require("path");
const archiver = require("archiver");
// ==== EDIT THIS ====
const PROJECT_NAME = "nesviz";
// ===================
function pad2(n) {
return String(n).padStart(2, "0");
}
function stamp(d) {
const mm = pad2(d.getMonth() + 1);
const dd = pad2(d.getDate());
const yy = pad2(d.getFullYear() % 100);
let h = d.getHours();
const ampm = h >= 12 ? "pm" : "am";
h = h % 12;
if (h === 0) h = 12;
const hh = pad2(h);
const min = pad2(d.getMinutes());
return `${mm}${dd}${yy}_${hh}${min}${ampm}`;
}
const outName = `${PROJECT_NAME}_${stamp(new Date())}.zip`;
const outPath = path.join(process.cwd(), outName);
const output = fs.createWriteStream(outPath);
const archive = archiver("zip", { zlib: { level: 9 } });
output.on("close", () => {
console.log(`Wrote ${outName} (${archive.pointer()} bytes)`);
});
archive.on("warning", (err) => {
// log non-fatal warnings, but still fail on everything else
if (err.code === "ENOENT") console.warn(err.message);
else throw err;
});
archive.on("error", (err) => {
console.error("Zip failed:", err);
process.exit(1);
});
archive.pipe(output);
// include everything from project root, including dotfiles,
// but exclude .git and any node_modules anywhere
archive.glob("**/*", {
cwd: process.cwd(),
dot: true,
ignore: [
outName, // don't zip the zip we’re creating
"**/.git/**",
"**/node_modules/**",
"*.zip"
],
});
archive.finalize();