forked from tanshuai/alphabiz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
packager.js
42 lines (36 loc) · 1.25 KB
/
packager.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
const packager = require('electron-packager')
const fs = require('fs')
const path = require('path')
const buildArch = process.env.BUILD_ARCH || process.arch
const buildPlatform = process.env.BUILD_PLATFORM || process.platform
console.log('Packager Build!', buildPlatform, buildArch)
const app = require('./developer/app')
const appName = app.name
const packagerOptions = require('./build-scripts/common/electron-packager')
packagerOptions.dir = `./dist/electron/UnPackaged`
packagerOptions.out = `./dist/electron`
const beforeBuild = async () => {
const { platform, arch } = process
const destDir = path.resolve(__dirname, `dist/electron/${app.displayName}-${platform}-${buildArch}`)
console.log('Before build', destDir)
if (fs.existsSync(destDir)) {
deleteFolderRecursive(destDir)
}
}
const deleteFolderRecursive = function (directoryPath) {
if (fs.existsSync(directoryPath)) {
fs.readdirSync(directoryPath).forEach((file, index) => {
const curPath = path.join(directoryPath, file)
if (fs.lstatSync(curPath).isDirectory()) {
// recurse
deleteFolderRecursive(curPath)
} else {
// delete file
fs.unlinkSync(curPath)
}
})
fs.rmdirSync(directoryPath)
}
}
beforeBuild()
packager(packagerOptions)