-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforge.config.ts
154 lines (146 loc) · 6.77 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
import { existsSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, writeFileSync } from "fs";
import pkgJSON from "./package.json";
import type { ForgeConfig } from "@electron-forge/shared-types";
import { MakerSquirrel } from "@electron-forge/maker-squirrel";
import { MakerZIP } from "@electron-forge/maker-zip";
import { MakerDeb } from "@electron-forge/maker-deb";
import { MakerRpm } from "@electron-forge/maker-rpm";
import { VitePlugin } from "@electron-forge/plugin-vite";
import path, { join } from "path";
const config: ForgeConfig = {
packagerConfig: {
name: pkgJSON.productName,
},
rebuildConfig: {},
makers: [
new MakerSquirrel({}),
new MakerZIP({}, ["win32"]),
new MakerDeb({
options: {
maintainer: pkgJSON.author.name,
homepage: pkgJSON.author.url,
bin: "./" + pkgJSON.productName,
},
}),
new MakerRpm({}),
],
plugins: [
new VitePlugin({
build: [
{
// `entry` is just an alias for `build.lib.entry` in the corresponding file of `config`.
entry: "src/electron/main.ts",
config: "vite.main.config.ts",
},
{
entry: "src/electron/preload.ts",
config: "vite.preload.config.ts",
},
],
renderer: [
{
name: "main_window",
config: "vite.renderer.config.ts",
},
],
}),
],
hooks: {
postMake: (config, makeResults) => {
return new Promise((res) => {
// writeFileSync("./test.json", JSON.stringify(makeResults, null, "\t"));
const filesToUpload = [] as string[];
let downloadBtns = `## Downloads\n\n`;
const appName = pkgJSON.productName;
const appVersion = "v" + pkgJSON.version;
// will only work for either win32 or linux
// need to manually add linux button when building on win32
const MAP = {
"win32+zip+ia32": {
name: `${appName}-${appVersion}-Portable-x32.zip`,
text: "Download 32-bit Portable (zip)",
icon: "windows&logoColor=blue",
},
"win32+zip+x64": {
name: `${appName}-${appVersion}-Portable-x64.zip`,
text: "Download 64-bit Portable (zip)",
icon: "windows&logoColor=blue",
},
"win32+exe+ia32": {
name: `${appName}-${appVersion}-Setup-x32.exe`,
text: "Download 32-bit Setup (exe)",
icon: "windows&logoColor=blue",
},
"win32+exe+x64": {
name: `${appName}-${appVersion}-Setup-x64.exe`,
text: "Download 64-bit Setup (exe)",
icon: "windows&logoColor=blue",
},
"linux+deb+amd64": {
name: `${appName}-${appVersion}-amd64.deb`,
text: "Download 64-bit Linux (Debian)",
icon: "debian&logoColor=red",
},
};
const mainOutDir = path.resolve("./out/all");
if (!existsSync(mainOutDir)) mkdirSync(mainOutDir);
makeResults.forEach((e1, i1) => {
//for reference
// "artifacts": [
// "C:\\Users\\sukoo\\code\\electron\\ytdl-gui\\out\\make\\squirrel.windows\\ia32\\RELEASES",
// "C:\\Users\\sukoo\\code\\electron\\ytdl-gui\\out\\make\\squirrel.windows\\ia32\\ytdl-gui-0.0.2 Setup.exe",
// "C:\\Users\\sukoo\\code\\electron\\ytdl-gui\\out\\make\\squirrel.windows\\ia32\\ytdl_gui-0.0.2-full.nupkg"
// ],
// "artifacts": [
// "C:\\Users\\sukoo\\code\\electron\\ytdl-gui\\out\\make\\zip\\win32\\ia32\\ytdl-gui-win32-ia32-0.0.2.zip"
// ],
const i2 = e1.artifacts.length === 1 ? 0 : 1;
const { name, text, icon } =
MAP[`${e1.platform}+${path.extname(e1.artifacts[i2]).replace(".", "")}+${e1.arch}`];
if (name) {
const newPath = path.join(mainOutDir, name);
renameSync(e1.artifacts[i2], newPath);
filesToUpload.push(newPath.replace(/\\/g, "/"));
makeResults[i1].artifacts[i2] = newPath;
downloadBtns += `[.replace(/-/g, "--")}-${encodeURIComponent(name).replace(
/-/g,
"--"
)}-brightgreen?logo=${icon})](${
pkgJSON.author.url
}/releases/download/${appVersion}/${name})\n`;
}
});
// for linux build (downloaded)
// {
// const { name, text, icon } = MAP["linux+deb+amd64"];
// downloadBtns += `[.replace(
// /-/g,
// "--"
// )}-${encodeURIComponent(name).replace(/-/g, "--")}-brightgreen?logo=${icon})](${
// pkgJSON.author.url
// }/releases/download/${name})\n`;
// }
downloadBtns += "---\n\n";
const base = readFileSync("./changelog.md", "utf-8");
writeFileSync("./changelog-temp.md", downloadBtns + base, "utf-8");
writeFileSync("./filesToUpload.txt", filesToUpload.join(" "));
res(makeResults);
});
},
// removing extra files
postPackage: async (config, packageResult) => {
const filesToKeep = [".vite", "package.json", "node_modules", "LICENSE"];
const appPath = join(packageResult.outputPaths[0], "resources/app");
const allFiles = readdirSync(appPath)
.filter((e) => !filesToKeep.includes(e))
.map((e) => join(appPath, e));
// writeFileSync("test.json", JSON.stringify(allFiles, null, "\t"));
allFiles.forEach((e) => {
rmSync(e, { force: true, recursive: true });
});
},
},
};
export default config;