Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Custom electronDist callback #5527

Merged
merged 2 commits into from
Jan 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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