afterbuild.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. const fs = require("fs")
  2. const fsAsync = fs.promises
  3. const yazl = require("yazl")
  4. const __path = require("path")
  5. fs.unlinkSync(__path.join(__dirname, "builds", "lightcord-win32-ia32.zip"))
  6. fs.unlinkSync(__path.join(__dirname, "builds", "lightcord-linux-x64.zip"))
  7. const winZip = new yazl.ZipFile()
  8. winZip.outputStream.pipe(fs.createWriteStream(__path.join(__dirname, "builds", "lightcord-win32-ia32.zip")))
  9. const linuxZip = new yazl.ZipFile()
  10. linuxZip.outputStream.pipe(fs.createWriteStream(__path.join(__dirname, "builds", "lightcord-linux-x64.zip")))
  11. async function processNextDir(dir, zip, bpath, platform){
  12. if(!bpath)bpath = dir
  13. if(dir.replace(bpath, ""))zip.addEmptyDirectory(dir.replace(bpath, "").slice(1))
  14. await Promise.all(fs.readdirSync(dir, {withFileTypes: true})
  15. .map(async file => {
  16. let path = __path.join(dir, file.name)
  17. if(file.isDirectory()){
  18. return await processNextDir(path, zip, bpath, platform)
  19. }else if(file.isFile()){
  20. if(!path.includes("node_modules")){
  21. if(platform === "win"){
  22. if(file.name.endsWith("_linux.node"))return
  23. }else if(platform === "lin"){
  24. if(file.name.endsWith(".node")){
  25. if(!file.name.endsWith("_linux.node"))return
  26. }
  27. if(file.name.endsWith(".dll"))return
  28. }
  29. }
  30. console.log("Adding "+file.name+" to "+platform)
  31. let stat = fs.statSync(path)
  32. zip.addBuffer(await fsAsync.readFile(path), __path.relative(bpath, path), {
  33. mode: stat.mode,
  34. mtime: stat.mtime
  35. })
  36. }
  37. }))
  38. }
  39. processNextDir(__path.join(__dirname, "builds", "lightcord-win32-ia32"), winZip, undefined, "win")
  40. .then(() => {
  41. console.log(`Zipped win32.`)
  42. winZip.end()
  43. })
  44. processNextDir(__path.join(__dirname, "builds", "lightcord-linux-x64"), linuxZip, undefined, "lin")
  45. .then(() => {
  46. console.log(`Zipped linux.`)
  47. linuxZip.end()
  48. })