Skip to content

Commit

Permalink
Convert the electron builder config from yaml to js file
Browse files Browse the repository at this point in the history
Having a js file will enable further customization of the build process.
That capability will be used notably for #6535 to download `WinFSP` installer when building the Windows installer.
  • Loading branch information
FirelightFlagboy committed Mar 8, 2024
1 parent c0f838c commit 1db1a9e
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 54 deletions.
1 change: 0 additions & 1 deletion .github/workflows/package-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ jobs:
os: ubuntu-20.04
paths: |
client/electron/dist/parsec-v3_*_*.snap
client/electron/dist/parsec-v3-*.AppImage
client/electron/dist/latest-linux.yml
- name: 🏁 Windows
platform: windows
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/releaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ jobs:
cp -v artifacts/Windows-X64-wheel/parsec_cloud-${{ needs.version.outputs.pep440 }}-*.whl release-files
cp -v artifacts/Linux-X64-electron-app/client/electron/dist/parsec-v3_${{ needs.version.outputs.no_local }}_amd64.snap release-files
cp -v artifacts/Linux-X64-electron-app/client/electron/dist/parsec-v3-${{ needs.version.outputs.no_local }}.AppImage release-files
cp -v artifacts/macOS-X64-electron-app/client/electron/dist/parsec-v3-${{ needs.version.outputs.no_local }}.dmg release-files
Expand Down
44 changes: 0 additions & 44 deletions client/electron/electron-builder.config.yml

This file was deleted.

30 changes: 23 additions & 7 deletions client/electron/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

116 changes: 116 additions & 0 deletions client/electron/package.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
// Parsec Cloud (https://parsec.cloud) Copyright (c) BUSL-1.1 2016-present Scille SAS

const builder = require('electron-builder');

/**
* @returns {{
* mode: 'test' | 'prod',
* platform: 'linux' | 'win32' | 'darwin',
* }}
*/
function cli() {
const { Command, Option } = require('commander');
const program = new Command();

program.name('electron-packager').description('Package the electron app');

program.addOption(new Option('--mode <mode>', 'package mode').choices(['test', 'prod']).default('test').makeOptionMandatory(true));
program.addOption(
new Option('--platform <platform>', 'Build electron for <platform>')
.choices(['linux', 'win32', 'darwin', builder.DEFAULT_TARGET])
.default(builder.DEFAULT_TARGET)
.makeOptionMandatory(true),
);

program.parse();
return program.opts();
}

/**
* @param {string} platform
* @return {Map<builder.Platform, Map<builder.Arch, string[]>>}
*/
function getBuildTargets(platform) {
switch (platform) {
case 'linux':
return builder.Platform.LINUX.createTarget();
case 'darwin':
return builder.Platform.MAC.createTarget();
case 'win32':
return builder.Platform.WINDOWS.createTarget();
case builder.DEFAULT_TARGET:
return builder.Platform.current().createTarget();
default:
throw new Error(`Unknown platform: ${platform}`);
}
}
const OPTS = cli();
console.debug(OPTS);

const BUILD_TARGETS = getBuildTargets(OPTS.platform);
console.log('BUILD_TARGETS', BUILD_TARGETS);

const PARSEC_SCHEME = 'parsec3';

/**
* @type {import('electron-builder').Configuration}
* @see https://www.electron.build/configuration/configuration
*/
const options = {
appId: 'cloud.parsec.parsec-v3',
protocols: {
name: 'Parsec-v3',
schemes: [PARSEC_SCHEME],
},

compression: OPTS.mode === 'test' ? 'store' : 'normal',

directories: {
buildResources: 'assets',
},

files: ['assets/**/*', 'build/**/*', 'app/**/*'],

publish: {
provider: 'github',
},

win: {
target: 'nsis',
},

nsis: {
allowElevation: true,
oneClick: false,
allowToChangeInstallationDirectory: true,
},

mac: {
target: 'dmg',
category: 'public.app-category.productivity',
},

linux: {
synopsis: 'Secure cloud framework',
description: 'Parsec is an open-source cloud-based application that allow simple yet cryptographically secure file hosting.',
category: 'Office Network FileTransfer FileSystem Security',
desktop: {
MimeType: `x-scheme-handler/${PARSEC_SCHEME}`,
},
target: 'snap',
},

snap: {
base: 'core22',
grade: 'devel',
allowNativeWayland: true,
stagePackages: ['default', 'fuse3'],
},

extends: null,
};
builder.build({
targets: BUILD_TARGETS,
publish: 'never',
config: options,
});
3 changes: 2 additions & 1 deletion client/electron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"build": "npm run libparsec:copy && tsc",
"electron:start-live": "npm run build && node ./live-runner.js",
"electron:start": "npm run build && electron --inspect=5858 ./",
"electron:release": "npm run build && npx electron-builder build --config ./electron-builder.config.yml --publish never"
"electron:release": "npm run build && node package.js --mode prod"
},
"dependencies": {
"@capacitor-community/electron": "^5.0.1",
Expand All @@ -29,6 +29,7 @@
"electron-window-state": "~5.0.3"
},
"devDependencies": {
"commander": "^12.0.0",
"electron": "^28.1.3",
"electron-builder": "~24.9.1",
"typescript": "~5.3.3"
Expand Down

0 comments on commit 1db1a9e

Please sign in to comment.