-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathelectron.vite.config.ts
More file actions
81 lines (73 loc) · 2.02 KB
/
electron.vite.config.ts
File metadata and controls
81 lines (73 loc) · 2.02 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
import { resolve } from 'path';
import { readFileSync } from 'fs';
import { config } from 'dotenv';
import jwt from 'jsonwebtoken';
import { defineConfig, externalizeDepsPlugin } from 'electron-vite';
import solid from 'vite-plugin-solid';
import tailwindcss from '@tailwindcss/vite';
// Load .env at config time to generate the developer token at build time.
// Only the signed JWT is embedded — the private key never ships in the binary.
config();
function generateDeveloperToken(): string {
const teamId = process.env.APPLE_TEAM_ID;
const keyId = process.env.APPLE_KEY_ID;
let privateKey = process.env.APPLE_PRIVATE_KEY ?? '';
if (!privateKey && process.env.APPLE_PRIVATE_KEY_PATH) {
try {
privateKey = readFileSync(resolve(__dirname, process.env.APPLE_PRIVATE_KEY_PATH), 'utf-8');
} catch {
// Key file not found — token will be empty
}
}
if (!teamId || !keyId || !privateKey) {
console.warn('[build] Missing Apple credentials — developer token will be empty');
return '';
}
const now = Math.floor(Date.now() / 1000);
const exp = now + 180 * 24 * 60 * 60; // 180 days
return jwt.sign(
{ iss: teamId, iat: now, exp },
privateKey,
{
algorithm: 'ES256',
header: { alg: 'ES256', kid: keyId },
},
);
}
const developerToken = generateDeveloperToken();
export default defineConfig({
main: {
plugins: [externalizeDepsPlugin()],
define: {
__APPLE_DEVELOPER_TOKEN__: JSON.stringify(developerToken),
},
build: {
rollupOptions: {
input: {
index: resolve(__dirname, 'electron/main/index.ts'),
},
},
},
},
preload: {
plugins: [externalizeDepsPlugin()],
build: {
rollupOptions: {
input: {
index: resolve(__dirname, 'electron/preload/index.ts'),
},
},
},
},
renderer: {
root: '.',
plugins: [solid(), tailwindcss()],
build: {
rollupOptions: {
input: {
main: resolve(__dirname, 'index.html'),
},
},
},
},
});