2022-08-23 01:49:23 +03:00
|
|
|
|
/**
|
|
|
|
|
* This module defines a TS script that is responsible for invoking the Electron Builder process to
|
|
|
|
|
* bundle the entire IDE distribution.
|
|
|
|
|
*
|
|
|
|
|
* There are two areas to this:
|
|
|
|
|
* - Parsing CLI options as per our needs.
|
|
|
|
|
* - The default configuration of the build process.
|
|
|
|
|
*
|
|
|
|
|
* @module
|
|
|
|
|
*/
|
|
|
|
|
|
2022-05-23 05:16:04 +03:00
|
|
|
|
import path from 'node:path'
|
2022-09-19 22:02:18 +03:00
|
|
|
|
import child_process from 'node:child_process'
|
2022-08-10 04:41:44 +03:00
|
|
|
|
import fs from 'node:fs/promises'
|
2022-08-23 01:49:23 +03:00
|
|
|
|
import { CliOptions, Configuration, LinuxTargetSpecificOptions, Platform } from 'electron-builder'
|
|
|
|
|
import builder from 'electron-builder'
|
2022-09-19 22:02:18 +03:00
|
|
|
|
import { notarize } from 'electron-notarize'
|
|
|
|
|
import signArchivesMacOs from './tasks/signArchivesMacOs.js'
|
2020-12-23 01:14:52 +03:00
|
|
|
|
|
2022-08-10 04:41:44 +03:00
|
|
|
|
import { project_manager_bundle } from './paths.js'
|
2022-05-23 05:16:04 +03:00
|
|
|
|
import build from '../../build.json' assert { type: 'json' }
|
2022-08-23 01:49:23 +03:00
|
|
|
|
import yargs from 'yargs'
|
|
|
|
|
import { MacOsTargetName } from 'app-builder-lib/out/options/macOptions'
|
2020-03-16 05:58:00 +03:00
|
|
|
|
|
2022-08-23 01:49:23 +03:00
|
|
|
|
const args = await yargs(process.argv.slice(2))
|
|
|
|
|
.env('ENSO_BUILD')
|
|
|
|
|
.option({
|
|
|
|
|
ideDist: {
|
|
|
|
|
// Alias here (and subsequent occurrences) are for the environment variable name.
|
|
|
|
|
alias: 'ide',
|
|
|
|
|
type: 'string',
|
|
|
|
|
description: 'Output directory for IDE',
|
|
|
|
|
demandOption: true,
|
|
|
|
|
},
|
|
|
|
|
guiDist: {
|
|
|
|
|
alias: 'gui',
|
|
|
|
|
type: 'string',
|
|
|
|
|
description: 'Output directory with GUI',
|
|
|
|
|
demandOption: true,
|
|
|
|
|
},
|
|
|
|
|
iconsDist: {
|
|
|
|
|
alias: 'icons',
|
|
|
|
|
type: 'string',
|
|
|
|
|
description: 'Output directory with icons',
|
|
|
|
|
demandOption: true,
|
|
|
|
|
},
|
|
|
|
|
projectManagerDist: {
|
|
|
|
|
alias: 'project-manager',
|
|
|
|
|
type: 'string',
|
|
|
|
|
description: 'Output directory with project manager',
|
|
|
|
|
demandOption: true,
|
|
|
|
|
},
|
|
|
|
|
platform: {
|
|
|
|
|
type: 'string',
|
|
|
|
|
description: 'Platform that Electron Builder should target',
|
|
|
|
|
default: Platform.current().toString(),
|
|
|
|
|
coerce: (p: string) => Platform.fromString(p),
|
|
|
|
|
},
|
|
|
|
|
targetOverride: {
|
|
|
|
|
type: 'string',
|
|
|
|
|
description: 'Overwrite the platform-default target',
|
|
|
|
|
},
|
|
|
|
|
}).argv
|
2020-03-16 05:58:00 +03:00
|
|
|
|
|
2022-08-10 04:41:44 +03:00
|
|
|
|
const config: Configuration = {
|
2020-12-30 06:37:51 +03:00
|
|
|
|
appId: 'org.enso',
|
|
|
|
|
productName: 'Enso',
|
2022-05-23 05:16:04 +03:00
|
|
|
|
extraMetadata: {
|
|
|
|
|
version: build.version,
|
|
|
|
|
},
|
|
|
|
|
copyright: 'Copyright © 2022 ${author}.',
|
2021-02-02 08:07:43 +03:00
|
|
|
|
artifactName: 'enso-${os}-${version}.${ext}',
|
2020-03-16 05:58:00 +03:00
|
|
|
|
mac: {
|
2021-02-05 03:44:21 +03:00
|
|
|
|
// We do not use compression as the build time is huge and file size saving is almost zero.
|
2022-08-23 01:49:23 +03:00
|
|
|
|
target: (args.targetOverride as MacOsTargetName) ?? 'dmg',
|
|
|
|
|
icon: `${args.iconsDist}/icon.icns`,
|
2020-12-23 01:14:52 +03:00
|
|
|
|
category: 'public.app-category.developer-tools',
|
2020-03-16 05:58:00 +03:00
|
|
|
|
darkModeSupport: true,
|
2020-12-23 01:14:52 +03:00
|
|
|
|
type: 'distribution',
|
2021-06-10 12:56:51 +03:00
|
|
|
|
// The following settings are required for macOS signing and notarisation.
|
|
|
|
|
// The hardened runtime is required to be able to notarise the application.
|
|
|
|
|
hardenedRuntime: true,
|
|
|
|
|
// This is a custom check that is not working correctly, so we disable it. See for more
|
|
|
|
|
// details https://kilianvalkhof.com/2019/electron/notarizing-your-electron-application/
|
|
|
|
|
gatekeeperAssess: false,
|
|
|
|
|
// Location of the entitlements files with the entitlements we need to run our application
|
|
|
|
|
// in the hardened runtime.
|
|
|
|
|
entitlements: './entitlements.mac.plist',
|
|
|
|
|
entitlementsInherit: './entitlements.mac.plist',
|
2020-03-16 05:58:00 +03:00
|
|
|
|
},
|
|
|
|
|
win: {
|
2021-02-05 03:44:21 +03:00
|
|
|
|
// We do not use compression as the build time is huge and file size saving is almost zero.
|
2022-08-23 01:49:23 +03:00
|
|
|
|
target: args.targetOverride ?? 'nsis',
|
|
|
|
|
icon: `${args.iconsDist}/icon.ico`,
|
2020-03-16 05:58:00 +03:00
|
|
|
|
},
|
|
|
|
|
linux: {
|
2021-02-05 03:44:21 +03:00
|
|
|
|
// We do not use compression as the build time is huge and file size saving is almost zero.
|
2022-08-23 01:49:23 +03:00
|
|
|
|
target: args.targetOverride ?? 'AppImage',
|
|
|
|
|
icon: `${args.iconsDist}/png`,
|
2020-12-23 01:14:52 +03:00
|
|
|
|
category: 'Development',
|
2020-03-16 05:58:00 +03:00
|
|
|
|
},
|
2022-05-23 05:16:04 +03:00
|
|
|
|
files: [
|
|
|
|
|
'!**/node_modules/**/*',
|
2022-08-23 01:49:23 +03:00
|
|
|
|
{ from: `${args.guiDist}/`, to: '.' },
|
|
|
|
|
{ from: `${args.ideDist}/client`, to: '.' },
|
2022-05-23 05:16:04 +03:00
|
|
|
|
],
|
|
|
|
|
extraResources: [
|
|
|
|
|
{
|
2022-08-23 01:49:23 +03:00
|
|
|
|
from: `${args.projectManagerDist}/`,
|
2022-05-23 05:16:04 +03:00
|
|
|
|
to: project_manager_bundle,
|
|
|
|
|
filter: ['!**.tar.gz', '!**.zip'],
|
|
|
|
|
},
|
|
|
|
|
],
|
2020-03-16 05:58:00 +03:00
|
|
|
|
fileAssociations: [
|
|
|
|
|
{
|
2020-12-23 01:14:52 +03:00
|
|
|
|
ext: 'enso',
|
|
|
|
|
name: 'Enso Source File',
|
|
|
|
|
role: 'Editor',
|
2021-11-05 14:51:43 +03:00
|
|
|
|
},
|
2020-03-16 05:58:00 +03:00
|
|
|
|
],
|
|
|
|
|
directories: {
|
2022-08-23 01:49:23 +03:00
|
|
|
|
output: `${args.ideDist}`,
|
2020-04-24 09:52:26 +03:00
|
|
|
|
},
|
2021-01-26 12:22:33 +03:00
|
|
|
|
nsis: {
|
2021-06-10 12:56:51 +03:00
|
|
|
|
// Disables "block map" generation during electron building. Block maps
|
2021-01-26 12:22:33 +03:00
|
|
|
|
// can be used for incremental package update on client-side. However,
|
|
|
|
|
// their generation can take long time (even 30 mins), so we removed it
|
|
|
|
|
// for now. Moreover, we may probably never need them, as our updates
|
2021-06-10 12:56:51 +03:00
|
|
|
|
// are handled by us. More info:
|
2021-01-26 12:22:33 +03:00
|
|
|
|
// https://github.com/electron-userland/electron-builder/issues/2851
|
|
|
|
|
// https://github.com/electron-userland/electron-builder/issues/2900
|
2021-11-05 14:51:43 +03:00
|
|
|
|
differentialPackage: false,
|
2021-01-26 12:22:33 +03:00
|
|
|
|
},
|
|
|
|
|
dmg: {
|
2021-06-10 12:56:51 +03:00
|
|
|
|
// Disables "block map" generation during electron building. Block maps
|
2021-01-26 12:22:33 +03:00
|
|
|
|
// can be used for incremental package update on client-side. However,
|
|
|
|
|
// their generation can take long time (even 30 mins), so we removed it
|
|
|
|
|
// for now. Moreover, we may probably never need them, as our updates
|
2021-06-10 12:56:51 +03:00
|
|
|
|
// are handled by us. More info:
|
2021-01-26 12:22:33 +03:00
|
|
|
|
// https://github.com/electron-userland/electron-builder/issues/2851
|
|
|
|
|
// https://github.com/electron-userland/electron-builder/issues/2900
|
2021-06-10 12:56:51 +03:00
|
|
|
|
writeUpdateInfo: false,
|
|
|
|
|
// Disable code signing of the final dmg as this triggers an issue
|
|
|
|
|
// with Apple’s Gatekeeper. Since the DMG contains a signed and
|
|
|
|
|
// notarised application it will still be detected as trusted.
|
|
|
|
|
// For more details see step (4) at
|
|
|
|
|
// https://kilianvalkhof.com/2019/electron/notarizing-your-electron-application/
|
2021-11-05 14:51:43 +03:00
|
|
|
|
sign: false,
|
2021-01-26 12:22:33 +03:00
|
|
|
|
},
|
2022-06-01 14:44:40 +03:00
|
|
|
|
afterAllArtifactBuild: path.join('tasks', 'computeHashes.cjs'),
|
2022-05-23 05:16:04 +03:00
|
|
|
|
|
2022-09-19 22:02:18 +03:00
|
|
|
|
afterPack: ctx => {
|
|
|
|
|
if (args.platform === Platform.MAC) {
|
|
|
|
|
// Make the subtree writable so we can sign the binaries.
|
|
|
|
|
// This is needed because GraalVM distribution comes with read-only binaries.
|
|
|
|
|
child_process.execFileSync('chmod', ['-R', 'u+w', ctx.appOutDir])
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
afterSign: async context => {
|
|
|
|
|
// Notarization for macOS.
|
2022-10-12 01:32:08 +03:00
|
|
|
|
if (args.platform === Platform.MAC && process.env['CSC_LINK']) {
|
2022-09-19 22:02:18 +03:00
|
|
|
|
const { packager, appOutDir } = context
|
|
|
|
|
const appName = packager.appInfo.productFilename
|
|
|
|
|
|
|
|
|
|
// We need to manually re-sign our build artifacts before notarization.
|
|
|
|
|
console.log(' • Performing additional signing of dependencies.')
|
|
|
|
|
await signArchivesMacOs({
|
|
|
|
|
appOutDir: appOutDir,
|
|
|
|
|
productFilename: appName,
|
|
|
|
|
entitlements: context.packager.config.mac.entitlements,
|
|
|
|
|
identity: 'Developer ID Application: New Byte Order Sp. z o. o. (NM77WTZJFQ)',
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
console.log(' • Notarizing.')
|
|
|
|
|
notarize({
|
|
|
|
|
appBundleId: packager.platformSpecificBuildOptions.appId,
|
|
|
|
|
appPath: `${appOutDir}/${appName}.app`,
|
|
|
|
|
appleId: process.env.APPLEID,
|
|
|
|
|
appleIdPassword: process.env.APPLEIDPASS,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
},
|
2022-08-23 01:49:23 +03:00
|
|
|
|
|
|
|
|
|
publish: null,
|
2020-03-16 05:58:00 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-08-10 04:41:44 +03:00
|
|
|
|
// `electron-builder` checks for presence of `node_modules` directory. If it is not present, it will
|
|
|
|
|
// install dependencies with `--production` flag (erasing all dev-only dependencies). This does not
|
|
|
|
|
// work sensibly with NPM workspaces. We have our `node_modules` in the root directory, not here.
|
|
|
|
|
//
|
|
|
|
|
// Without this workaround, `electron-builder` will end up erasing its own dependencies and failing
|
|
|
|
|
// because of that.
|
|
|
|
|
await fs.mkdir('node_modules', { recursive: true })
|
2022-08-23 01:49:23 +03:00
|
|
|
|
|
|
|
|
|
const cli_opts: CliOptions = {
|
|
|
|
|
config: config,
|
|
|
|
|
targets: args.platform.createTarget(),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log('Building with configuration:', cli_opts)
|
|
|
|
|
|
|
|
|
|
const result = await builder.build(cli_opts)
|
|
|
|
|
console.log('Electron Builder is done. Result:', result)
|