Skip to content

Commit

Permalink
feat: Allow to specify custom build-version for electron-packager
Browse files Browse the repository at this point in the history
Closes #323
  • Loading branch information
develar committed Apr 16, 2016
1 parent 8266b22 commit c866084
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 7 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@
"bugs": "https://github.com/electron-userland/electron-builder/issues",
"homepage": "https://github.com/electron-userland/electron-builder",
"dependencies": {
"7zip-bin": "^0.0.3",
"bluebird": "^3.3.5",
"command-line-args": "^2.1.6",
"deep-assign": "^2.0.0",
"electron-packager-tf": "^6.0.3-beta.3",
"electron-winstaller-fixed": "^2.2.1-beta.0",
"fs-extra": "^0.27.0",
Expand All @@ -69,8 +71,7 @@
"progress-stream": "^1.2.0",
"read-package-json": "^2.0.3",
"source-map-support": "^0.4.0",
"tmp": "0.0.28",
"7zip-bin": "^0.0.3"
"tmp": "0.0.28"
},
"optionalDependencies": {
"appdmg": "^0.3.6"
Expand Down
2 changes: 1 addition & 1 deletion src/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export async function build(originalOptions?: BuildOptions): Promise<void> {
cscKeyPassword: process.env.CSC_KEY_PASSWORD,
githubToken: process.env.GH_TOKEN || process.env.GH_TEST_TOKEN,
}, originalOptions)

options.platform = normalizePlatforms(originalOptions.platform)

const lifecycleEvent = process.env.npm_lifecycle_event
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export { Packager } from "./packager"
export { PackagerOptions, ArtifactCreated } from "./platformPackager"
export { BuildOptions, build, createPublisher } from "./builder"
export { PublishOptions, Publisher } from "./gitHubPublisher"
export { AppMetadata, DevMetadata, Platform, getProductName, BuildMetadata, OsXBuildOptions, WinBuildOptions, LinuxBuildOptions } from "./metadata"
3 changes: 2 additions & 1 deletion src/macPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { log, spawn } from "./util"
import { createKeychain, deleteKeychain, CodeSigningInfo, generateKeychainName, sign } from "./codeSign"
import { stat } from "fs-extra-p"
import { path7za } from "7zip-bin"
import deepAssign = require("deep-assign")

//noinspection JSUnusedLocalSymbols
const __awaiter = require("./awaiter")
Expand Down Expand Up @@ -57,7 +58,7 @@ export default class MacPackager extends PlatformPackager<OsXBuildOptions> {
new BluebirdPromise<any>(async (resolve, reject) => {
log("Creating DMG")

const specification: appdmg.Specification = Object.assign({
const specification: appdmg.Specification = deepAssign({
title: this.appName,
icon: path.join(this.buildResourcesDir, "icon.icns"),
"icon-size": 80,
Expand Down
3 changes: 2 additions & 1 deletion src/packager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import MacPackager from "./macPackager"
import { WinPackager } from "./winPackager"
import * as errorMessages from "./errorMessages"
import * as util from "util"
import deepAssign = require("deep-assign")

//noinspection JSUnusedLocalSymbols
const __awaiter = require("./awaiter")
Expand Down Expand Up @@ -54,7 +55,7 @@ export class Packager implements BuildInfo {

const metadataList = await BluebirdPromise.map(Array.from(new Set([devPackageFile, appPackageFile])), readPackageJson)
this.metadata = metadataList[metadataList.length - 1]
this.devMetadata = metadataList[0]
this.devMetadata = deepAssign(metadataList[0], this.options.devMetadata)
this.checkMetadata(appPackageFile, devPackageFile, platforms)

this.electronVersion = await getElectronVersion(this.devMetadata, devPackageFile)
Expand Down
10 changes: 9 additions & 1 deletion src/platformPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import globby = require("globby")
import { copy } from "fs-extra-p"
import { statOrNull } from "./util"
import { Packager } from "./packager"
import deepAssign = require("deep-assign")

//noinspection JSUnusedLocalSymbols
const __awaiter = require("./awaiter")
Expand All @@ -34,6 +35,13 @@ export interface PackagerOptions {
cscKeyPassword?: string

platformPackagerFactory?: (packager: Packager, platform: Platform, cleanupTasks: Array<() => Promise<any>>) => PlatformPackager<any>

/**
* The same as [development package.json](https://github.com/electron-userland/electron-builder/wiki/Options#development-packagejson).
*
* Development `package.json` will be still read, but options specified in this object will override.
*/
readonly devMetadata?: DevMetadata
}

export interface BuildInfo extends ProjectMetadataProvider {
Expand Down Expand Up @@ -105,7 +113,7 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>

checkConflictingOptions(this.devMetadata.build)

const options = Object.assign({
const options = deepAssign({
dir: this.info.appDir,
out: outDir,
name: this.appName,
Expand Down
20 changes: 19 additions & 1 deletion test/src/winPackagerTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,34 @@ test.ifNotTravis("noMsi as string", t => t.throws(assertPack("test-app-one", pla
test("detect install-spinner", () => {
let platformPackager: CheckingWinPackager = null
let loadingGifPath: string = null

// todo all PackagerOptions should be optional otherwise it is not possible to pass only several to override dev package.json
const devMetadata: any = {
build: {
win: {
certificatePassword: "pass",
}
}
}
return assertPack("test-app-one", {
platform: [Platform.WINDOWS],
platformPackagerFactory: (packager, platform, cleanupTasks) => platformPackager = new CheckingWinPackager(packager, cleanupTasks),
devMetadata: devMetadata
}, {
tempDirCreated: it => {
loadingGifPath = path.join(it, "build", "install-spinner.gif")
return move(path.join(it, "install-spinner.gif"), loadingGifPath)
return BluebirdPromise.all([
move(path.join(it, "install-spinner.gif"), loadingGifPath),
modifyPackageJson(it, data => {
data.build.win = {
certificateFile: "secretFile",
certificatePassword: "mustBeOverridden",
}
})])
},
packed: () => {
assertThat(platformPackager.effectiveDistOptions.loadingGif).equal(loadingGifPath)
assertThat(platformPackager.effectiveDistOptions.certificateFile).equal("secretFile")
return BluebirdPromise.resolve(null)
},
})
Expand Down
1 change: 1 addition & 0 deletions test/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"files": [
"../typings/appdmg.d.ts",
"../typings/command-line-args.d.ts",
"../typings/deep-assign.d.ts",
"../typings/electron-packager.d.ts",
"../typings/gh-api.d.ts",
"../typings/globby.d.ts",
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"files": [
"typings/appdmg.d.ts",
"typings/command-line-args.d.ts",
"typings/deep-assign.d.ts",
"typings/electron-packager.d.ts",
"typings/gh-api.d.ts",
"typings/globby.d.ts",
Expand Down
5 changes: 5 additions & 0 deletions typings/deep-assign.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare module "deep-assign" {
function deepAssign<T, U>(target: T, source: U): T & U

export = deepAssign
}

0 comments on commit c866084

Please sign in to comment.