-
Notifications
You must be signed in to change notification settings - Fork 380
Expand file tree
/
Copy pathforge.config.js
More file actions
196 lines (190 loc) · 7.27 KB
/
forge.config.js
File metadata and controls
196 lines (190 loc) · 7.27 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
import path from 'node:path';
import fs from 'node:fs';
import { fileURLToPath } from 'node:url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
export default {
packagerConfig: {
executableName: "inav-configurator",
asar: false,
icon: 'images/inav',
extraResource: [
'resources/public/sitl'
],
},
rebuildConfig: {},
plugins: [
{
name: '@electron-forge/plugin-vite',
config: {
build: [
{
entry: 'js/main/main.js',
config: 'vite.main.config.js',
},
{
entry: 'js/main/preload.js',
config: 'vite.preload.config.js',
},
{
entry: 'js/libraries/bluetooth-device-chooser/bt-device-chooser-preload.js',
config: 'vite.preload.config.js',
},
],
renderer: [
{
name: 'bt_device_chooser',
config: 'vite.bt-dc-renderer.config.js',
},
{
name: 'main_window',
config: 'vite.main-renderer.config.js',
},
],
},
},
],
hooks: {
// Remove SITL binaries for other platforms/architectures to reduce package size
postPackage: async (forgeConfig, options) => {
for (const outputPath of options.outputPaths) {
let sitlPath;
if (options.platform === 'darwin') {
// macOS app bundle structure: <outputDir>/<AppName>.app/Contents/Resources/sitl
// Find the .app directory
const appBundles = fs.readdirSync(outputPath).filter(f => f.endsWith('.app'));
if (appBundles.length === 0) {
console.log(`postPackage: No .app bundle found in ${outputPath}`);
continue;
}
sitlPath = path.join(outputPath, appBundles[0], 'Contents', 'Resources', 'sitl');
} else {
// Windows/Linux: <outputPath>/resources/sitl
sitlPath = path.join(outputPath, 'resources', 'sitl');
}
console.log(`postPackage: Checking SITL path for ${options.platform}: ${sitlPath}`);
if (!fs.existsSync(sitlPath)) {
console.log(`postPackage: SITL path not found, skipping: ${sitlPath}`);
continue;
}
if (options.platform === 'win32') {
console.log('postPackage: Removing non-Windows SITL binaries (linux, macos)');
fs.rmSync(path.join(sitlPath, 'linux'), { recursive: true, force: true });
fs.rmSync(path.join(sitlPath, 'macos'), { recursive: true, force: true });
} else if (options.platform === 'darwin') {
console.log('postPackage: Removing non-macOS SITL binaries (linux, windows)');
fs.rmSync(path.join(sitlPath, 'linux'), { recursive: true, force: true });
fs.rmSync(path.join(sitlPath, 'windows'), { recursive: true, force: true });
} else if (options.platform === 'linux') {
console.log('postPackage: Removing non-Linux SITL binaries (macos, windows)');
fs.rmSync(path.join(sitlPath, 'macos'), { recursive: true, force: true });
fs.rmSync(path.join(sitlPath, 'windows'), { recursive: true, force: true });
// Remove wrong architecture
if (options.arch === 'x64') {
fs.rmSync(path.join(sitlPath, 'linux', 'arm64'), { recursive: true, force: true });
} else if (options.arch === 'arm64') {
// Move arm64 binary to linux root and remove x64
const arm64Binary = path.join(sitlPath, 'linux', 'arm64', 'inav_SITL');
const destBinary = path.join(sitlPath, 'linux', 'inav_SITL');
if (fs.existsSync(arm64Binary)) {
fs.rmSync(destBinary, { force: true });
fs.renameSync(arm64Binary, destBinary);
fs.rmSync(path.join(sitlPath, 'linux', 'arm64'), { recursive: true, force: true });
}
}
}
}
},
// Uniform artifact file names
postMake: async (config, makeResults) => {
makeResults.forEach(result => {
var baseName = `${result.packageJSON.productName.replace(' ', '-')}_${result.platform}_${result.arch}_${result.packageJSON.version}`;
result.artifacts.forEach(artifact => {
var artifactStr = artifact.toString();
var newPath = path.join(path.dirname(artifactStr), baseName + path.extname(artifactStr));
newPath = newPath.replace('Configurator_win32_ia32', 'Configurator_Win32');
newPath = newPath.replace('Configurator_win32_x64', 'Configurator_Win64');
newPath = newPath.replace('Configurator_darwin', 'Configurator_MacOS');
fs.renameSync(artifactStr, newPath);
console.log('Artifact: ' + newPath);
});
});
},
},
makers: [
{
name: '@electron-forge/maker-wix',
config: {
name: "INAV Configurator",
shortName: "INAV",
exe: "inav-configurator",
description: "Configurator for the open source flight controller software INAV.",
programFilesFolderName: "inav-configurator",
shortcutFolderName: "INAV",
manufacturer: "The INAV open source project",
appUserModelId: "com.inav.configurator",
icon: path.join(__dirname, "./assets/windows/inav_installer_icon.ico"),
upgradeCode: "13606ff3-b0bc-4dde-8fac-805bc8aed2f8",
ui: {
enabled: false,
chooseDirectory: true,
images: {
background: path.join(__dirname, "./assets/windows/background.jpg"),
banner: path.join(__dirname, "./assets/windows/banner.jpg")
}
},
// Standard WiX template appends the unsightly "(Machine - WSI)" to the name, so use our own template
beforeCreate: (msiCreator) => {
return new Promise((resolve, reject) => {
fs.readFile(path.join(__dirname,"./assets/windows/wix.xml"), "utf8" , (err, content) => {
if (err) {
reject (err);
}
msiCreator.wixTemplate = content;
resolve();
});
});
}
}
},
{
name: '@electron-forge/maker-dmg',
config: {
name: "INAV Configurator",
title: "INAV-Configurator", // Volume name without spaces to avoid hdiutil detach issues
background: "./assets/osx/dmg-background.png",
icon: "./images/inav.icns"
}
},
{
name: '@electron-forge/maker-zip',
platforms: ['win32', 'linux', 'darwin'],
},
{
name: '@electron-forge/maker-deb',
config: {
options: {
name: "inav-configurator",
productName: "INAV Configurator",
categories: ["Utility"],
icon: "./assets/linux/icon/inav_icon_128.png",
description: "Configurator for the open source flight controller software INAV.",
homepage: "https://github.com/inavflight/",
}
},
},
{
name: '@electron-forge/maker-rpm',
config: {
options: {
name: "inav-configurator",
productName: "INAV Configurator",
license: "GPL-3.0",
categories: ["Utility"],
icon: "./assets/linux/icon/inav_icon_128.png",
description: "Configurator for the open source flight controller software INAV.",
homepage: "https://github.com/inavflight/",
}
},
},
],
};