-
Notifications
You must be signed in to change notification settings - Fork 27
/
build.js
31 lines (28 loc) · 1.39 KB
/
build.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
const JSZip = require('jszip')
const fs = require('fs')
const path = require('path')
const files = [
...fs.readdirSync('src').map(it => ['src/' + it, 'resources/app/' + it]),
'LICENSE',
'es.exe',
'README.md'
]
const electronRoot = path.resolve(require.resolve('electron'), '../dist')
const walkDir = dir => fs.promises.readdir(dir).then(list => Promise.all(list.map(async file => {
const cur = path.join(dir, file)
if ((await fs.promises.stat(cur)).isDirectory()) await walkDir(cur)
else {
const name = path.relative(electronRoot, cur).replace(/\\/g, '/')
if (name === 'LICENSE' || name.startsWith('resources/')) return
files.push([cur, name.startsWith('electron') ? 'CefDetectorX' + name.replace(/^electron/, '') : name])
}
})))
const ZIP_OPTIONS = { type: 'nodebuffer', compression: 'DEFLATE', compressionOptions: { level: 9 } }
const zip = new JSZip()
walkDir(electronRoot)
.then(() => Promise.all(files.map(it => fs.promises.readFile(typeof it === 'string' ? it : it[0]).then(data => zip.file('CefDetectorX/' + (typeof it === 'string' ? it : it[1]), data)))))
.then(() => console.log(Object.keys(zip.files)))
.then(() => zip.generateAsync(ZIP_OPTIONS))
.then(data => fs.promises.writeFile('CefDetectorX-with-bgm.zip', data))
.then(() => zip.remove('CefDetectorX/resources/app/bgm.mp3').generateAsync(ZIP_OPTIONS))
.then(data => fs.promises.writeFile('CefDetectorX.zip', data))