1
0
Fork 0
mirror of https://gitlab.com/futo-org/fcast.git synced 2025-06-24 21:25:23 +00:00
fcast/receivers/electron/forge.config.js

264 lines
11 KiB
JavaScript
Raw Permalink Normal View History

2024-10-21 20:51:07 +00:00
const fs = require('fs');
const yargs = require('yargs/yargs');
const { hideBin } = require('yargs/helpers');
2024-11-18 12:52:31 -06:00
const cp = require('child_process');
2024-10-21 20:51:07 +00:00
const path = require('path');
// const extract = require('extract-zip')
const { FusesPlugin } = require('@electron-forge/plugin-fuses');
const { FuseV1Options, FuseVersion } = require('@electron/fuses');
const argv = yargs(hideBin(process.argv)).argv;
const APPLICATION_NAME = 'fcast-receiver';
const APPLICATION_TITLE = 'FCast Receiver';
2024-11-18 12:52:31 -06:00
const CI_SIGNING_DIR = '/deploy/signing';
2024-10-21 20:51:07 +00:00
module.exports = {
packagerConfig: {
asar: true,
2024-11-04 09:17:20 -06:00
icon: './assets/icons/app/icon',
2024-10-21 20:51:07 +00:00
osxSign: {},
osxNotarize: {
appleApiKey: process.env.FCAST_APPLE_API_KEY,
appleApiKeyId: process.env.FCAST_APPLE_API_KEY_ID,
appleApiIssuer: process.env.FCAST_APPLE_API_ISSUER
}
},
rebuildConfig: {},
makers: [
{
name: '@electron-forge/maker-deb',
config: {
options: {
categories: ['AudioVideo', 'Audio', 'Video', 'Network', 'Utility'],
homepage: 'https://fcast.org/',
2024-11-04 09:17:20 -06:00
icon: './assets/icons/app/icon.png',
2024-10-21 20:51:07 +00:00
}
},
},
{
name: '@electron-forge/maker-dmg',
config: {
additionalDMGOptions: {
window: {
position: {
x: 425,
y: 275
},
size: {
width: 640,
height: 480
}
}
},
background: './assets/images/background.png',
contents: [
{ 'x': 190, 'y': 350, 'type': 'file', 'path': `out/${APPLICATION_NAME}-darwin-${argv.arch}/${APPLICATION_TITLE}.app` },
{ 'x': 460, 'y': 350, 'type': 'link', 'path': '/Applications' },
2024-10-21 20:51:07 +00:00
{ 'x': 0, 'y': 540, 'type': 'position', 'path': '.background' },
{ 'x': 120, 'y': 540, 'type': 'position', 'path': '.VolumeIcon.icns' }
],
format: 'ULFO',
2024-11-04 09:17:20 -06:00
icon: './assets/icons/app/icon.icns',
2024-10-21 20:51:07 +00:00
name: APPLICATION_TITLE
}
},
{
name: '@electron-forge/maker-rpm',
config: {
options: {
categories: ['AudioVideo', 'Audio', 'Video', 'Network', 'Utility'],
homepage: 'https://fcast.org/',
2024-11-04 09:17:20 -06:00
icon: './assets/icons/app/icon.png',
2024-10-21 20:51:07 +00:00
license: 'MIT',
}
},
},
// Same as '@electron-forge/maker-wix', except linux compatible
{
name: '@futo/forge-maker-wix-linux',
config: {
arch: 'x64',
appUserModelId: `org.futo.${APPLICATION_NAME}`,
2024-11-04 09:17:20 -06:00
icon: './assets/icons/app/icon.ico',
2024-10-21 20:51:07 +00:00
name: APPLICATION_TITLE,
programFilesFolderName: APPLICATION_TITLE,
shortcutName: APPLICATION_TITLE,
}
},
{
name: '@electron-forge/maker-zip',
// Manually creating zip for mac targets due to .app renaming
platforms: ["win32", "linux"],
config: {}
},
],
hooks: {
2024-11-11 12:24:17 -06:00
readPackageJson: async (forgeConfig, packageJson) => {
2024-11-21 11:51:46 -06:00
packageJson.commit = cp.execSync('git rev-parse HEAD').toString().trim();
2024-11-11 12:24:17 -06:00
packageJson.channel = process.env.FCAST_CHANNEL ? process.env.FCAST_CHANNEL : 'stable';
if (packageJson.channel !== 'stable') {
packageJson.channelVersion = process.env.FCAST_CHANNEL_VERSION ? process.env.FCAST_CHANNEL_VERSION : '1';
}
return packageJson;
},
postPackage: async (config, packageResults) => {
2024-10-21 20:51:07 +00:00
switch (packageResults.platform) {
2024-11-18 12:52:31 -06:00
case "win32": {
const exePath = `./out/${APPLICATION_NAME}-${packageResults.platform}-${packageResults.arch}/${APPLICATION_NAME}.exe`;
2024-11-18 14:09:03 -06:00
if (fs.existsSync(CI_SIGNING_DIR)) {
2024-11-21 13:11:19 -06:00
console.log(cp.execSync(path.join(CI_SIGNING_DIR, `sign.sh ${exePath}`)).toString().trim());
2024-11-18 14:09:03 -06:00
}
else {
console.warn('Windows signing script not found, skipping...');
}
2024-11-18 12:52:31 -06:00
break;
}
2024-10-21 20:51:07 +00:00
case "darwin": {
let artifactName = `${APPLICATION_NAME}.app`;
if (fs.existsSync(`./out/${APPLICATION_NAME}-${packageResults.platform}-${packageResults.arch}/${artifactName}`)) {
fs.renameSync(`./out/${APPLICATION_NAME}-${packageResults.platform}-${packageResults.arch}/${artifactName}`, `./out/${APPLICATION_NAME}-${packageResults.platform}-${packageResults.arch}/${APPLICATION_TITLE}.app`);
}
break;
}
2024-11-19 14:49:08 -06:00
case "linux": {
// Workaround for broken Ubuntu builds due to sandboxing permissions:
// * https://github.com/electron/electron/issues/17972c
// * https://github.com/electron/electron/issues/41066
fs.renameSync(`./out/${APPLICATION_NAME}-${packageResults.platform}-${packageResults.arch}/${APPLICATION_NAME}`, `./out/${APPLICATION_NAME}-${packageResults.platform}-${packageResults.arch}/${APPLICATION_NAME}.app`);
fs.writeFileSync(`./out/${APPLICATION_NAME}-${packageResults.platform}-${packageResults.arch}/${APPLICATION_NAME}`,
'#!/bin/sh\n' +
2024-11-19 15:18:36 -06:00
'if [ "$0" = "/usr/bin/fcast-receiver" ]; then\n' +
'\tbin="/usr/lib/fcast-receiver/fcast-receiver.app"\n' +
2024-11-19 14:49:08 -06:00
'else\n' +
2024-11-19 15:18:36 -06:00
'\tbin="$0.app"\n' +
2024-11-19 14:49:08 -06:00
'fi\n' +
'"$bin" --no-sandbox --password-store=basic $*'
2024-11-19 14:49:08 -06:00
);
fs.chmodSync(`./out/${APPLICATION_NAME}-${packageResults.platform}-${packageResults.arch}/${APPLICATION_NAME}`, 0o755);
2024-11-19 15:18:36 -06:00
break;
2024-11-19 14:49:08 -06:00
}
2024-10-21 20:51:07 +00:00
default:
break;
}
},
2024-11-11 12:24:17 -06:00
2024-10-21 20:51:07 +00:00
postMake: async (forgeConfig, makeResults) => {
for (const e of makeResults) {
// Standardize artifact output naming
switch (e.platform) {
case "win32": {
let artifactName = `${APPLICATION_NAME}-win32-${e.arch}-${e.packageJSON.version}.zip`;
if (fs.existsSync(`./out/make/zip/win32/${e.arch}/${artifactName}`)) {
2024-11-11 12:24:17 -06:00
fs.renameSync(`./out/make/zip/win32/${e.arch}/${artifactName}`, path.join(`./out/make/zip/win32/${e.arch}`, generateArtifactName(e.packageJSON, e.platform, e.arch, 'zip')));
2024-10-21 20:51:07 +00:00
}
artifactName = `${APPLICATION_NAME}.msi`;
if (fs.existsSync(`./out/make/wix/${e.arch}/${artifactName}`)) {
2024-11-18 12:52:31 -06:00
const artifactPath = path.join(`./out/make/wix/${e.arch}`, generateArtifactName(e.packageJSON, e.platform, e.arch, 'msi'));
fs.renameSync(`./out/make/wix/${e.arch}/${artifactName}`, artifactPath);
2024-11-18 14:09:03 -06:00
if (fs.existsSync(CI_SIGNING_DIR)) {
2024-11-21 13:11:19 -06:00
console.log(cp.execSync(path.join(CI_SIGNING_DIR, `sign.sh ${artifactPath}`)).toString().trim());
2024-11-18 14:09:03 -06:00
}
else {
console.warn('Windows signing script not found, skipping...');
}
2024-10-21 20:51:07 +00:00
}
break;
}
case "darwin": {
let artifactName = `${APPLICATION_TITLE}.dmg`;
if (fs.existsSync(`./out/make/${artifactName}`)) {
fs.mkdirSync(`./out/make/dmg/${e.arch}`, { recursive: true });
2024-11-11 12:24:17 -06:00
fs.renameSync(`./out/make/${artifactName}`, path.join(`./out/make/dmg/${e.arch}`, generateArtifactName(e.packageJSON, e.platform, e.arch, 'dmg')));
2024-10-21 20:51:07 +00:00
}
console.log(`Making a zip distributable for ${e.platform}/${e.arch}`);
2024-11-11 12:24:17 -06:00
const zipPath = path.resolve(process.cwd(), 'out', 'make', 'zip', e.platform, e.arch, generateArtifactName(e.packageJSON, e.platform, e.arch, 'zip'));
2024-10-21 20:51:07 +00:00
2024-11-21 13:11:19 -06:00
console.log(cp.execSync(`mkdir -p ${path.dirname(zipPath)}`).toString().trim());
console.log(cp.execSync(`cd out/${APPLICATION_NAME}-${e.platform}-${e.arch}; zip -r -y "${zipPath}" "${APPLICATION_TITLE}.app"`).toString().trim());
2024-10-21 20:51:07 +00:00
break;
}
case "linux": {
let artifactName = `${APPLICATION_NAME}-linux-${e.arch}-${e.packageJSON.version}.zip`;
if (fs.existsSync(`./out/make/zip/linux/${e.arch}/${artifactName}`)) {
2024-11-11 12:24:17 -06:00
fs.renameSync(`./out/make/zip/linux/${e.arch}/${artifactName}`, path.join(`./out/make/zip/linux/${e.arch}`, generateArtifactName(e.packageJSON, e.platform, e.arch, 'zip')));
2024-10-21 20:51:07 +00:00
}
artifactName = `${APPLICATION_NAME}_${e.packageJSON.version}_amd64.deb`
if (fs.existsSync(`./out/make/deb/${e.arch}/${artifactName}`)) {
2024-11-11 12:24:17 -06:00
fs.renameSync(`./out/make/deb/${e.arch}/${artifactName}`, path.join(`./out/make/deb/${e.arch}`, generateArtifactName(e.packageJSON, e.platform, e.arch, 'deb')));
2024-10-21 20:51:07 +00:00
}
artifactName = `${APPLICATION_NAME}_${e.packageJSON.version}_arm64.deb`
if (fs.existsSync(`./out/make/deb/${e.arch}/${artifactName}`)) {
2024-11-11 12:24:17 -06:00
fs.renameSync(`./out/make/deb/${e.arch}/${artifactName}`, path.join(`./out/make/deb/${e.arch}`, generateArtifactName(e.packageJSON, e.platform, e.arch, 'deb')));
2024-10-21 20:51:07 +00:00
}
artifactName = `${APPLICATION_NAME}-${e.packageJSON.version}-1.x86_64.rpm`
if (fs.existsSync(`./out/make/rpm/${e.arch}/${artifactName}`)) {
2024-11-11 12:24:17 -06:00
fs.renameSync(`./out/make/rpm/${e.arch}/${artifactName}`, path.join(`./out/make/rpm/${e.arch}`, generateArtifactName(e.packageJSON, e.platform, e.arch, 'rpm')));
2024-10-21 20:51:07 +00:00
}
artifactName = `${APPLICATION_NAME}-${e.packageJSON.version}-1.arm64.rpm`
if (fs.existsSync(`./out/make/rpm/${e.arch}/${artifactName}`)) {
2024-11-11 12:24:17 -06:00
fs.renameSync(`./out/make/rpm/${e.arch}/${artifactName}`, path.join(`./out/make/rpm/${e.arch}`, generateArtifactName(e.packageJSON, e.platform, e.arch, 'rpm')));
2024-10-21 20:51:07 +00:00
}
break;
}
default:
break;
}
}
}
},
plugins: [
{
name: '@electron-forge/plugin-auto-unpack-natives',
config: {},
},
// Fuses are used to enable/disable various Electron functionality
// at package time, before code signing the application
new FusesPlugin({
version: FuseVersion.V1,
[FuseV1Options.RunAsNode]: false,
[FuseV1Options.EnableCookieEncryption]: true,
[FuseV1Options.EnableNodeOptionsEnvironmentVariable]: false,
[FuseV1Options.EnableNodeCliInspectArguments]: false,
[FuseV1Options.EnableEmbeddedAsarIntegrityValidation]: false,
2024-10-21 20:51:07 +00:00
[FuseV1Options.OnlyLoadAppFromAsar]: true,
}),
],
};
2024-11-11 12:24:17 -06:00
function getArtifactOS(platform) {
switch (platform) {
case 'win32':
return 'windows';
case 'darwin':
return 'macOS';
default:
return platform;
}
}
function generateArtifactName(packageJSON, platform, arch, extension) {
let artifactName = `${APPLICATION_NAME}-${packageJSON.version}-${getArtifactOS(platform)}-${arch}`;
if (extension === 'msi') {
artifactName += '-setup';
}
if (packageJSON.channel !== 'stable') {
2024-11-11 17:48:34 -06:00
artifactName += `-${packageJSON.channel}-${packageJSON.channelVersion}`;
2024-11-11 12:24:17 -06:00
}
artifactName += `.${extension}`
return artifactName;
}