2023-03-09 18:02:28 +03:00
|
|
|
|
/** @file This module defines a TS script that is responsible for invoking the Electron Builder
|
|
|
|
|
* process to bundle the entire IDE distribution.
|
2022-08-23 01:49:23 +03:00
|
|
|
|
*
|
|
|
|
|
* There are two areas to this:
|
|
|
|
|
* - Parsing CLI options as per our needs.
|
2023-03-09 18:02:28 +03:00
|
|
|
|
* - The default configuration of the build process. */
|
|
|
|
|
/** @module */
|
2022-08-23 01:49:23 +03:00
|
|
|
|
|
2023-03-15 06:42:14 +03:00
|
|
|
|
import * as childProcess from 'node:child_process'
|
|
|
|
|
import * as fs from 'node:fs/promises'
|
2020-12-23 01:14:52 +03:00
|
|
|
|
|
2023-03-15 06:42:14 +03:00
|
|
|
|
import * as electronBuilder from 'electron-builder'
|
2023-11-01 22:58:28 +03:00
|
|
|
|
import * as electronNotarize from '@electron/notarize'
|
2023-10-11 13:24:33 +03:00
|
|
|
|
import type * as macOptions from 'app-builder-lib/out/options/macOptions'
|
2022-08-23 01:49:23 +03:00
|
|
|
|
import yargs from 'yargs'
|
2023-03-15 06:42:14 +03:00
|
|
|
|
|
2023-03-15 14:54:16 +03:00
|
|
|
|
import * as common from 'enso-common'
|
|
|
|
|
|
2023-04-24 15:56:26 +03:00
|
|
|
|
import * as fileAssociations from './file-associations'
|
|
|
|
|
import * as paths from './paths'
|
2023-09-22 06:43:25 +03:00
|
|
|
|
import computeHashes from './tasks/computeHashes.mjs'
|
2023-04-24 15:56:26 +03:00
|
|
|
|
import signArchivesMacOs from './tasks/signArchivesMacOs'
|
2023-03-15 06:42:14 +03:00
|
|
|
|
|
2023-09-22 06:43:25 +03:00
|
|
|
|
import BUILD_INFO from '../../../../build.json' assert { type: 'json' }
|
2020-03-16 05:58:00 +03:00
|
|
|
|
|
2023-05-19 22:55:29 +03:00
|
|
|
|
// =============
|
|
|
|
|
// === Types ===
|
|
|
|
|
// =============
|
|
|
|
|
|
2023-03-03 01:00:47 +03:00
|
|
|
|
/** The parts of the electron-builder configuration that we want to keep configurable.
|
2023-05-19 22:55:29 +03:00
|
|
|
|
* @see `args` definition below for fields description. */
|
2023-03-03 01:00:47 +03:00
|
|
|
|
export interface Arguments {
|
2023-06-19 02:02:08 +03:00
|
|
|
|
// The types come from a third-party API and cannot be changed.
|
2023-03-20 12:35:16 +03:00
|
|
|
|
// eslint-disable-next-line no-restricted-syntax
|
2024-02-07 14:26:59 +03:00
|
|
|
|
readonly target?: string | undefined
|
|
|
|
|
readonly iconsDist: string
|
|
|
|
|
readonly guiDist: string
|
|
|
|
|
readonly ideDist: string
|
|
|
|
|
readonly projectManagerDist: string
|
|
|
|
|
readonly platform: electronBuilder.Platform
|
2023-03-03 01:00:47 +03:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-07 19:22:11 +03:00
|
|
|
|
/** File association configuration, extended with information needed by the `enso-installer`. */
|
|
|
|
|
interface ExtendedFileAssociation extends electronBuilder.FileAssociation {
|
|
|
|
|
/** The Windows registry key under which the file association is registered.
|
|
|
|
|
*
|
|
|
|
|
* Should follow the pattern `Enso.CamelCaseName`. */
|
|
|
|
|
readonly progId: string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Additional configuration for the installer. */
|
|
|
|
|
interface InstallerAdditionalConfig {
|
|
|
|
|
/** The company name to be used in the installer. */
|
|
|
|
|
readonly publisher: string
|
|
|
|
|
|
|
|
|
|
/** File association configuration. */
|
|
|
|
|
readonly fileAssociations: ExtendedFileAssociation[]
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-19 22:55:29 +03:00
|
|
|
|
//======================================
|
|
|
|
|
// === Argument parser configuration ===
|
|
|
|
|
//======================================
|
|
|
|
|
|
|
|
|
|
/** CLI argument parser (with support for environment variables) that provides
|
|
|
|
|
* the necessary options. */
|
2023-03-03 01:00:47 +03:00
|
|
|
|
export const args: Arguments = await yargs(process.argv.slice(2))
|
2022-08-23 01:49:23 +03:00
|
|
|
|
.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',
|
2023-03-15 06:42:14 +03:00
|
|
|
|
default: electronBuilder.Platform.current().toString(),
|
|
|
|
|
coerce: (p: string) => electronBuilder.Platform.fromString(p),
|
2022-08-23 01:49:23 +03:00
|
|
|
|
},
|
2022-12-21 04:14:54 +03:00
|
|
|
|
target: {
|
2022-08-23 01:49:23 +03:00
|
|
|
|
type: 'string',
|
|
|
|
|
description: 'Overwrite the platform-default target',
|
|
|
|
|
},
|
|
|
|
|
}).argv
|
2020-03-16 05:58:00 +03:00
|
|
|
|
|
2023-05-19 22:55:29 +03:00
|
|
|
|
// ======================================
|
|
|
|
|
// === Electron builder configuration ===
|
|
|
|
|
// ======================================
|
|
|
|
|
|
2024-05-07 19:22:11 +03:00
|
|
|
|
/** File associations for the IDE. */
|
|
|
|
|
export const EXTENDED_FILE_ASSOCIATIONS = [
|
|
|
|
|
{
|
|
|
|
|
ext: fileAssociations.SOURCE_FILE_EXTENSION,
|
|
|
|
|
name: `${common.PRODUCT_NAME} Source File`,
|
|
|
|
|
role: 'Editor',
|
|
|
|
|
// Note that MIME type is used on Windows by the enso-installer to register the file association.
|
|
|
|
|
// This behavior is unlike what electron-builder does.
|
|
|
|
|
mimeType: 'text/plain',
|
|
|
|
|
progId: 'Enso.Source',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
ext: fileAssociations.BUNDLED_PROJECT_EXTENSION,
|
|
|
|
|
name: `${common.PRODUCT_NAME} Project Bundle`,
|
|
|
|
|
role: 'Editor',
|
|
|
|
|
mimeType: 'application/gzip',
|
|
|
|
|
progId: 'Enso.ProjectBundle',
|
|
|
|
|
},
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
/** Returns non-extended file associations, as required by the `electron-builder`.
|
|
|
|
|
*
|
|
|
|
|
* Note that we need to actually remove any additional fields that we added to the file associations,
|
|
|
|
|
* as the `electron-builder` will error out if it encounters unknown fields. */
|
|
|
|
|
function getFileAssociations(): electronBuilder.FileAssociation[] {
|
|
|
|
|
return EXTENDED_FILE_ASSOCIATIONS.map(assoc => {
|
|
|
|
|
const { ext, name, role, mimeType } = assoc
|
|
|
|
|
return { ext, name, role, mimeType }
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Returns additional configuration for the `enso-installer`. */
|
|
|
|
|
function getInstallerAdditionalConfig(): InstallerAdditionalConfig {
|
|
|
|
|
return {
|
|
|
|
|
publisher: common.COMPANY_NAME,
|
|
|
|
|
fileAssociations: EXTENDED_FILE_ASSOCIATIONS,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-03 01:00:47 +03:00
|
|
|
|
/** Based on the given arguments, creates a configuration for the Electron Builder. */
|
2023-03-15 06:42:14 +03:00
|
|
|
|
export function createElectronBuilderConfig(passedArgs: Arguments): electronBuilder.Configuration {
|
2023-11-16 22:07:29 +03:00
|
|
|
|
let version = BUILD_INFO.version
|
2024-05-07 19:22:11 +03:00
|
|
|
|
if (passedArgs.target === 'msi') {
|
2023-11-16 22:07:29 +03:00
|
|
|
|
// MSI installer imposes some restrictions on the version number. Namely, product version must have a major
|
|
|
|
|
// version less than 256, a minor version less than 256, and a build version less than 65536.
|
|
|
|
|
//
|
|
|
|
|
// As a workaround (we use year, like 2023, as a major version), we drop two leading digits from the major
|
|
|
|
|
// version number.
|
|
|
|
|
version = version.substring(2)
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-03 01:00:47 +03:00
|
|
|
|
return {
|
|
|
|
|
appId: 'org.enso',
|
2023-03-20 12:35:16 +03:00
|
|
|
|
productName: common.PRODUCT_NAME,
|
2023-03-03 01:00:47 +03:00
|
|
|
|
extraMetadata: {
|
2023-11-16 22:07:29 +03:00
|
|
|
|
version,
|
2024-05-07 19:22:11 +03:00
|
|
|
|
// This provides extra data for the installer.
|
|
|
|
|
installer: getInstallerAdditionalConfig(),
|
2023-03-03 01:00:47 +03:00
|
|
|
|
},
|
2023-10-03 21:07:20 +03:00
|
|
|
|
copyright: `Copyright © ${new Date().getFullYear()} ${common.COMPANY_NAME}`,
|
2023-11-16 22:07:29 +03:00
|
|
|
|
|
|
|
|
|
// Note that the `artifactName` uses the "canonical" version of the product, not one that might have been
|
|
|
|
|
// simplified for the MSI installer to cope.
|
2024-02-01 15:53:50 +03:00
|
|
|
|
artifactName: 'enso-${os}-${arch}-' + BUILD_INFO.version + '.${ext}',
|
2023-11-16 22:07:29 +03:00
|
|
|
|
|
2023-03-15 06:42:14 +03:00
|
|
|
|
/** Definitions of URL {@link electronBuilder.Protocol} schemes used by the IDE.
|
2023-03-09 18:02:28 +03:00
|
|
|
|
*
|
2023-05-19 22:55:29 +03:00
|
|
|
|
* Electron will register all URL protocol schemes defined here with the OS.
|
|
|
|
|
* Once a URL protocol scheme is registered with the OS, any links using that scheme
|
|
|
|
|
* will function as "deep links".
|
2023-03-09 18:02:28 +03:00
|
|
|
|
* Deep links are used to redirect the user from external sources (e.g., system web browser,
|
|
|
|
|
* email client) to the IDE.
|
|
|
|
|
*
|
|
|
|
|
* Clicking a deep link will:
|
|
|
|
|
* - open the IDE (if it is not already open),
|
|
|
|
|
* - focus the IDE, and
|
|
|
|
|
* - navigate to the location specified by the URL of the deep link.
|
|
|
|
|
*
|
|
|
|
|
* For details on how this works, see:
|
2023-03-15 06:42:14 +03:00
|
|
|
|
* https://www.electronjs.org/docs/latest/tutorial/launch-app-from-url-in-another-app. */
|
2023-03-09 18:02:28 +03:00
|
|
|
|
protocols: [
|
2023-05-19 22:55:29 +03:00
|
|
|
|
/** Electron URL protocol scheme definition for deep links to authentication pages. */
|
2023-03-09 18:02:28 +03:00
|
|
|
|
{
|
2023-03-20 12:35:16 +03:00
|
|
|
|
name: `${common.PRODUCT_NAME} url`,
|
2023-03-15 14:54:16 +03:00
|
|
|
|
schemes: [common.DEEP_LINK_SCHEME],
|
2023-03-09 18:02:28 +03:00
|
|
|
|
role: 'Editor',
|
|
|
|
|
},
|
|
|
|
|
],
|
2023-03-03 01:00:47 +03:00
|
|
|
|
mac: {
|
2023-05-19 22:55:29 +03:00
|
|
|
|
// Compression is not used as the build time is huge and file size saving
|
|
|
|
|
// almost zero.
|
2023-03-20 12:35:16 +03:00
|
|
|
|
// This type assertion is UNSAFE, and any users MUST verify that
|
|
|
|
|
// they are passing a valid value to `target`.
|
|
|
|
|
// eslint-disable-next-line no-restricted-syntax
|
2023-03-15 06:42:14 +03:00
|
|
|
|
target: (passedArgs.target ?? 'dmg') as macOptions.MacOsTargetName,
|
|
|
|
|
icon: `${passedArgs.iconsDist}/icon.icns`,
|
2023-03-03 01:00:47 +03:00
|
|
|
|
category: 'public.app-category.developer-tools',
|
|
|
|
|
darkModeSupport: true,
|
|
|
|
|
type: 'distribution',
|
|
|
|
|
// 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,
|
2023-05-19 22:55:29 +03:00
|
|
|
|
// Location of the entitlements files with the entitlements we need to run
|
|
|
|
|
// our application in the hardened runtime.
|
2023-03-03 01:00:47 +03:00
|
|
|
|
entitlements: './entitlements.mac.plist',
|
|
|
|
|
entitlementsInherit: './entitlements.mac.plist',
|
|
|
|
|
},
|
|
|
|
|
win: {
|
2023-05-19 22:55:29 +03:00
|
|
|
|
// Compression is not used as the build time is huge and file size saving
|
|
|
|
|
// almost zero.
|
2024-05-07 19:22:11 +03:00
|
|
|
|
target: passedArgs.target ?? 'dir',
|
2023-03-15 06:42:14 +03:00
|
|
|
|
icon: `${passedArgs.iconsDist}/icon.ico`,
|
2023-03-03 01:00:47 +03:00
|
|
|
|
},
|
|
|
|
|
linux: {
|
2023-05-19 22:55:29 +03:00
|
|
|
|
// Compression is not used as the build time is huge and file size saving
|
|
|
|
|
// is almost zero.
|
2023-03-15 06:42:14 +03:00
|
|
|
|
target: passedArgs.target ?? 'AppImage',
|
|
|
|
|
icon: `${passedArgs.iconsDist}/png`,
|
2023-03-03 01:00:47 +03:00
|
|
|
|
category: 'Development',
|
2022-05-23 05:16:04 +03:00
|
|
|
|
},
|
2023-03-03 01:00:47 +03:00
|
|
|
|
files: [
|
|
|
|
|
'!**/node_modules/**/*',
|
2023-03-15 06:42:14 +03:00
|
|
|
|
{ from: `${passedArgs.guiDist}/`, to: '.' },
|
|
|
|
|
{ from: `${passedArgs.ideDist}/client`, to: '.' },
|
2023-03-03 01:00:47 +03:00
|
|
|
|
],
|
|
|
|
|
extraResources: [
|
|
|
|
|
{
|
2023-03-15 06:42:14 +03:00
|
|
|
|
from: `${passedArgs.projectManagerDist}/`,
|
|
|
|
|
to: paths.PROJECT_MANAGER_BUNDLE,
|
2023-03-03 01:00:47 +03:00
|
|
|
|
filter: ['!**.tar.gz', '!**.zip'],
|
|
|
|
|
},
|
|
|
|
|
],
|
2024-05-07 19:22:11 +03:00
|
|
|
|
fileAssociations: getFileAssociations(),
|
2023-03-03 01:00:47 +03:00
|
|
|
|
directories: {
|
2023-03-15 06:42:14 +03:00
|
|
|
|
output: `${passedArgs.ideDist}`,
|
2021-11-05 14:51:43 +03:00
|
|
|
|
},
|
2023-11-16 22:07:29 +03:00
|
|
|
|
msi: {
|
|
|
|
|
runAfterFinish: false,
|
|
|
|
|
},
|
2023-03-03 01:00:47 +03:00
|
|
|
|
nsis: {
|
|
|
|
|
// Disables "block map" generation during electron building. Block maps
|
|
|
|
|
// 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
|
|
|
|
|
// are handled by us. More info:
|
|
|
|
|
// https://github.com/electron-userland/electron-builder/issues/2851
|
|
|
|
|
// https://github.com/electron-userland/electron-builder/issues/2900
|
|
|
|
|
differentialPackage: false,
|
2023-07-02 13:33:27 +03:00
|
|
|
|
runAfterFinish: false,
|
2023-03-03 01:00:47 +03:00
|
|
|
|
},
|
|
|
|
|
dmg: {
|
|
|
|
|
// Disables "block map" generation during electron building. Block maps
|
|
|
|
|
// 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
|
|
|
|
|
// are handled by us. More info:
|
|
|
|
|
// https://github.com/electron-userland/electron-builder/issues/2851
|
|
|
|
|
// https://github.com/electron-userland/electron-builder/issues/2900
|
|
|
|
|
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/
|
|
|
|
|
sign: false,
|
|
|
|
|
},
|
2023-09-22 06:43:25 +03:00
|
|
|
|
afterAllArtifactBuild: computeHashes,
|
2024-05-07 19:22:11 +03:00
|
|
|
|
afterPack: (context: electronBuilder.AfterPackContext) => {
|
2023-03-15 06:42:14 +03:00
|
|
|
|
if (passedArgs.platform === electronBuilder.Platform.MAC) {
|
2023-03-03 01:00:47 +03:00
|
|
|
|
// Make the subtree writable, so we can sign the binaries.
|
|
|
|
|
// This is needed because GraalVM distribution comes with read-only binaries.
|
2024-05-07 19:22:11 +03:00
|
|
|
|
childProcess.execFileSync('chmod', ['-R', 'u+w', context.appOutDir])
|
2023-03-03 01:00:47 +03:00
|
|
|
|
}
|
|
|
|
|
},
|
2022-09-19 22:02:18 +03:00
|
|
|
|
|
2024-05-07 19:22:11 +03:00
|
|
|
|
afterSign: async (context: electronBuilder.AfterPackContext) => {
|
2023-03-03 01:00:47 +03:00
|
|
|
|
// Notarization for macOS.
|
2023-06-19 02:02:08 +03:00
|
|
|
|
if (
|
|
|
|
|
passedArgs.platform === electronBuilder.Platform.MAC &&
|
|
|
|
|
process.env.CSC_LINK != null
|
|
|
|
|
) {
|
2023-03-15 06:42:14 +03:00
|
|
|
|
const {
|
|
|
|
|
packager: {
|
|
|
|
|
appInfo: { productFilename: appName },
|
|
|
|
|
config: { mac: macConfig },
|
|
|
|
|
},
|
|
|
|
|
appOutDir,
|
|
|
|
|
} = context
|
2022-09-19 22:02:18 +03:00
|
|
|
|
|
2023-03-03 01:00:47 +03:00
|
|
|
|
// We need to manually re-sign our build artifacts before notarization.
|
|
|
|
|
console.log(' • Performing additional signing of dependencies.')
|
|
|
|
|
await signArchivesMacOs({
|
|
|
|
|
appOutDir: appOutDir,
|
|
|
|
|
productFilename: appName,
|
2023-03-15 06:42:14 +03:00
|
|
|
|
// This will always be defined since we have an `entitlements.mac.plist`.
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
|
|
|
entitlements: macConfig!.entitlements!,
|
2023-03-03 01:00:47 +03:00
|
|
|
|
identity: 'Developer ID Application: New Byte Order Sp. z o. o. (NM77WTZJFQ)',
|
|
|
|
|
})
|
2022-09-19 22:02:18 +03:00
|
|
|
|
|
2023-03-03 01:00:47 +03:00
|
|
|
|
console.log(' • Notarizing.')
|
2023-11-01 22:58:28 +03:00
|
|
|
|
|
2023-03-15 06:42:14 +03:00
|
|
|
|
await electronNotarize.notarize({
|
2023-11-01 22:58:28 +03:00
|
|
|
|
tool: 'notarytool',
|
2023-03-03 01:00:47 +03:00
|
|
|
|
appPath: `${appOutDir}/${appName}.app`,
|
2023-08-25 10:33:31 +03:00
|
|
|
|
// It is a mistake for either of these to be undefined.
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
|
|
|
appleId: process.env.APPLEID!,
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
|
|
|
appleIdPassword: process.env.APPLEIDPASS!,
|
2023-11-01 22:58:28 +03:00
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
|
|
|
teamId: process.env.APPLETEAMID!,
|
2023-03-03 01:00:47 +03:00
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
},
|
2022-08-23 01:49:23 +03:00
|
|
|
|
|
2023-03-03 01:00:47 +03:00
|
|
|
|
publish: null,
|
|
|
|
|
}
|
2020-03-16 05:58:00 +03:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-07 19:22:11 +03:00
|
|
|
|
/** Write the configuration to a JSON file.
|
|
|
|
|
*
|
|
|
|
|
* On Windows it is necessary to provide configuration to our installer. On other platforms, this may be useful for debugging.
|
|
|
|
|
*
|
|
|
|
|
* The configuration will be extended with additional information needed by the `enso-installer`.
|
|
|
|
|
*/
|
|
|
|
|
async function dumpConfiguration(configPath: string, config: electronBuilder.Configuration) {
|
|
|
|
|
const jsonConfig = JSON.stringify(config)
|
|
|
|
|
await fs.writeFile(configPath, jsonConfig)
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-03 01:00:47 +03:00
|
|
|
|
/** Build the IDE package with Electron Builder. */
|
2023-03-15 06:42:14 +03:00
|
|
|
|
export async function buildPackage(passedArgs: Arguments) {
|
2023-05-19 22:55:29 +03:00
|
|
|
|
// `electron-builder` checks for presence of `node_modules` directory. If it is not present, it
|
|
|
|
|
// will install dependencies with the`--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.
|
2023-03-03 01:00:47 +03:00
|
|
|
|
//
|
2023-05-19 22:55:29 +03:00
|
|
|
|
// Without this workaround, `electron-builder` will end up erasing its own dependencies and
|
|
|
|
|
// failing because of that.
|
2023-03-03 01:00:47 +03:00
|
|
|
|
await fs.mkdir('node_modules', { recursive: true })
|
2022-08-23 01:49:23 +03:00
|
|
|
|
|
2024-05-07 19:22:11 +03:00
|
|
|
|
const config = createElectronBuilderConfig(passedArgs)
|
2023-03-15 06:42:14 +03:00
|
|
|
|
const cliOpts: electronBuilder.CliOptions = {
|
2024-05-07 19:22:11 +03:00
|
|
|
|
config,
|
2023-03-15 06:42:14 +03:00
|
|
|
|
targets: passedArgs.platform.createTarget(),
|
2023-03-03 01:00:47 +03:00
|
|
|
|
}
|
2024-05-07 19:22:11 +03:00
|
|
|
|
|
|
|
|
|
// If `ENSO_BUILD_ELECTRON_BUILDER_CONFIG` is set, we will write the configuration to the
|
|
|
|
|
// specified path. Otherwise, we will write it to the default path.
|
|
|
|
|
// This is used on Windows to provide the configuration to the installer build. On other
|
|
|
|
|
// platforms, this may be useful for debugging.
|
|
|
|
|
const configPath =
|
|
|
|
|
process.env['ENSO_BUILD_ELECTRON_BUILDER_CONFIG'] ??
|
|
|
|
|
`${passedArgs.ideDist}/electron-builder-config.yaml`
|
|
|
|
|
console.log(`Writing configuration to ${configPath}`)
|
|
|
|
|
await dumpConfiguration(configPath, config)
|
|
|
|
|
|
2023-03-15 06:42:14 +03:00
|
|
|
|
console.log('Building with configuration:', cliOpts)
|
|
|
|
|
const result = await electronBuilder.build(cliOpts)
|
2023-03-03 01:00:47 +03:00
|
|
|
|
console.log('Electron Builder is done. Result:', result)
|
2023-03-31 17:19:07 +03:00
|
|
|
|
// FIXME: https://github.com/enso-org/enso/issues/6082
|
2023-05-19 22:55:29 +03:00
|
|
|
|
// This is a workaround which fixes esbuild hanging after successfully finishing
|
|
|
|
|
// `electronBuilder.build`. It is safe to `exit(0)` since all processes are finished.
|
2023-03-31 17:19:07 +03:00
|
|
|
|
process.exit(0)
|
2022-08-23 01:49:23 +03:00
|
|
|
|
}
|