This repository has been archived by the owner on Aug 17, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 137
/
afterbuild.js
54 lines (48 loc) · 2.06 KB
/
afterbuild.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
const fs = require("fs")
const fsAsync = fs.promises
const yazl = require("yazl")
const __path = require("path")
fs.unlinkSync(__path.join(__dirname, "builds", "lightcord-win32-ia32.zip"))
fs.unlinkSync(__path.join(__dirname, "builds", "lightcord-linux-x64.zip"))
const winZip = new yazl.ZipFile()
winZip.outputStream.pipe(fs.createWriteStream(__path.join(__dirname, "builds", "lightcord-win32-ia32.zip")))
const linuxZip = new yazl.ZipFile()
linuxZip.outputStream.pipe(fs.createWriteStream(__path.join(__dirname, "builds", "lightcord-linux-x64.zip")))
async function processNextDir(dir, zip, bpath, platform){
if(!bpath)bpath = dir
if(dir.replace(bpath, ""))zip.addEmptyDirectory(dir.replace(bpath, "").slice(1))
await Promise.all(fs.readdirSync(dir, {withFileTypes: true})
.map(async file => {
let path = __path.join(dir, file.name)
if(file.isDirectory()){
return await processNextDir(path, zip, bpath, platform)
}else if(file.isFile()){
if(!path.includes("node_modules")){
if(platform === "win"){
if(file.name.endsWith("_linux.node"))return
}else if(platform === "lin"){
if(file.name.endsWith(".node")){
if(!file.name.endsWith("_linux.node"))return
}
if(file.name.endsWith(".dll"))return
}
}
console.log("Adding "+file.name+" to "+platform)
let stat = fs.statSync(path)
zip.addBuffer(await fsAsync.readFile(path), __path.relative(bpath, path), {
mode: stat.mode,
mtime: stat.mtime
})
}
}))
}
processNextDir(__path.join(__dirname, "builds", "lightcord-win32-ia32"), winZip, undefined, "win")
.then(() => {
console.log(`Zipped win32.`)
winZip.end()
})
processNextDir(__path.join(__dirname, "builds", "lightcord-linux-x64"), linuxZip, undefined, "lin")
.then(() => {
console.log(`Zipped linux.`)
linuxZip.end()
})