forked from tanshuai/alphabiz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
forge.config.js
280 lines (273 loc) · 10.5 KB
/
forge.config.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
const package = require('./package.json')
const fs = require('fs')
const { resolve } = require('path')
const { default: rebuild } = require('electron-rebuild')
const { version } = package
const appConfig = require('./developer/app');
const productName = appConfig.displayName;
const author = appConfig.author;
const protocol = appConfig.protocol;
const homepage = appConfig.homepage;
const publisher = appConfig.publisher;
const description = appConfig.description;
const defaultPfxPath = resolve(__dirname, 'appx/default.pfx')
const appxPfxPath = resolve(__dirname, 'developer/appx.pfx')
const appxPfx = fs.existsSync(appxPfxPath) ? appxPfxPath : defaultPfxPath
const icoPath = resolve(__dirname, 'developer/platform-assets/windows/icon.ico')
const wixLangPath = resolve(__dirname, 'wix/localizations')
// Add localization files here
const wixLocalizationFiles = [
'zh-CN.wxl',
'zh-TW.wxl',
'en-US.wxl'
].map(f => {
return resolve(wixLangPath, f)
})
// The .deb package requires a .desktop template, see here:
// node_modules/electron-installer-debian/resources/desktop.ejs
// We just change the `Exec` for file association
const debDesktopTemplate = resolve(__dirname, 'out/desktop.template')
// overwrites the default template for opending files
if (process.platform === 'linux') fs.writeFileSync(debDesktopTemplate, `[Desktop Entry]
<% if (productName) { %>Name=<%= productName %>
<% } %><% if (description) { %>Comment=<%= description %>
<% } %><% if (genericName) { %>GenericName=<%= genericName %>
<% } %><% if (name) { %>Exec=<%= name %> -- %U
Icon=<%= name %>
<% } %>Type=Application
StartupNotify=true
<% if (categories && categories.length) { %>Categories=<%= categories.join(';') %>;
<% } %><% if (mimeType && mimeType.length) { %>MimeType=<%= mimeType.join(';') %>;
<% } %>
`)
// patch-package throws error if dependency is optional.
// We can do nothing with it, so we have to patch manually.
const controlTemplate = `<% if (name) { %>Package: <%= name %>
<% } %><% if (version) { %>Version: <%= version %><% if (revision) { %>-<%= revision %><% } %>
<% } %><% if (section) { %>Section: <%= section %>
<% } %><% if (priority) { %>Priority: <%= priority %>
<% } %><% if (arch) { %>Architecture: <%= arch %>
<% } %><% if (depends && depends.length) { %>Depends: <%= depends.join(', ') %>
<% } %><% if (recommends && recommends.length) { %>Recommends: <%= recommends.join(', ') %>
<% } %><% if (suggests && suggests.length) { %>Suggests: <%= suggests.join(', ') %>
<% } %><% if (enhances && enhances.length) { %>Enhances: <%= enhances.join(', ') %>
<% } %><% if (preDepends && preDepends.length) { %>Pre-Depends: <%= preDepends.join(', ') %>
<% } %><% if (size) { %>Installed-Size: <%= size %>
<% } %><% if (maintainer) { %>Maintainer: <%= maintainer %>
<% } %><% if (name) { %>Provides: <%= name %>
<% } %><% if (name) { %>Conflicts: <%= name %>
<% } %><% if (name) { %>Replaces: <%= name %>
<% } %><% if (homepage) { %>Homepage: <%= homepage %>
<% } %><% if (description) { %>Description: <%= description %>
<% } %><% if (productDescription) { %><%= productDescription %><% } %>
`
if (process.platform === 'linux') {
fs.writeFileSync(
resolve(__dirname, 'node_modules/electron-installer-debian/resources/control.ejs'),
controlTemplate
)
}
module.exports = {
hooks: {
packageAfterPrune: (conf, buildPath, electronVersion, platform, arch, callback) => {
console.log('forge conf', conf)
// console.log('---App Build Path---\n', buildPath)
['webtorrent', '@quasar/app'].forEach(dep => {
const src = resolve(__dirname, 'node_modules', dep)
const dest = resolve(buildPath, 'node_modules', dep)
if (!fs.existsSync(src)) return
const copyRecursive = (src, dest) => {
if (fs.statSync(src).isDirectory()) {
fs.readdirSync(src).forEach(dir => {
copyRecursive(resolve(src, dir), 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()
},
packageAfterCopy: (conf, buildPath, electronVersion, platform, arch, callback) => {
rebuild({
buildPath,
arch,
electronVersion: '17.0.0'
})
.then(() => {
console.log('Rebuilt native module')
callback()
})
.catch(e => callback(e))
}
},
packagerConfig: {
download: {
mirrorOptions: {
mirror: 'https://github.com/zeeis/velectron/releases/download/'
},
downloader: require('@zeeis/velectron/downloader')
},
asar: {
unpack: '*.{node,dll}'
},
// not dependencies in production mode
ignore: [
// /aws-/,
/@zeeis\/velectron/
],
protocols: [{
name: protocol, schemes: [`${protocol}://`]
}, {
name: 'magnet', schemes: ['magnet://']
}, {
name: 'thunder', schemes: ['thunder://']
}]
},
plugins: [
['@electron-forge/plugin-local-electron', {
electronPath: resolve(__dirname, 'node_modules/@zeeis/velectron/dist')
}]
],
makers: [
{
name: "@electron-forge/maker-squirrel",
config: {
name: appConfig.name,
title: productName,
setupExe: `${productName}-${version} Setup.exe`,
productName,
author,
description,
version,
iconUrl: resolve(__dirname, 'developer/favicon.ico'),
setupIcon: resolve(__dirname, 'developer/favicon.ico'),
loadingGif: resolve(__dirname, 'developer/platform-assets/windows/splash/InstallSplash.gif'),
}
},
{
name: '@electron-forge/maker-dmg',
config: {
name: productName,
title: `${appConfig.fileName}-${version} Setup`,
icon: resolve(__dirname, 'developer/platform-assets/mac/volume-icon.icns'),
iconSize: 96,
overwrite: true,
background: resolve(__dirname, 'developer/platform-assets/mac/background.png'),
contents: [
{ x: 460, y: 256, type: 'link', path: '/Applications' },
{ x: 200, y: 256, type: 'file', path: resolve(__dirname, `out/${productName}-darwin-x64/${productName}.app`) }
]
}
},
// {
// name: "@electron-forge/maker-zip",
// platforms: [
// "darwin"
// ]
// },
{
name: "@electron-forge/maker-deb",
config: {
name: productName,
bin: productName,
genericName: productName,
categories: ['AudioVideo', 'Network', 'Utility'],
description,
productDescription: description,
version,
homepage,
icon: resolve(__dirname, 'developer/platform-assets/linux/512x512.png'),
mantainer: author,
// TODO: add file associations here
mimeType: ['audio/*', 'video/mp4', 'video/*', 'application/x-bittorrent'],
desktopTemplate: debDesktopTemplate
}
},
{
name: '@electron-forge/maker-appx',
config: {
publisher,
publisherName: publisher,
publisherDisplayName: appConfig.developer,
assets: resolve(__dirname, 'developer/platform-assets/windows/icon'),
devCert: appxPfx,
deploy: false,
makePri: true,
packageName: appConfig.name,
packageDisplayName: appConfig.displayName,
packageDescription: description,
packageVersion: version + '.0', // appx uses a version like 1.2.3.4
packageExecutable: `app\\${productName}.exe`,
manifest: 'appx/template.xml'
}
}
// {
// name: "@electron-forge/maker-rpm",
// config: {}
// },
// {
// name: "@electron-forge/maker-wix",
// config: {
// name: productName,
// shortName: productName,
// arch: 'x64',
// description,
// exe: productName,
// manufacturer: 'Alphabiz Team',
// shortcutFolderName: '',
// programFilesFolderName: productName,
// appIconPath: resolve(__dirname, 'public/platform-assets/windows/icon.ico'),
// /**
// * This code is randomly generate by [uuid](https://www.npmjs.com/package/uuid).
// * The Windows MSI installer uses it to upgrade an existed software.
// * Do NOT change this unless you know what will happen.
// */
// upgradeCode: '4d8a65aa-fc5b-421c-94ab-cb722ef737e2',
// version,
// cultures: 'zh-cn;zh-tw;en-us',
// ui: {
// chooseDirectory: true,
// images: {
// background: resolve(__dirname, 'public/platform-assets/windows/splash/background_493x312.png'),
// banner: resolve(__dirname, 'public/platform-assets/windows/splash/banner_493x58.png'),
// exclamationIcon: resolve(__dirname, 'public/icons/favicon-32x32.png'),
// infoIcon: resolve(__dirname, 'public/icons/favicon-32x32.png'),
// newIcon: resolve(__dirname, 'public/icons/favicon-16x16.png'),
// upIcon: resolve(__dirname, 'public/icons/favicon-16x16.png')
// },
// localizations: wixLocalizationFiles
// },
// beforeCreate (wix) {
// // console.log(wix.wixTemplate || wix)
// // Remove appName tail created by wix
// if (wix.wixTemplate) {
// const iconTemplate = `\n<Icon Id="icon.ico" SourceFile="${icoPath}"/>`
// + `\n<Property Id="ARPPRODUCTICON" Value="icon.ico" />`
// // console.log(wix.getRegistryKeys)
// const _getRegistryKeys = wix.getRegistryKeys
// wix.getRegistryKeys = (function getRegistryKeys (...args) {
// const registry = _getRegistryKeys.bind(wix)(...args)
// const icon = registry.find(i => i.id === 'UninstallDisplayIcon')
// if (icon) icon.value = '[APPLICATIONROOTDIRECTORY]Alphabiz.exe'
// console.log(icon, registry.find)
// return registry
// }).bind(wix)
// wix.uiTemplate = wix.uiTemplate
// .replace('<DialogRef Id="MsiRMFilesInUse" />', '<!-- <DialogRef Id="MsiRMFilesInUse" /> -->')
// wix.wixTemplate = wix.wixTemplate
// .replace('"{{ApplicationName}} (Machine - MSI)"', '"{{ApplicationName}}"')
// .replace('"{{ApplicationName}} (Machine)"', '"{{ApplicationName}}"')
// .replace('</Product>', iconTemplate + '\n</Product>')
// }
// }
// }
// }
],
publishers: []
}