-
Notifications
You must be signed in to change notification settings - Fork 202
Expand file tree
/
Copy pathforge.config.mjs
More file actions
296 lines (270 loc) · 7.83 KB
/
Copy pathforge.config.mjs
File metadata and controls
296 lines (270 loc) · 7.83 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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
import path from "node:path";
import { readFileSync } from "node:fs";
import { MakerDMG } from "@electron-forge/maker-dmg";
import { MakerSquirrel } from "@electron-forge/maker-squirrel";
import { MakerZIP } from "@electron-forge/maker-zip";
import { brandMacHelperApps } from "./scripts/electron/brand-mac-helper-apps.mjs";
const PRODUCT_NAME = "Lime";
const APP_ID = "com.limecloud.lime";
const RELEASE_OUTPUT_DIR =
process.env.LIME_ELECTRON_FORGE_OUT_DIR || "release-electron";
const SQUIRREL_PACKAGE_NAME = "lime";
const PACKAGE_VERSION = JSON.parse(
readFileSync("package.json", "utf8"),
).version;
const DEFAULT_UPDATE_BASE_URL = "https://updates.limecloud.com";
const MACOS_APP_ENTITLEMENTS = "lime-rs/entitlements.plist";
const retainedPackageRoots = new Set(["dist", "node_modules", "package.json"]);
const retainedPackageDirectories = new Set([
"dist-electron",
"dist-electron/main",
"dist-electron/preload",
]);
const retainedPackagePrefixes = [
"dist-electron/main/",
"dist-electron/preload/",
];
function ignorePackagerInput(filePath) {
const normalizedInput = filePath.replace(/\\/g, "/");
const normalizedCwd = process.cwd().replace(/\\/g, "/");
const relativePath =
normalizedInput === normalizedCwd ||
normalizedInput.startsWith(`${normalizedCwd}/`)
? path.relative(process.cwd(), filePath)
: normalizedInput;
const normalized = relativePath.replace(/\\/g, "/").replace(/^\/+/, "");
if (!normalized) {
return false;
}
const root = normalized.split("/")[0];
if (retainedPackageRoots.has(root)) {
return false;
}
if (retainedPackageDirectories.has(normalized)) {
return false;
}
if (retainedPackagePrefixes.some((prefix) => normalized.startsWith(prefix))) {
return false;
}
return true;
}
function isTopLevelAppBundle(filePath) {
const normalized = String(filePath || "").replace(/\\/g, "/");
return normalized.endsWith(".app") && !normalized.includes(".app/");
}
function macSignOptions({
env = process.env,
platform = process.platform,
} = {}) {
if (platform !== "darwin") {
return undefined;
}
const releaseSigning =
env.LIME_ELECTRON_SIGN === "1" || Boolean(env.LIME_MACOS_KEYCHAIN);
const options = {
continueOnError: false,
identityValidation: releaseSigning,
preAutoEntitlements: false,
preEmbedProvisioningProfile: false,
optionsForFile: (filePath) => {
if (!isTopLevelAppBundle(filePath)) {
return releaseSigning
? null
: { hardenedRuntime: false, timestamp: "none" };
}
return {
entitlements: MACOS_APP_ENTITLEMENTS,
hardenedRuntime: releaseSigning,
...(releaseSigning
? { signatureFlags: ["runtime"] }
: { timestamp: "none" }),
};
},
strictVerify: true,
};
if (!releaseSigning) {
options.identity = "-";
} else if (env.APPLE_SIGNING_IDENTITY) {
options.identity = env.APPLE_SIGNING_IDENTITY;
}
if (env.LIME_MACOS_KEYCHAIN) {
options.keychain = env.LIME_MACOS_KEYCHAIN;
}
return options;
}
function macNotarizeOptions({
env = process.env,
platform = process.platform,
} = {}) {
if (
platform !== "darwin" ||
(env.LIME_ELECTRON_SIGN !== "1" && !env.LIME_MACOS_KEYCHAIN)
) {
return undefined;
}
const appleId = env.APPLE_ID;
const appleIdPassword = env.APPLE_APP_SPECIFIC_PASSWORD || env.APPLE_PASSWORD;
const teamId = env.APPLE_TEAM_ID;
if (!appleId || !appleIdPassword || !teamId) {
return undefined;
}
return { appleId, appleIdPassword, teamId };
}
function normalizedUpdateBaseUrl({ env = process.env } = {}) {
return (env.LIME_UPDATES_BASE_URL || DEFAULT_UPDATE_BASE_URL)
.trim()
.replace(/\/+$/, "");
}
function updateFeedLabel(platform = process.platform, arch = process.arch) {
if (platform === "darwin") {
return arch === "arm64" ? "darwin-arm64" : "darwin-x64";
}
if (platform === "win32") {
return arch === "arm64" ? "win32-arm64" : "win32-x64";
}
return `${platform}-${arch}`;
}
function updateFeedUrl(
platform = process.platform,
arch = process.arch,
{ env = process.env } = {},
) {
const explicitFeedUrl = env.LIME_ELECTRON_UPDATES_URL?.trim();
if (explicitFeedUrl) {
return explicitFeedUrl.replace(/\/+$/, "");
}
return `${normalizedUpdateBaseUrl({ env })}/lime/stable/${updateFeedLabel(platform, arch)}`;
}
function macZipConfig(arch = process.arch, options = {}) {
return {
macUpdateManifestBaseUrl: updateFeedUrl("darwin", arch, options),
};
}
function windowsSigningOptions({
env = process.env,
platform = process.platform,
} = {}) {
if (platform !== "win32" || env.LIME_ELECTRON_SIGN !== "1") {
return {};
}
const certificateFile = env.LIME_WINDOWS_SIGNING_CERTIFICATE_FILE?.trim();
const certificatePassword = env.LIME_WINDOWS_SIGNING_CERTIFICATE_PASSWORD;
if (!certificateFile || !certificatePassword) {
return {};
}
return {
certificateFile,
certificatePassword,
};
}
function windowsSquirrelRemoteReleasesUrl({ env = process.env } = {}) {
const remoteReleasesUrl =
env.LIME_WINDOWS_SQUIRREL_REMOTE_RELEASES_URL?.trim();
if (!remoteReleasesUrl) {
return undefined;
}
return remoteReleasesUrl.replace(/\/+$/, "");
}
function windowsSquirrelRemoteReleasesOptions(options = {}) {
const remoteReleases = windowsSquirrelRemoteReleasesUrl(options);
if (!remoteReleases) {
return {};
}
return { remoteReleases };
}
function squirrelConfig(arch = process.arch, options = {}) {
const packageVersion = options.packageVersion || PACKAGE_VERSION;
return {
authors: "Lime",
exe: `${PRODUCT_NAME}.exe`,
name: SQUIRREL_PACKAGE_NAME,
noMsi: true,
setupExe: `${PRODUCT_NAME}-${packageVersion} Setup.exe`,
setupIcon: "lime-rs/icons/icon.ico",
...windowsSquirrelRemoteReleasesOptions(options),
...windowsSigningOptions(options),
};
}
export {
ignorePackagerInput,
macNotarizeOptions,
macSignOptions,
macZipConfig,
normalizedUpdateBaseUrl,
squirrelConfig,
updateFeedLabel,
updateFeedUrl,
windowsSigningOptions,
windowsSquirrelRemoteReleasesOptions,
windowsSquirrelRemoteReleasesUrl,
};
export default {
outDir: RELEASE_OUTPUT_DIR,
packagerConfig: {
name: PRODUCT_NAME,
executableName: PRODUCT_NAME,
appBundleId: APP_ID,
appCategoryType: "public.app-category.productivity",
appCopyright: "Copyright © Lime",
asar: true,
prune: true,
icon:
process.platform === "win32"
? "lime-rs/icons/icon.ico"
: "lime-rs/icons/icon.icns",
extraResource: [
"dist-electron/desktop-assets",
"dist-electron/app-server.release.json",
"dist-electron/app-server",
],
protocols: [
{
name: "Lime URL",
schemes: ["lime"],
},
],
extendInfo: {
NSMicrophoneUsageDescription: "Lime 需要访问麦克风以使用语音输入功能",
NSAppleEventsUsageDescription: "Lime 需要控制其他应用以输入识别的文本",
},
osxSign: macSignOptions(),
osxNotarize: macNotarizeOptions(),
win32metadata: {
CompanyName: "Lime",
FileDescription: PRODUCT_NAME,
ProductName: PRODUCT_NAME,
InternalName: PRODUCT_NAME,
},
afterCopyExtraResources: [
(buildPath, _electronVersion, platform, _arch, done) => {
if (platform !== "darwin") {
done();
return;
}
try {
brandMacHelperApps({
appOutDir: buildPath,
productName: PRODUCT_NAME,
});
done();
} catch (error) {
done(error);
}
},
],
ignore: ignorePackagerInput,
},
rebuildConfig: {
ignoreModules: ["canvas"],
},
makers: [
new MakerDMG(
{
name: PRODUCT_NAME,
},
["darwin"],
),
new MakerZIP((arch) => macZipConfig(arch), ["darwin"]),
new MakerSquirrel((arch) => squirrelConfig(arch), ["win32"]),
],
};