Skip to content

Commit

Permalink
feat: Custom electronDist callback (#5527)
Browse files Browse the repository at this point in the history
* Enabling `electronDist` to be a function that returns the path to the electron dist. This is necessary for universal builds where an `electronDist` must be specified per-architecture. Updated documentation for the expected options (string path vs function)

* Allow absolute path, otherwise resolve from projectDir

Co-authored-by: Mike Maietta <[email protected]>
  • Loading branch information
mmaietta and Mike Maietta authored Jan 15, 2021
1 parent a6e86b5 commit 4f4e018
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
11 changes: 9 additions & 2 deletions packages/app-builder-lib/scheme.json
Original file line number Diff line number Diff line change
Expand Up @@ -5711,8 +5711,15 @@
"type": "boolean"
},
"electronDist": {
"description": "The path to custom Electron build (e.g. `~/electron/out/R`).",
"type": "string"
"description": "Returns the path to custom Electron build (e.g. `~/electron/out/R`). Zip files must follow the pattern `electron-v${version}-${platformName}-${arch}.zip`, otherwise it will be assumed to be an unpacked Electron app directory",
"anyOf": [
{
"typeof": "function"
},
{
"type": "string"
}
]
},
"electronDownload": {
"$ref": "#/definitions/ElectronDownloadOptions",
Expand Down
5 changes: 3 additions & 2 deletions packages/app-builder-lib/src/configuration.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Arch } from "builder-util"
import { BeforeBuildContext, Target } from "./core"
import { ElectronDownloadOptions } from "./electron/ElectronFramework"
import { PrepareApplicationStageDirectoryOptions } from "./Framework"
import { AppXOptions } from "./options/AppXOptions"
import { AppImageOptions, DebOptions, LinuxConfiguration, LinuxTargetSpecificOptions } from "./options/linuxOptions"
import { DmgOptions, MacConfiguration, MasConfiguration } from "./options/macOptions"
Expand Down Expand Up @@ -129,9 +130,9 @@ export interface Configuration extends PlatformSpecificBuildOptions {
readonly electronCompile?: boolean

/**
* The path to custom Electron build (e.g. `~/electron/out/R`).
* Returns the path to custom Electron build (e.g. `~/electron/out/R`). Zip files must follow the pattern `electron-v${version}-${platformName}-${arch}.zip`, otherwise it will be assumed to be an unpacked Electron app directory
*/
readonly electronDist?: string
readonly electronDist?: string | ((options: PrepareApplicationStageDirectoryOptions) => string)

/**
* The [electron-download](https://github.com/electron-userland/electron-download#usage) options.
Expand Down
19 changes: 10 additions & 9 deletions packages/app-builder-lib/src/electron/ElectronFramework.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,15 @@ export async function createElectronFrameworkSupport(configuration: Configuratio
}

async function unpack(prepareOptions: PrepareApplicationStageDirectoryOptions, options: ElectronDownloadOptions, distMacOsAppName: string) {
const packager = prepareOptions.packager
const out = prepareOptions.appOutDir
const { packager, appOutDir, platformName } = prepareOptions

let dist: string | null | undefined = packager.config.electronDist
const electronDist = packager.config.electronDist
let dist: string | undefined | null = (typeof electronDist === 'function') ? electronDist(prepareOptions) : electronDist
if (dist != null) {
const zipFile = `electron-v${options.version}-${prepareOptions.platformName}-${options.arch}.zip`
const resolvedDist = path.resolve(packager.projectDir, dist)
const zipFile = `electron-v${options.version}-${platformName}-${options.arch}.zip`
const resolvedDist = path.isAbsolute(dist) ? dist : path.resolve(packager.projectDir, dist)
if ((await statOrNull(path.join(resolvedDist, zipFile))) != null) {
log.debug({ resolvedDist, zipFile }, "Resolved electronDist")
options.cache = resolvedDist
dist = null
}
Expand All @@ -161,15 +162,15 @@ async function unpack(prepareOptions: PrepareApplicationStageDirectoryOptions, o
if (isSafeToUnpackElectronOnRemoteBuildServer(packager)) {
return
}

await executeAppBuilder(["unpack-electron", "--configuration", JSON.stringify([options]), "--output", out, "--distMacOsAppName", distMacOsAppName])
log.info({ zipPath: options.cache }, "Unpacking electron zip")
await executeAppBuilder(["unpack-electron", "--configuration", JSON.stringify([options]), "--output", appOutDir, "--distMacOsAppName", distMacOsAppName])
}
else {
isFullCleanup = true
const source = packager.getElectronSrcDir(dist)
const destination = packager.getElectronDestinationDir(out)
const destination = packager.getElectronDestinationDir(appOutDir)
log.info({source, destination}, "copying Electron")
await emptyDir(out)
await emptyDir(appOutDir)
await copyDir(source, destination, {
isUseHardLink: DO_NOT_USE_HARD_LINKS,
})
Expand Down

0 comments on commit 4f4e018

Please sign in to comment.