Repository navigation
Expand file tree
/
Copy pathforge.config.js
More file actions
251 lines (230 loc) · 7.28 KB
/
Copy pathforge.config.js
File metadata and controls
251 lines (230 loc) · 7.28 KB
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
const { execFileSync, execSync } = require('node:child_process')
const fs = require('node:fs')
const os = require('node:os')
const path = require('node:path')
const { FusesPlugin } = require('@electron-forge/plugin-fuses')
const { FuseV1Options, FuseVersion } = require('@electron/fuses')
const {
CLERUM_OAUTH_PROTOCOL,
SANDBOX_UI_DEEP_LINK_PROTOCOL,
} = require('@clerum/desktop-app-links')
const desktopLicense = require('./package.json').license
const defaultAppleBundleId = 'ai.evenfire.desktop'
const assetsDirectory = path.resolve(__dirname, 'assets')
const adaptiveIconDocument = path.join(assetsDirectory, 'adaptive-icon.icon')
const evenfireProtocol = SANDBOX_UI_DEEP_LINK_PROTOCOL.replace(/:$/, '')
const clerumProtocol = CLERUM_OAUTH_PROTOCOL.replace(/:$/, '')
function compileMacAdaptiveIcon(buildPath, _electronVersion, platform, _arch, callback) {
if (platform !== 'darwin') {
callback()
return
}
const temporaryDirectory = fs.mkdtempSync(path.join(os.tmpdir(), 'evenfire-app-icon-'))
const compileDirectory = path.join(temporaryDirectory, 'compiled')
const compileInput = path.join(temporaryDirectory, 'Icon.icon')
const partialInfoPath = path.join(temporaryDirectory, 'partial-info.plist')
const appDirectory = path.join(buildPath, 'Evenfire.app')
const resourcesDirectory = path.join(appDirectory, 'Contents', 'Resources')
const infoPlistPath = path.join(appDirectory, 'Contents', 'Info.plist')
let hookError
try {
fs.mkdirSync(compileDirectory, { recursive: true })
fs.cpSync(adaptiveIconDocument, compileInput, { recursive: true })
execFileSync(
'xcrun',
[
'actool',
compileInput,
'--compile',
compileDirectory,
'--output-format',
'human-readable-text',
'--notices',
'--warnings',
'--platform',
'macosx',
'--minimum-deployment-target',
'26.0',
'--app-icon',
'Icon',
'--include-all-app-icons',
'--output-partial-info-plist',
partialInfoPath,
'--enable-on-demand-resources',
'NO',
'--target-device',
'mac',
],
{ stdio: 'inherit' }
)
fs.copyFileSync(
path.join(compileDirectory, 'Assets.car'),
path.join(resourcesDirectory, 'Assets.car')
)
fs.copyFileSync(
path.join(compileDirectory, 'Icon.icns'),
path.join(resourcesDirectory, 'Icon.icns')
)
execFileSync(
'/usr/bin/plutil',
['-replace', 'CFBundleIconName', '-string', 'Icon', infoPlistPath],
{ stdio: 'inherit' }
)
} catch (error) {
if (process.env.EVENFIRE_REQUIRE_ADAPTIVE_ICONS === '1') {
hookError = error
} else {
console.warn(
'Skipping the macOS adaptive icon catalog; the compatible static icon remains available.'
)
}
} finally {
fs.rmSync(temporaryDirectory, { recursive: true, force: true })
}
callback(hookError)
}
function resolveOsxSignConfig() {
if (process.platform !== 'darwin' || process.env.ENABLE_APPLE_CODESIGN !== '1') {
return undefined
}
const osxSign = {}
if (process.env.APPLE_CODESIGN_IDENTITY) {
osxSign.identity = process.env.APPLE_CODESIGN_IDENTITY
}
if (process.env.APPLE_KEYCHAIN) {
osxSign.keychain = process.env.APPLE_KEYCHAIN
}
return osxSign
}
function resolveOsxNotarizeConfig() {
if (process.platform !== 'darwin' || process.env.ENABLE_APPLE_CODESIGN !== '1') {
return undefined
}
if (process.env.APPLE_API_KEY && process.env.APPLE_API_KEY_ID && process.env.APPLE_API_ISSUER) {
return {
appleApiKey: process.env.APPLE_API_KEY,
appleApiKeyId: process.env.APPLE_API_KEY_ID,
appleApiIssuer: process.env.APPLE_API_ISSUER,
}
}
if (process.env.APPLE_KEYCHAIN_PROFILE) {
const osxNotarize = {
keychainProfile: process.env.APPLE_KEYCHAIN_PROFILE,
}
if (process.env.APPLE_KEYCHAIN) {
osxNotarize.keychain = process.env.APPLE_KEYCHAIN
}
return osxNotarize
}
throw new Error(
'ENABLE_APPLE_CODESIGN=1 requires either APPLE_API_KEY/APPLE_API_KEY_ID/APPLE_API_ISSUER or APPLE_KEYCHAIN_PROFILE.'
)
}
const osxSign = resolveOsxSignConfig()
const osxNotarize = resolveOsxNotarizeConfig()
module.exports = {
packagerConfig: {
asar: true,
// npm installs internal file: dependencies as symlinks. Copy their contents
// into the staging app so ASAR never contains links to the monorepo outside
// desktop-app (which Electron correctly rejects as an escaping symlink).
derefSymlinks: true,
executableName: 'Evenfire',
name: 'Evenfire',
icon: './assets/icon',
darwinDarkModeSupport: true,
extraResource: ['./assets/icon-light.png', './assets/icon-dark.png'],
afterCopyExtraResources: [compileMacAdaptiveIcon],
appBundleId: process.env.APPLE_BUNDLE_ID || defaultAppleBundleId,
appCategoryType: 'public.app-category.productivity',
protocols: [
{
name: 'Evenfire',
schemes: [evenfireProtocol],
},
{
name: 'Clerum OAuth callback',
schemes: [clerumProtocol],
},
],
...(osxSign ? { osxSign } : {}),
...(osxNotarize ? { osxNotarize } : {}),
},
rebuildConfig: {},
hooks: {
prePackage: async () => {
if (process.env.EVENFIRE_SKIP_PACKAGE_BUILD === '1') return
execSync('npm run build', { stdio: 'inherit' })
},
},
makers: [
{
name: '@electron-forge/maker-zip',
platforms: ['darwin', 'win32', 'linux'],
},
{
name: '@electron-forge/maker-dmg',
platforms: ['darwin'],
config: {
icon: path.join(assetsDirectory, 'icon.icns'),
},
},
{
name: '@electron-forge/maker-squirrel',
platforms: ['win32'],
config: {
authors: 'Evenfire',
name: 'Evenfire',
title: 'Evenfire',
setupExe: 'EvenfireSetup.exe',
setupIcon: path.join(assetsDirectory, 'icon.ico'),
},
},
{
name: '@electron-forge/maker-deb',
platforms: ['linux'],
config: {
options: {
name: 'evenfire',
productName: 'Evenfire',
genericName: 'Evenfire',
bin: 'Evenfire',
categories: ['Utility'],
icon: path.join(assetsDirectory, 'icon.png'),
mimeType: [`x-scheme-handler/${evenfireProtocol}`, `x-scheme-handler/${clerumProtocol}`],
},
},
},
{
name: '@electron-forge/maker-rpm',
platforms: ['linux'],
config: {
options: {
name: 'evenfire',
productName: 'Evenfire',
genericName: 'Evenfire',
bin: 'Evenfire',
license: desktopLicense,
categories: ['Utility'],
icon: path.join(assetsDirectory, 'icon.png'),
mimeType: [`x-scheme-handler/${evenfireProtocol}`, `x-scheme-handler/${clerumProtocol}`],
},
},
},
],
plugins: [
{
name: '@electron-forge/plugin-auto-unpack-natives',
config: {},
},
new FusesPlugin({
version: FuseVersion.V1,
[FuseV1Options.RunAsNode]: false,
[FuseV1Options.EnableCookieEncryption]: true,
[FuseV1Options.EnableNodeOptionsEnvironmentVariable]: false,
[FuseV1Options.EnableNodeCliInspectArguments]: false,
[FuseV1Options.EnableEmbeddedAsarIntegrityValidation]: true,
[FuseV1Options.OnlyLoadAppFromAsar]: true,
}),
],
}