forked from hgwood/hash-code-tooling
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zip.js
36 lines (32 loc) · 1.05 KB
/
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
const _ = require("lodash");
const fs = require("fs");
const archiver = require("archiver");
const glob = require("glob");
const path = require("path");
const exec = require("child_process").execSync;
try {
exec("npm run prettier && git add *.js && git commit -m 'tayo!'", {
encoding: "utf8"
});
} catch (err) {
console.warn("could not commit because", err, "continuing anyway");
}
const buildDir =
process.env.BUILD_DIR || process.env.npm_package_config_buildDir || ".builds";
const sha1 = exec("git rev-parse HEAD", { encoding: "utf8" }).trim();
const date = new Date().toISOString().replace(/:/g, "-");
const dest = path.join(
__dirname,
buildDir,
`submission-sources-${date}-${sha1}.zip`
);
try {
fs.mkdirSync(path.dirname(dest));
} catch (err) {
if (err.code !== "EEXIST") throw err;
}
const files = glob.sync("!(node_modules)", {});
const archive = archiver("zip");
_.each(files, file => archive.file(file, { name: path.basename(file) }));
archive.finalize().pipe(fs.createWriteStream(dest));
console.log(`wrote ${files.length} files to ${dest}`);