-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforge.config.ts
185 lines (161 loc) · 6.68 KB
/
forge.config.ts
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
// Node.js dependencies
import { spawn, SpawnOptionsWithoutStdio } from 'child_process';
import { readdir, unlink } from 'fs/promises';
import { join, resolve } from 'path';
// External dependencies
import type { ForgeConfig } from '@electron-forge/shared-types';
import { MakerDMG } from '@electron-forge/maker-dmg';
import { MakerZIP } from '@electron-forge/maker-zip';
import { AutoUnpackNativesPlugin } from '@electron-forge/plugin-auto-unpack-natives';
import { WebpackPlugin } from '@electron-forge/plugin-webpack';
import { signAsync, PerFileSignOptions } from '@electron/osx-sign';
import { notarize } from '@electron/notarize';
// import { FusesPlugin } from '@electron-forge/plugin-fuses';
// import { FuseV1Options, FuseVersion } from '@electron/fuses';
import { config as dotenvConfig } from 'dotenv';
// Local dependencies
import { mainConfig } from './webpack/main.config';
import { rendererConfig } from './webpack/renderer.config';
import { author, productName } from './package.json';
dotenvConfig();
const spawnPromise = (command: string, args?: string[], options?: SpawnOptionsWithoutStdio) => {
return new Promise<void>((resolve, reject) => {
const child = spawn(command, args, options);
child.on('exit', code => {
if (code === 0)
resolve();
else
reject(new Error(`Command "${command} ${args ? args.join(' ') : ''}" exited with code ${code}`));
});
child.on('error', reject);
});
};
const vmpSignPkg = async (pkgPath: string, username: string, password: string) => {
await spawnPromise('python', ['-m', 'pip', 'install', '--upgrade', 'castlabs-evs']);
await spawnPromise('python', ['-m', 'castlabs_evs.account', 'reauth', '--account-name', username, '--passwd', password]);
await spawnPromise('python', ['-m', 'castlabs_evs.vmp', 'sign-pkg', pkgPath]);
};
const osxSignPkg = async (pkgPath: string, optionsForFile?: (path: string) => PerFileSignOptions) => {
if (process.platform !== 'darwin')
throw new Error(`OSX Code-Signing is only supported on macOS!`);
await signAsync({
app: `${pkgPath}/${productName}.app`,
platform: 'darwin',
optionsForFile: optionsForFile,
});
};
const osxNotarizePkg = async (pkgPath: string, appleId: string, appleIdPassword: string, appleTeamId: string) => {
if (process.platform !== 'darwin')
throw new Error(`OSX Notarization is only supported on macOS!`);
await notarize({
tool: 'notarytool',
appPath: `${pkgPath}/${productName}.app`,
appleId: appleId,
appleIdPassword: appleIdPassword,
teamId: appleTeamId,
});
};
const config: ForgeConfig = {
hooks: {
packageAfterExtract: async (config, buildPath, electronVersion, platform) => {
if (platform !== 'darwin')
return;
const helpers = await readdir(buildPath, { recursive: true })
.then(files => files.filter(f => f.endsWith('Electron Framework.framework')))
.then(files => files.map(f => join(buildPath, f)));
for (const helper of helpers) {
const sigFiles = await readdir(helper, { recursive: true })
.then(files => files.filter(f => f.endsWith('Versions/A/Resources/Electron Framework.sig')))
.then(files => files.map(f => join(helper, f)));
for (const sigFile of sigFiles)
await unlink(sigFile);
}
},
postPackage: async (config, pkgResult) => {
// Linux doesn't support VMP signing
if (pkgResult.platform === 'linux')
return;
if (!process.env.CASTLABS_EVS_USERNAME || !process.env.CASTLABS_EVS_PASSWORD)
throw new Error(`Missing CASTLABS_EVS_USERNAME or CASTLABS_EVS_PASSWORD environment variables required for signing!`);
for (const path of pkgResult.outputPaths) {
await vmpSignPkg(path, process.env.CASTLABS_EVS_USERNAME, process.env.CASTLABS_EVS_PASSWORD);
if (pkgResult.platform === 'darwin' && process.platform === 'darwin') {
await osxSignPkg(path, fPath => {
let entitlements = resolve(join(__dirname, 'entitlements', 'Default.plist'));
if (fPath.endsWith('Helper.app')) // https://github.com/castlabs/electron-releases/issues/161#issuecomment-1609020079
entitlements = resolve(join(__dirname, 'entitlements', 'Helper.plist'));
else if (fPath.endsWith('(Plugin).app'))
entitlements = resolve(join(__dirname, 'entitlements', 'Plugin.plist'));
return {
entitlements: entitlements,
hardenedRuntime: true,
};
});
if (!process.env.APPLE_ID || !process.env.APPLE_ID_PASSWORD || !process.env.APPLE_TEAM_ID)
throw new Error(`Missing APPLE_ID, APPLE_ID_PASSWORD or APPLE_TEAM_ID environment variables required for notarization!`);
await osxNotarizePkg(path, process.env.APPLE_ID, process.env.APPLE_ID_PASSWORD, process.env.APPLE_TEAM_ID);
}
}
},
},
packagerConfig: {
appBundleId: `com.${author.name}.${productName}`.toLowerCase(),
appCategoryType: 'public.app-category.entertainment',
appCopyright: `Copyright © 2024 ${author.name}`,
asar: true,
download: {
mirrorOptions: {
mirror: 'https://github.com/castlabs/electron-releases/releases/download/'
}
},
icon: './assets/icon',
},
rebuildConfig: {},
makers: [
new MakerZIP({}, ['darwin', 'linux', 'win32']),
new MakerDMG({
appPath: 'fakePathToSatisfyTypeCheck',
name: `Install ${productName}`,
icon: './assets/icon.icns',
}),
],
plugins: [
new AutoUnpackNativesPlugin({}),
new WebpackPlugin({
mainConfig,
devContentSecurityPolicy: 'media-src * blob:; font-src https://fonts.gstatic.com;',
renderer: {
config: rendererConfig,
entryPoints: [
{
html: './src/main_window/index.html',
js: './src/main_window/renderer.ts',
name: 'main_window',
preload: {
js: './src/main_window/preload.ts',
},
},
{
html: './src/player/index.html',
js: './src/player/renderer.ts',
name: 'player',
preload: {
js: './src/player/preload.ts',
},
},
],
},
}),
// https://github.com/castlabs/electron-releases/issues/152
// new FusesPlugin({
// version: FuseVersion.V1,
// [FuseV1Options.RunAsNode]: false,
// [FuseV1Options.EnableCookieEncryption]: true,
// [FuseV1Options.EnableNodeOptionsEnvironmentVariable]: false,
// [FuseV1Options.EnableNodeCliInspectArguments]: false,
// [FuseV1Options.EnableEmbeddedAsarIntegrityValidation]: true,
// [FuseV1Options.OnlyLoadAppFromAsar]: true,
// }),
],
};
export default config;