-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpack.js
52 lines (43 loc) · 1.51 KB
/
pack.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 { exec } = require('pkg')
const archiver = require('archiver');
const fs = require('fs');
const stem_name = "v2asub"
const exe_tails = [
"-linux",
"-macos",
"-win.exe"
]
const extra_files = [
["subs.example.json", "subs.example.json"],
["template.json", "template.json"],
["node_modules/raw-socket/build/Release/raw.node", "raw.node"]
]
exec([ "." ]).then(function() {
fs.mkdir("build", () => {
exe_tails.forEach(i => {
const bin_name = stem_name + i;
const zip_name = "/build/" + stem_name + i + ".zip";
console.log(`Packing ${bin_name} to ${zip_name}`)
const output = fs.createWriteStream(__dirname + zip_name);
if(!fs.existsSync(__dirname + zip_name)) {
fs.writeFileSync(__dirname + zip_name)
}
const archive = archiver('zip', {
zlib: { level: 9 } // Sets the compression level.
});
output.on('close', function() {
console.log(`${zip_name}: ${archive.pointer()} bytes.`);
fs.unlink(bin_name, ()=>{console.log(`${bin_name} removed.`)})
});
archive.pipe(output)
extra_files.forEach(j => {
archive.file(j[0], {"name": j[1]})
})
archive.file(bin_name)
archive.finalize();
})
console.log('Dispatch completed. Waiting for async operations to finish...')
})
}).catch(function(error) {
console.error(error)
})