forked from fantinodavide/Squad_Whitelister
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzipRelease.js
52 lines (39 loc) · 1.26 KB
/
zipRelease.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
const fs = require("fs-extra");
const zip = (require('node-zip'))();
const path = require('path');
const StreamZip = require('node-stream-zip');
console.log("CREATING release.zip");
fs.removeSync("./release.zip");
const allF = getAllFiles(path.join(__dirname, "release"));
// console.log(allF);
for (let f of allF) {
zip.file(f.replace(__dirname + "\\", ""), fs.readFileSync(f));
}
var data = zip.generate({ base64: true, compression: 'DEFLATE' });
fs.writeFileSync('release.zip', data, 'base64');
const zipTest = new StreamZip({
file: "release.zip",
storeEntries: true,
skipEntryNameValidation: true
});
zipTest.on('ready', async () => {
let testPass = false;
zipTest.on('entry', e => {
if (e.isDirectory) testPass = true;
});
console.log(" > Test:",testPass?"PASS":"FAIL")
process.exit(!testPass);
});
console.log(" > Done");
function getAllFiles(dirPath, arrayOfFiles) {
files = fs.readdirSync(dirPath)
arrayOfFiles = arrayOfFiles || []
files.forEach(function (file) {
if (fs.statSync(dirPath + "/" + file).isDirectory()) {
arrayOfFiles = getAllFiles(dirPath + "/" + file, arrayOfFiles)
} else {
arrayOfFiles.push(path.join(dirPath, file))
}
})
return arrayOfFiles
}