forked from tanshuai/alphabiz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
packager.js
114 lines (110 loc) · 3.79 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
const packager = require('electron-packager')
const fs = require('fs')
const path = require('path')
const { default: rebuild } = require('electron-rebuild')
const version = require('./package.json').version
const publicVersion = require('./public/version.json').version
const buildVersion = publicVersion || version
const packagePath = path.resolve(__dirname, './package.json')
const package = fs.readFileSync(packagePath)
console.log(path.resolve(__dirname, 'alphabiz-icon-1024.png'))
const beforeBuild = async () => {
// console.log('run beforeBuild')
// const pkg = JSON.parse(package)
// pkg.version = buildVersion
// console.log('Build version:', pkg.version)
// fs.writeFileSync(packagePath, JSON.stringify(pkg, null, 2))
// process.on('exit', () => {
// fs.writeFileSync(packagePath, package)
// console.log('Restored package.json before exit')
// })
}
beforeBuild ()
packager({
dir: './build/electron/UnPackaged',
out: './build/electron',
appVersion: buildVersion,
buildVersion: buildVersion,
extraResource: [
path.resolve(__dirname, 'alphabiz-icon-1024.png'),
path.resolve(__dirname, 'public/favicon.ico'),
path.resolve(__dirname, 'public/platform-assets/mac/trayiconTemplate.png'),
path.resolve(__dirname, 'public/version.json')
],
icon: process.platform === 'darwin'
? path.resolve(__dirname, 'public/platform-assets/mac/app.icns')
: path.resolve(__dirname, 'public/platform-assets/windows/icon.ico'),
// patch-package does not work in quasar production mode
// we should manually copy our patched webtorrent to build path
// NOTE: this requires `yarn` before `yarn build`
afterPrune: [(buildPath, electronVersion, platform, arch, callback) => {
// console.log('---App Build Path---\n', buildPath)
[
'webtorrent',
'bittorrent-tracker',
'torrent-discovery', // this builds with self-dep bittorrent-tracker
'@videojs'
].forEach(dep => {
const src = path.resolve(__dirname, 'node_modules', dep)
const dest = path.resolve(buildPath, 'node_modules', dep)
if (!fs.existsSync(src)) return console.error('not found', src)
console.log('--- COPY ---\n', src, '\n', dest, '\n--- COPY END ---')
if (fs.existsSync(dest)) fs.rmSync(dest, { recursive: true })
const copyRecursive = (src, dest) => {
if (fs.statSync(src).isDirectory()) {
fs.readdirSync(src).forEach(dir => {
copyRecursive(path.resolve(src, dir), path.resolve(dest, dir))
})
} else {
// ensure directory exists
if (!fs.existsSync(path.dirname(dest))) {
fs.mkdirSync(path.dirname(dest), { recursive: true })
}
fs.copyFileSync(src, dest)
}
}
copyRecursive(src, dest)
})
callback()
}],
afterCopy: [(buildPath, electronVersion, platform, arch, callback) => {
rebuild({
buildPath,
arch,
electronVersion: '17.0.0'
})
.then(() => {
console.log('Rebuilt native module')
callback()
})
.catch(e => callback(e))
}],
// downloader for our velectron build
download: {
mirrorOptions: {
mirror: 'https://github.com/zeeis/velectron/releases/download/'
},
downloader: require('@zeeis/velectron/downloader')
},
// asar compress all resources to app.asar, which is
// not an accessable directory for __statics, set to
// `false` to use __statics in electron
asar: {
unpack: '*.{node,dll}'
},
// not dependencies in production mode
ignore: [
// /aws-/,
/@zeeis\/velectron/,
/^exe-icon-extractor$/,
/@types/
],
protocols: [{
name: 'alphabiz', schemes: ['alphabiz://']
},
{
name: 'magnet', schemes: ['magnet://']
}, {
name: 'thunder', schemes: ['thunder://']
}]
})