This repository has been archived by the owner on Jan 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
forge.config.js
215 lines (209 loc) · 5.83 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
/* eslint-disable @typescript-eslint/no-var-requires */
require('dotenv').config()
const { exec } = require('child_process')
async function manuallySignExe(packagePath) {
return new Promise((resolve, reject) => {
const cmd = `AzureSignTool sign -kvu "${process.env.AZURE_KEY_VAULT_URI}" -kvi "${process.env.AZURE_CLIENT_ID}" -kvt "${process.env.AZURE_TENANT_ID}" -kvs "${process.env.AZURE_CLIENT_SECRET}" -kvc "${process.env.AZURE_CERT_NAME}" -tr http://timestamp.digicert.com -v "${packagePath}"`
exec(cmd, (error, stdout, stderr) => {
if (error) {
console.log(`Manual Sign exe Error: ${error}`)
return reject(error)
}
if (stderr) {
console.log(`Manual Sign exe Stderr: ${stderr}`)
return reject(new Error(stderr))
}
console.log(`Manual Sign exe Stdout: ${stdout}`)
resolve(stdout)
})
})
}
const COMMON_CONFIG = {
packagerConfig: {
name: 'Iron Fish Node App',
executableName: 'node-app',
icon: 'electron/icons/icon',
osxSign: process.env.APPLE_API_KEY ? {} : undefined,
osxNotarize: process.env.APPLE_API_KEY
? {
tool: 'notarytool',
appleApiKey: process.env.APPLE_API_KEY,
appleApiKeyId: process.env.APPLE_API_KEY_ID,
appleApiIssuer: process.env.APPLE_API_ISSUER,
}
: undefined,
},
makers: [
{
name: '@electron-forge/maker-squirrel',
config: {
// An URL to an ICO file to use as the application icon (displayed in Control Panel > Programs and Features).
iconUrl:
'https://github.com/iron-fish/node-app/raw/master/electron/icons/icon.ico',
setupIcon: './electron/icons/icon.ico',
},
},
{
name: '@electron-forge/maker-zip',
platforms: ['darwin'],
},
{
name: '@electron-forge/maker-dmg',
platforms: ['darwin'],
config: {
icon: './electron/icons/icon.icns',
background: './electron/icons/background.png',
format: 'ULFO',
window: {
size: {
width: 645,
height: 493,
},
},
},
},
{
name: '@electron-forge/maker-deb',
config: {
options: {
icon: './electron/icons/icon.png',
},
},
},
],
hooks: {
readPackageJson: async (forgeConfig, packageJson) => {
// only copy deps if there isn't any
if (Object.keys(packageJson.dependencies).length === 0) {
const originalPackageJson = require('./package.json')
const webpackConfigJs = require('./webpack/common/main.config.js')
Object.keys(webpackConfigJs.externals).forEach(package => {
packageJson.dependencies[package] =
originalPackageJson.dependencies[package]
})
}
return packageJson
},
postMake: async (forgeConfig, makeResults) => {
// makeResults is an array of { artifacts: string[] }
for (const result of makeResults) {
for (const artifactPath of result.artifacts) {
console.log(artifactPath)
if (artifactPath.endsWith('.exe')) {
try {
await manuallySignExe(artifactPath)
console.log(`Successfully signed ${artifactPath}`)
} catch (error) {
console.error(`Failed to sign ${artifactPath}: ${error}`)
throw error // Rethrow the error to stop the process
}
}
}
}
},
},
}
const ENV_CONFIGS = {
dev: {
plugins: [
{
name: '@electron-forge/plugin-webpack',
config: {
mainConfig: './webpack/dev/main.config.js',
renderer: {
config: './webpack/common/renderer.config.js',
entryPoints: [
{
html: './public/index.html',
js: './electron/dev/renderer.ts',
name: 'node',
preload: {
js: './electron/dev/preload.ts',
},
},
],
},
},
},
],
},
demo: {
plugins: [
{
name: '@electron-forge/plugin-webpack',
config: {
mainConfig: './webpack/demo/main.config.js',
renderer: {
config: './webpack/common/renderer.config.js',
entryPoints: [
{
html: './public/index.html',
js: './electron/demo/renderer.ts',
name: 'node',
preload: {
js: './electron/demo/preload.ts',
},
},
],
},
},
},
],
publishers: [
{
name: '@electron-forge/publisher-github',
config: {
repository: {
owner: 'iron-fish',
name: 'node-app',
draft: true,
},
prerelease: true,
tagPrefix: 'demo-v',
},
},
],
},
production: {
plugins: [
{
name: '@electron-forge/plugin-webpack',
config: {
mainConfig: './webpack/prod/main.config.js',
renderer: {
config: './webpack/common/renderer.config.js',
entryPoints: [
{
html: './public/index.html',
js: './electron/prod/renderer.ts',
name: 'node',
preload: {
js: './electron/prod/preload.ts',
},
},
],
},
},
},
],
publishers: [
{
name: '@electron-forge/publisher-github',
config: {
repository: {
owner: 'iron-fish',
name: 'node-app',
draft: true,
},
prerelease: true,
tagPrefix: 'v',
},
},
],
},
}
const config = {
...COMMON_CONFIG,
...ENV_CONFIGS[process.env['MODE'] || 'dev'],
}
module.exports = config