-
Notifications
You must be signed in to change notification settings - Fork 69
/
winbundle.js
93 lines (80 loc) · 2.86 KB
/
winbundle.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
const fs = require('fs');
const spawnSync = require('child_process').spawnSync;
const path = require('path');
const async = require('async');
const archiver = require('archiver');
const bundleName = "clusterodm-windows-x64.zip";
async.series([
cb => {
// Cleanup directories
console.log("Cleaning up folders");
for (let dir of ["data", "tmp"]){
for (let entry of fs.readdirSync(dir)){
if (entry !== ".gitignore"){
const e = path.join(dir, entry);
console.log(`Removing ${e}`);
if (fs.lstatSync(e).isDirectory()){
fs.rmdirSync(e, { recursive: true });
}else{
fs.unlinkSync(e);
}
}
}
}
cb();
},
cb => {
console.log("Building executable");
const code = spawnSync('nexe.cmd', ['index.js', '-t', 'windows-x64-12.16.3', '-o', 'clusterodm.exe', '-r', 'libs/**'], { stdio: "pipe"}).status;
if (code === 0) cb();
else cb(new Error(`nexe returned non-zero error code: ${code}`));
},
cb => {
// Zip
const outFile = path.join("dist", bundleName);
if (!fs.existsSync("dist")) fs.mkdirSync("dist");
if (fs.existsSync(outFile)) fs.unlinkSync(outFile);
let output = fs.createWriteStream(outFile);
let archive = archiver.create('zip', {
zlib: { level: 5 } // Sets the compression level (1 = best speed since most assets are already compressed)
});
archive.on('finish', () => {
console.log("Done!");
cb();
});
archive.on('error', err => {
console.error(`Could not archive .zip file: ${err.message}`);
cb(err);
});
const files = [
"data",
"docs",
"letsencrypt",
"public",
"tmp",
"config-default.json",
"LICENSE",
"package.json",
"clusterodm.exe"
];
archive.pipe(output);
files.forEach(file => {
console.log(`Adding ${file}`);
let stat = fs.lstatSync(file);
if (stat.isFile()){
archive.file(file, {name: path.basename(file)});
}else if (stat.isDirectory()){
archive.directory(file, path.basename(file));
}else{
logger.error(`Could not add ${file}`);
}
});
// Plus node-libcurl
console.log("Adding node_modules/node-libcurl")
archive.directory(path.join("node_modules", "node-libcurl"), path.join("node_modules", "node-libcurl"));
archive.finalize();
}
], (err) => {
if (err) console.log(`Bundle failed: ${err}`);
else console.log(`Bundle ==> dist/${bundleName}`);
});