Skip to content

Commit

Permalink
feat: specify path to custom Electron build (Electron.app)
Browse files Browse the repository at this point in the history
Closes #760
  • Loading branch information
develar committed Sep 20, 2016
1 parent f0b38d9 commit 3132610
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 10 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ language: c
cache:
directories:
- node_modules
- nsis-auto-updater/node_modules
- $HOME/.electron

before_install:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# electron-builder [![npm version](https://img.shields.io/npm/v/electron-builder.svg)](https://npmjs.org/package/electron-builder) [![donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=W6V79R2RGCCHL)
A complete solution to package and build a ready for distribution Electron app for MacOS, Windows and Linux with "auto update" support out of the box.
A complete solution to package and build a ready for distribution Electron app for MacOS, Windows and Linux with auto update support out of the box.

* NPM packages management:
* [Native application dependencies](http://electron.atom.io/docs/latest/tutorial/using-native-node-modules/) compilation (only if the [two-package.json project structure](#two-packagejson-structure) is used).
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "electron-builder",
"description": "Complete solution to build ready for distribution and 'auto update' Electron App installers",
"description": "A complete solution to package and build a ready for distribution Electron app for MacOS, Windows and Linux with “auto update” support out of the box",
"version": "0.0.0-semantic-release",
"main": "out/index.js",
"files": [
Expand Down
5 changes: 5 additions & 0 deletions src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ export interface BuildMetadata {
*/
readonly nodeGypRebuild?: boolean

/**
The path to custom Electron build (e.g. `~/electron/out/R`). Only macOS supported, file issue if need for Linux or Windows.
*/
readonly electronDist?: string

readonly icon?: string | null

// deprecated
Expand Down
24 changes: 17 additions & 7 deletions src/packager/dirPackager.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { Promise as BluebirdPromise } from "bluebird"
import { emptyDir } from "fs-extra-p"
import { emptyDir, copy } from "fs-extra-p"
import { warn } from "../util/log"
import { PlatformPackager } from "../platformPackager"
import { debug7zArgs, spawn } from "../util/util"
import { path7za } from "7zip-bin"
import * as path from "path"

const downloadElectron: (options: any) => Promise<any> = BluebirdPromise.promisify(require("electron-download"))
const extract: any = BluebirdPromise.promisify(require("extract-zip"))

//noinspection JSUnusedLocalSymbols
const __awaiter = require("../util/awaiter")
Expand All @@ -29,11 +31,19 @@ function subOptionWarning (properties: any, optionName: any, parameter: any, val
}

export async function pack(packager: PlatformPackager<any>, out: string, platform: string, arch: string, electronVersion: string, initializeApp: () => Promise<any>) {
const zipPath = (await BluebirdPromise.all<any>([
downloadElectron(createDownloadOpts(packager.devMetadata.build, platform, arch, electronVersion)),
emptyDir(out)
]))[0]
await extract(zipPath, {dir: out})
const electronDist = packager.devMetadata.build.electronDist
if (electronDist == null) {
const zipPath = (await BluebirdPromise.all<any>([
downloadElectron(createDownloadOpts(packager.devMetadata.build, platform, arch, electronVersion)),
emptyDir(out)
]))[0]

await spawn(path7za, debug7zArgs("x").concat(zipPath, `-o${out}`))
}
else {
await emptyDir(out)
await copy(path.resolve(packager.info.projectDir, electronDist, "Electron.app"), path.join(out, "Electron.app"))
}

if (platform === "darwin" || platform === "mas") {
await(<any>require("./mac")).createApp(packager, out, initializeApp)
Expand Down
11 changes: 10 additions & 1 deletion test/src/macPackagerTest.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import test from "./helpers/avaEx"
import { assertPack, platform, modifyPackageJson, signed, app } from "./helpers/packTester"
import { assertPack, platform, modifyPackageJson, signed, app, appThrows } from "./helpers/packTester"
import OsXPackager from "out/macPackager"
import { move, writeFile, deleteFile, remove } from "fs-extra-p"
import * as path from "path"
Expand All @@ -11,6 +11,7 @@ import { SignOptions, FlatOptions } from "electron-osx-sign-tf"
import { Arch } from "out"
import { Target } from "out/platformPackager"
import { DmgTarget } from "out/targets/dmg"
import { DIR_TARGET } from "out/targets/targetFactory"

//noinspection JSUnusedLocalSymbols
const __awaiter = require("out/util/awaiter")
Expand Down Expand Up @@ -204,6 +205,14 @@ test.ifOsx("disable dmg icon, bundleVersion", () => {
})
})

test.ifOsx("electronDist", appThrows(/ENOENT: no such file or directory/, {
targets: Platform.OSX.createTarget(DIR_TARGET),
}, {
projectDirCreated: projectDir => modifyPackageJson(projectDir, data => {
data.build.electronDist = "foo"
})
}))

class CheckingMacPackager extends OsXPackager {
effectiveDistOptions: any
effectiveSignOptions: SignOptions
Expand Down

0 comments on commit 3132610

Please sign in to comment.