-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathforge.config.ts
More file actions
266 lines (244 loc) · 10.7 KB
/
forge.config.ts
File metadata and controls
266 lines (244 loc) · 10.7 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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
import type { ForgeConfig } from '@electron-forge/shared-types';
import { MakerSquirrel } from '@electron-forge/maker-squirrel';
import { MakerZIP } from '@electron-forge/maker-zip';
import { MakerDMG } from '@electron-forge/maker-dmg';
import { MakerPKG } from '@electron-forge/maker-pkg';
import { MakerMSIX } from '@electron-forge/maker-msix';
import { VitePlugin } from '@electron-forge/plugin-vite';
import { FusesPlugin } from '@electron-forge/plugin-fuses';
import { FuseV1Options, FuseVersion } from '@electron/fuses';
import { PublisherGithub } from '@electron-forge/publisher-github';
import dotenv from 'dotenv';
import { execSync } from 'child_process';
import * as fs from 'fs';
import * as path from 'path';
// Load environment variables from .env file (local development only)
dotenv.config();
// Check if building for Mac App Store
const isMAS = process.env.PLATFORM === 'mas';
const windowsExecutableName = 'talktofigma-desktop';
const config: ForgeConfig = {
packagerConfig: {
asar: true,
appBundleId: 'com.grabtaxi.klever',
name: 'TalkToFigma Desktop',
executableName: windowsExecutableName,
icon: './public/icon', // Electron Forge will append .icns, .ico, .png automatically
extraResource: [
'./public',
],
// Code signing configuration (uses .env locally, CI environment variables in automation)
osxSign: (isMAS ? {
// Mac App Store signing
identity: process.env.SIGNING_IDENTITY_APPSTORE || 'Apple Distribution',
hardenedRuntime: false, // MAS doesn't use hardened runtime
timestamp: 'none', // Disable TSA calls explicitly for @electron/osx-sign
// Skip locale resource payloads from explicit signing to reduce signing overhead
ignore: (filePath: string) => /\/Resources\/[^/]+\.lproj\/locale\.pak$/.test(filePath.replace(/\\/g, '/')),
entitlements: 'entitlements.mas.plist',
// Child helpers (Renderer/GPU/Plugin) must inherit sandbox from parent.
// Using parent entitlements here can crash helper startup in libsecinit.
'entitlements-inherit': 'entitlements.child.plist',
provisioningProfile: process.env.PROVISIONING_PROFILE, // Optional: only if using provisioning profile
optionsForFile: (filePath: string) => {
// Apply child entitlements only to helper/framework binaries.
const normalizedPath = filePath.replace(/\\/g, '/');
const useChildEntitlements =
/\/Contents\/Frameworks\/[^/]+\.app\/Contents\/MacOS\//.test(normalizedPath) ||
/\/Contents\/Frameworks\/[^/]+\.framework\//.test(normalizedPath);
return {
hardenedRuntime: false,
timestamp: 'none',
entitlements: useChildEntitlements ? 'entitlements.child.plist' : 'entitlements.mas.plist',
};
},
} : {
// Regular distribution signing (Developer ID)
identity: process.env.SIGNING_IDENTITY || 'Developer ID Application: GRABTAXI HOLDINGS PTE. LTD. (VU3G7T53K5)',
hardenedRuntime: true,
'gatekeeper-assess': false,
entitlements: 'entitlements.plist',
'entitlements-inherit': 'entitlements.plist',
}) as any,
// Notarization configuration (not used for MAS/App Store builds)
osxNotarize: isMAS ? undefined : {
appleId: process.env.APPLE_ID || '',
appleIdPassword: process.env.APPLE_PASSWORD || '',
teamId: process.env.APPLE_TEAM_ID || 'VU3G7T53K5',
},
},
rebuildConfig: {},
// Hooks for post-processing after packaging
hooks: {
postPackage: async (_config, options) => {
// Only run for MAS builds on macOS
if (!isMAS || options.platform !== 'mas') {
return;
}
console.log('[postPackage] Re-signing helper apps with correct entitlements for MAS...');
const outputDir = options.outputPaths[0];
const identity = process.env.SIGNING_IDENTITY_APPSTORE || 'Apple Distribution';
const childEntitlements = path.resolve('entitlements.child.plist');
const mainEntitlements = path.resolve('entitlements.mas.plist');
const teamId = process.env.APPLE_TEAM_ID || '';
const bundleId = (_config as any).packagerConfig.appBundleId || 'com.grabtaxi.klever';
// Find the .app bundle inside the output directory
const items = fs.readdirSync(outputDir);
const appBundle = items.find(item => item.endsWith('.app'));
if (!appBundle) {
console.log('[postPackage] No .app bundle found in output directory, skipping');
return;
}
const appPath = path.join(outputDir, appBundle);
const frameworksPath = path.join(appPath, 'Contents', 'Frameworks');
console.log(`[postPackage] App bundle: ${appPath}`);
console.log(`[postPackage] Frameworks path: ${frameworksPath}`);
if (!fs.existsSync(frameworksPath)) {
console.log('[postPackage] No Frameworks directory found, skipping helper re-signing');
return;
}
// Find all helper apps
const frameworkItems = fs.readdirSync(frameworksPath);
const helperApps = frameworkItems.filter(item => item.endsWith('.app'));
console.log(`[postPackage] Found ${helperApps.length} helper apps to re-sign`);
for (const helperApp of helperApps) {
const helperPath = path.join(frameworksPath, helperApp);
console.log(`[postPackage] Re-signing helper: ${helperApp}`);
try {
// Re-sign the helper app with child entitlements (inherit only)
execSync(
`codesign --force --sign "${identity}" --entitlements "${childEntitlements}" --timestamp=none "${helperPath}"`,
{ stdio: 'inherit' }
);
console.log(`[postPackage] ✅ Successfully re-signed: ${helperApp}`);
// Verify the entitlements were applied
try {
const verifyOutput = execSync(
`codesign -d --entitlements - "${helperPath}" 2>&1`,
{ encoding: 'utf8' }
);
console.log(`[postPackage] Verifying entitlements for ${helperApp}:`);
console.log(verifyOutput);
} catch (verifyError) {
console.error(`[postPackage] ⚠️ Failed to verify entitlements for ${helperApp}:`, verifyError);
}
} catch (error) {
console.error(`[postPackage] ❌ Failed to re-sign ${helperApp}:`, error);
throw error;
}
}
// Re-sign the main app to update the seal after helper modifications
console.log('[postPackage] Re-signing main app to update seal...');
try {
// Create enhanced entitlements with application identifier for TestFlight
const mainEntitlementsContent = fs.readFileSync(mainEntitlements, 'utf8');
const enhancedEntitlements = mainEntitlementsContent.replace(
'</dict>',
` <!-- Required for TestFlight distribution -->
<key>com.apple.application-identifier</key>
<string>${teamId}.${bundleId}</string>
<key>com.apple.developer.team-identifier</key>
<string>${teamId}</string>
<key>com.apple.security.application-groups</key>
<array>
<string>${teamId}.${bundleId}</string>
</array>
</dict>`
);
const tempEntitlements = path.join(outputDir, 'temp-entitlements.plist');
fs.writeFileSync(tempEntitlements, enhancedEntitlements);
execSync(
`codesign --force --sign "${identity}" --entitlements "${tempEntitlements}" --timestamp=none "${appPath}"`,
{ stdio: 'inherit' }
);
// Clean up temp file
fs.unlinkSync(tempEntitlements);
console.log('[postPackage] ✅ Successfully re-signed main app');
} catch (error) {
console.error('[postPackage] ❌ Failed to re-sign main app:', error);
throw error;
}
console.log('[postPackage] Helper re-signing complete');
},
},
makers: [
// macOS: DMG (primary) and ZIP (backup/CI) for Developer ID distribution
new MakerDMG({
format: 'UDZO',
icon: './public/icon.icns', // DMG volume icon (prevents Electron default icon confusion)
name: 'TalkToFigmaDesktop', // Volume name without spaces to avoid hdiutil issues
}, ['darwin']),
new MakerZIP({}, ['darwin']),
// macOS: PKG for Mac App Store distribution
new MakerPKG({
identity: process.env.INSTALLER_IDENTITY || '3rd Party Mac Developer Installer',
}, ['mas']),
// Windows: Squirrel for traditional distribution with auto-update
new MakerSquirrel({
setupIcon: './public/icon.ico',
iconUrl: 'https://raw.githubusercontent.com/grab/TalkToFigmaDesktop/main/public/icon.ico',
}, ['win32']),
// Windows: MSIX for Microsoft Store distribution (no signing required for store submission)
new MakerMSIX({
manifestVariables: {
publisher: process.env.MSIX_PUBLISHER || 'CN=GRABTAXI HOLDINGS PTE. LTD.',
publisherDisplayName: process.env.MSIX_PUBLISHER_DISPLAY_NAME || 'GRABTAXI HOLDINGS PTE. LTD.',
packageIdentity: process.env.MSIX_IDENTITY_NAME || 'com.grabtaxi.klever',
appExecutable: `${windowsExecutableName}.exe`,
},
}),
],
plugins: [
new VitePlugin({
// `build` can specify multiple entry builds, which can be Main process, Preload scripts, Worker process, etc.
// If you are familiar with Vite configuration, it will look really familiar.
build: [
{
// `entry` is just an alias for `build.lib.entry` in the corresponding file of `config`.
entry: 'src/main.ts',
config: 'vite.main.config.ts',
target: 'main',
},
{
entry: 'src/preload.ts',
config: 'vite.preload.config.ts',
target: 'preload',
},
{
// stdio MCP server - standalone executable
entry: 'src/main/server/mcp-stdio-server.ts',
config: 'vite.stdio.config.ts',
target: 'main',
},
],
renderer: [
{
name: 'main_window',
config: 'vite.renderer.config.ts',
},
],
}),
// Fuses are used to enable/disable various Electron functionality
// at package time, before code signing the application
new FusesPlugin({
version: FuseVersion.V1,
[FuseV1Options.RunAsNode]: false,
[FuseV1Options.EnableCookieEncryption]: true,
[FuseV1Options.EnableNodeOptionsEnvironmentVariable]: false,
[FuseV1Options.EnableNodeCliInspectArguments]: false,
[FuseV1Options.EnableEmbeddedAsarIntegrityValidation]: true,
[FuseV1Options.OnlyLoadAppFromAsar]: false, // Allow loading extraResources outside asar
}),
],
publishers: [
new PublisherGithub({
repository: {
owner: 'grab',
name: 'TalkToFigmaDesktop',
},
prerelease: false,
draft: true, // Create as draft for manual review before publishing
}),
],
};
export default config;