-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbuild.js
More file actions
105 lines (95 loc) · 2.91 KB
/
build.js
File metadata and controls
105 lines (95 loc) · 2.91 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
import { build, Platform, Arch } from "electron-builder";
import fs from "fs/promises";
import dotenv from "dotenv";
import path from "path";
import os from "os";
dotenv.config();
async function main() {
const platform = os.platform();
const isWSL = await fs
.readFile("/proc/version", "utf8")
.then((content) => content.toLowerCase().includes("microsoft"))
.catch(() => false);
const cwd = process.cwd();
const isPathOnWindows = cwd.startsWith("/mnt/c/");
if (isPathOnWindows && platform === "linux") {
console.log(
"[!] You're running the build inside WSL but on a Windows filesystem path."
);
console.log(
"[!] Cannot build for Linux using Windows paths. Move your project to the Linux filesystem (/home)!"
);
process.exit(1);
}
const certPassword = process.env.CERT_PASSWORD?.trim() || "";
const rawConfig = await fs.readFile("./electron-builder.json", "utf-8");
const config = JSON.parse(rawConfig);
if (config.win && certPassword) {
config.win.cscKeyPassword = certPassword;
}
const tempConfigPath = path.join(process.cwd(), "temp-electron-builder.json");
await fs.writeFile(tempConfigPath, JSON.stringify(config, null, 2));
try {
if (isWSL) {
console.log(
"[?] Detected WSL. Building for Linux (no Windows builds inside WSL)."
);
await build({
config: tempConfigPath,
targets: new Map([
[Platform.LINUX, new Map([[Arch.x64, ["deb", "AppImage"]]])],
]),
});
} else if (platform === "linux") {
console.log("[?] Running on native Linux. Building for Linux...");
await build({
config: tempConfigPath,
targets: new Map([
[Platform.LINUX, new Map([[Arch.x64, ["deb", "AppImage"]]])],
]),
});
} else if (platform === "win32") {
console.log("[?] Running on Windows. Building for Windows...");
await build({
config: tempConfigPath,
targets: new Map([
[
Platform.WINDOWS,
new Map([
[Arch.x64, ["nsis", "portable"]],
[Arch.ia32, ["nsis", "portable"]],
]),
],
]),
});
} else if (platform === "darwin") {
console.log("[?] Running on macOS. Building for macOS...");
await build({
config: tempConfigPath,
targets: new Map([
[
Platform.MAC,
new Map([
[Arch.x64, ["dmg"]],
[Arch.arm64, ["dmg"]],
]),
],
]),
});
} else {
console.error("Unsupported platform:", platform);
process.exit(1);
}
console.log("Build succeeded!");
} catch (err) {
console.error("Build failed:", err);
process.exit(1);
} finally {
try {
await fs.unlink(tempConfigPath);
} catch (cleanupErr) {
console.warn("Failed to clean up temporary config file:", cleanupErr);
}
}
}
main();