Skip to content

Commit

Permalink
fix(dmg): pass -ov flag to overwrite existing dmg
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Feb 28, 2017
1 parent 3e2798f commit d854a2b
Show file tree
Hide file tree
Showing 14 changed files with 158 additions and 229 deletions.
1 change: 1 addition & 0 deletions .idea/dictionaries/develar.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ You can use [file macros](#file-macros) in the `from` and `to` fields as well.
| publish | <a name="Config-publish"></a>See [publish](https://github.com/electron-userland/electron-builder/wiki/Publishing-Artifacts#PublishConfiguration).
| forceCodeSigning | <a name="Config-forceCodeSigning"></a>Whether to fail if application will be not signed (to prevent unsigned app if code signing configuration is not correct).
| electronVersion | <a name="Config-electronVersion"></a>The version of electron you are packaging for. Defaults to version of `electron`, `electron-prebuilt` or `electron-prebuilt-compile` dependency.
| artifactName | <a name="Config-artifactName"></a><p>The [artifact file name pattern](https://github.com/electron-userland/electron-builder/wiki/Options#artifact-file-name-pattern). Defaults to <code>${productName}-${version}.${ext}</code> (some target can have another defaults, see corresponding options).</p> <p>Currently supported only for <code>pkg</code>, <code>dmg</code> and <code>nsis</code>.</p>
| artifactName | <a name="Config-artifactName"></a><p>The [artifact file name pattern](https://github.com/electron-userland/electron-builder/wiki/Options#artifact-file-name-pattern). Defaults to <code>${productName}-${version}.${ext}</code> (some target can have another defaults, see corresponding options).</p> <p>Currently supported only for <code>mas</code>, <code>pkg</code>, <code>dmg</code> and <code>nsis</code>.</p>

<a name="AppXOptions"></a>
### `appx`
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"ajv-keywords": "^2.0.1-beta.0",
"archiver": "^1.3.0",
"asar": "~0.13.0",
"aws-sdk": "^2.20.0",
"aws-sdk": "^2.22.0",
"bluebird-lst": "^1.0.1",
"chalk": "^1.1.3",
"chromium-pickle-js": "^0.2.0",
Expand Down Expand Up @@ -62,8 +62,7 @@
"yargs": "^6.6.0"
},
"devDependencies": {
"@develar/typescript-json-schema": "0.9.3",
"@types/electron": "^1.4.32",
"@types/electron": "^1.4.33",
"@types/ini": "^1.3.29",
"@types/jest": "^18.1.1",
"@types/js-yaml": "^3.5.29",
Expand All @@ -89,8 +88,9 @@
"path-sort": "^0.1.0",
"source-map-support": "^0.4.11",
"ts-babel": "^1.4.4",
"tslint": "^4.4.2",
"tslint": "^4.5.0",
"typescript": "^2.2.1",
"typescript-json-schema": "0.10.0",
"whitespace": "^2.1.0",
"xml2js": "^0.4.17"
},
Expand Down
26 changes: 17 additions & 9 deletions packages/electron-builder/src/macPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { exec } from "electron-builder-util"
import { deepAssign } from "electron-builder-util/out/deepAssign"
import { log, task, warn } from "electron-builder-util/out/log"
import { signAsync, SignOptions } from "electron-macos-sign"
import { ensureDir } from "fs-extra-p"
import * as path from "path"
import { AppInfo } from "./appInfo"
import { appleCertificatePrefixes, CodeSigningInfo, createKeychain, findIdentity } from "./codeSign"
Expand Down Expand Up @@ -41,7 +42,7 @@ export default class MacPackager extends PlatformPackager<MacOptions> {
if (iconPath != null && !iconPath.endsWith(".icns")) {
iconPath += ".icns"
}
return iconPath == null ? await this.getDefaultIcon("icns") : path.resolve(this.projectDir, iconPath)
return iconPath == null ? await this.getDefaultIcon("icns") : await this.getResource(iconPath)
}

createTargets(targets: Array<string>, mapper: (name: string, factory: (outDir: string) => Target) => void, cleanupTasks: Array<() => Promise<any>>): void {
Expand Down Expand Up @@ -77,8 +78,8 @@ export default class MacPackager extends PlatformPackager<MacOptions> {

if (!hasMas || targets.length > 1) {
const appPath = prepackaged == null ? path.join(this.computeAppOutDir(outDir, arch), `${this.appInfo.productFilename}.app`) : prepackaged
nonMasPromise = (prepackaged ? BluebirdPromise.resolve() : this.doPack(outDir, path.dirname(appPath), this.platform.nodeName, arch, this.platformSpecificBuildOptions))
.then(() => this.sign(appPath, null))
nonMasPromise = (prepackaged ? BluebirdPromise.resolve() : this.doPack(outDir, path.dirname(appPath), this.platform.nodeName, arch, this.platformSpecificBuildOptions, targets))
.then(() => this.sign(appPath, null, null))
.then(() => this.packageInDistributableFormat(appPath, Arch.x64, targets, postAsyncTasks))
}

Expand All @@ -88,25 +89,28 @@ export default class MacPackager extends PlatformPackager<MacOptions> {
continue
}

const appOutDir = prepackaged || path.join(outDir, targetName)
const masBuildOptions = deepAssign({}, this.platformSpecificBuildOptions, (<any>this.config).mas)
if (targetName === "mas-dev") {
deepAssign(masBuildOptions, (<any>this.config)[targetName])
masBuildOptions.type = "development"
}

const targetOutDir = path.join(outDir, targetName)
if (prepackaged == null) {
await this.doPack(outDir, appOutDir, "mas", arch, masBuildOptions)
await this.doPack(outDir, targetOutDir, "mas", arch, masBuildOptions, [target])
await this.sign(path.join(targetOutDir, `${this.appInfo.productFilename}.app`), targetOutDir, masBuildOptions)
}
else {
await this.sign(prepackaged, targetOutDir, masBuildOptions)
}
await this.sign(path.join(appOutDir, `${this.appInfo.productFilename}.app`), masBuildOptions)
}

if (nonMasPromise != null) {
await nonMasPromise
}
}

private async sign(appPath: string, masOptions: MasBuildOptions | null): Promise<void> {
private async sign(appPath: string, outDir: string | null, masOptions: MasBuildOptions | null): Promise<void> {
if (process.platform !== "darwin") {
warn("macOS application code signing is supported only on macOS, skipping.")
return
Expand Down Expand Up @@ -198,12 +202,13 @@ export default class MacPackager extends PlatformPackager<MacOptions> {
await task(`Signing app (identity: ${name})`, this.doSign(signOptions))

if (masOptions != null) {
const pkg = path.join(path.dirname(appPath), `${this.appInfo.productFilename}-${this.appInfo.version}.pkg`)
const certType = "3rd Party Mac Developer Installer"
const masInstallerIdentity = await findIdentity(certType, masOptions.identity, keychainName)
if (masInstallerIdentity == null) {
throw new Error(`Cannot find valid "${certType}" identity to sign MAS installer, please see https://github.com/electron-userland/electron-builder/wiki/Code-Signing`)
}

const pkg = path.join(outDir!, this.expandArtifactNamePattern(masOptions, "pkg"))
await this.doFlat(appPath, pkg, masInstallerIdentity, keychainName)
this.dispatchArtifactCreated(pkg, null, `${this.appInfo.name}-${this.appInfo.version}.pkg`)
}
Expand All @@ -216,9 +221,12 @@ export default class MacPackager extends PlatformPackager<MacOptions> {

//noinspection JSMethodCanBeStatic
protected async doFlat(appPath: string, outFile: string, identity: string, keychain: string | n): Promise<any> {
// productbuild doesn't created directory for out file
await ensureDir(path.dirname(outFile))

const args = prepareProductBuildArgs(identity, keychain)
args.push("--component", appPath, "/Applications")
args.push(outFile)
return exec("productbuild", args)
return await exec("productbuild", args)
}
}
5 changes: 3 additions & 2 deletions packages/electron-builder/src/metadata.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Arch, Platform, TargetSpecificOptions } from "electron-builder-core"
import { Arch, Platform, Target, TargetSpecificOptions } from "electron-builder-core"
import { Publish } from "electron-builder-http/out/publishOptions"
import { DebOptions, LinuxBuildOptions, SnapOptions } from "./options/linuxOptions"
import { DmgOptions, MacOptions, MasBuildOptions, PkgOptions } from "./options/macOptions"
Expand Down Expand Up @@ -221,7 +221,7 @@ export interface Config extends PlatformSpecificBuildOptions, TargetSpecificOpti
/**
The [artifact file name pattern](https://github.com/electron-userland/electron-builder/wiki/Options#artifact-file-name-pattern). Defaults to `${productName}-${version}.${ext}` (some target can have another defaults, see corresponding options).
Currently supported only for `pkg`, `dmg` and `nsis`.
Currently supported only for `mas`, `pkg`, `dmg` and `nsis`.
*/
readonly artifactName?: string | null
}
Expand All @@ -231,6 +231,7 @@ export interface AfterPackContext {
readonly packager: PlatformPackager<any>
readonly electronPlatformName: string
readonly arch: Arch
readonly targets: Array<Target>
}

export interface BeforeBuildContext {
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-builder/src/packager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class Packager implements BuildInfo {
readonly prepackaged?: string | null

//noinspection JSUnusedGlobalSymbols
constructor(readonly options: PackagerOptions, private readonly cancellationToken: CancellationToken) {
constructor(readonly options: PackagerOptions, readonly cancellationToken: CancellationToken) {
this.projectDir = options.projectDir == null ? process.cwd() : path.resolve(options.projectDir)

this.prepackaged = options.prepackaged == null ? null : path.resolve(this.projectDir, options.prepackaged)
Expand Down
3 changes: 3 additions & 0 deletions packages/electron-builder/src/packagerApi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Arch, Platform, Target } from "electron-builder-core"
import { CancellationToken } from "electron-builder-http/out/CancellationToken"
import { PublishConfiguration } from "electron-builder-http/out/publishOptions"
import { TmpDir } from "electron-builder-util/out/tmp"
import { AppInfo } from "./appInfo"
Expand Down Expand Up @@ -63,6 +64,8 @@ export interface BuildInfo {

readonly prepackaged?: string | null

readonly cancellationToken: CancellationToken

dispatchArtifactCreated(event: ArtifactCreated): void

afterPack(context: AfterPackContext): Promise<void>
Expand Down
40 changes: 27 additions & 13 deletions packages/electron-builder/src/platformPackager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import BluebirdPromise from "bluebird-lst"
import { Arch, getArchSuffix, Platform, Target, TargetSpecificOptions } from "electron-builder-core"
import { asArray, debug, isEmptyOrSpaces, use } from "electron-builder-util"
import { asArray, debug, isEmptyOrSpaces, Lazy, use } from "electron-builder-util"
import { deepAssign } from "electron-builder-util/out/deepAssign"
import { copyDir, statOrNull, unlinkIfExists } from "electron-builder-util/out/fs"
import { log, warn } from "electron-builder-util/out/log"
Expand All @@ -25,7 +25,19 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>

readonly platformSpecificBuildOptions: DC

readonly resourceList: Promise<Array<string>>
get resourceList(): Promise<Array<string>> {
return this._resourceList.value
}

private readonly _resourceList = new Lazy<Array<string>>(() => {
return readdir(this.buildResourcesDir)
.catch(e => {
if (e.code !== "ENOENT") {
throw e
}
return []
})
})

abstract get platform(): Platform

Expand All @@ -39,14 +51,6 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
this.projectDir = info.projectDir

this.buildResourcesDir = path.resolve(this.projectDir, this.relativeBuildResourcesDirname)

this.resourceList = readdir(this.buildResourcesDir)
.catch(e => {
if (e.code !== "ENOENT") {
throw e
}
return []
})
}

abstract get defaultTarget(): Array<string>
Expand Down Expand Up @@ -95,7 +99,7 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>

async pack(outDir: string, arch: Arch, targets: Array<Target>, postAsyncTasks: Array<Promise<any>>): Promise<any> {
const appOutDir = this.computeAppOutDir(outDir, arch)
await this.doPack(outDir, appOutDir, this.platform.nodeName, arch, this.platformSpecificBuildOptions)
await this.doPack(outDir, appOutDir, this.platform.nodeName, arch, this.platformSpecificBuildOptions, targets)
this.packageInDistributableFormat(appOutDir, arch, targets, postAsyncTasks)
}

Expand Down Expand Up @@ -135,7 +139,7 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
return matcher
}

protected async doPack(outDir: string, appOutDir: string, platformName: string, arch: Arch, platformSpecificBuildOptions: DC) {
protected async doPack(outDir: string, appOutDir: string, platformName: string, arch: Arch, platformSpecificBuildOptions: DC, targets: Array<Target>) {
if (this.info.prepackaged != null) {
return
}
Expand Down Expand Up @@ -218,11 +222,16 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
await copyFiles(extraResourceMatchers)
await copyFiles(extraFileMatchers)

if (this.info.cancellationToken.cancelled) {
return
}

await this.info.afterPack({
appOutDir: appOutDir,
packager: this,
electronPlatformName: platformName,
arch: arch,
targets: targets,
})
await this.sanityCheckPackage(appOutDir, asarOptions != null)
}
Expand Down Expand Up @@ -517,7 +526,12 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
}
}
}
else if (!isEmptyOrSpaces(custom)) {
else if (custom != null && !isEmptyOrSpaces(custom)) {
const resourceList = await this.resourceList
if (resourceList.includes(custom)) {
return path.join(this.buildResourcesDir, custom)
}

let p = path.resolve(this.buildResourcesDir, custom)
if (await statOrNull(p) == null) {
p = path.resolve(this.projectDir, custom)
Expand Down
32 changes: 25 additions & 7 deletions packages/electron-builder/src/publish/PublishManager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import BluebirdPromise from "bluebird-lst"
import { createHash } from "crypto"
import { Arch, Platform } from "electron-builder-core"
import { Arch, Platform, Target } from "electron-builder-core"
import { CancellationToken } from "electron-builder-http/out/CancellationToken"
import { GenericServerOptions, GithubOptions, githubUrl, PublishConfiguration, PublishProvider, S3Options, s3Url, UpdateInfo, VersionInfo } from "electron-builder-http/out/publishOptions"
import { asArray, debug, isEmptyOrSpaces } from "electron-builder-util"
Expand Down Expand Up @@ -60,11 +60,21 @@ export class PublishManager implements PublishContext {
}

packager.addAfterPackHandler(async event => {
if (this.cancellationToken.cancelled || !(event.electronPlatformName == "darwin" || event.packager.platform === Platform.WINDOWS)) {
const packager = event.packager
if (event.electronPlatformName === "darwin") {
if (!event.targets.some(it => it.name === "zip")) {
return
}
}
else if (packager.platform === Platform.WINDOWS) {
if (!event.targets.some(it => isSuitableWindowsTarget(it))) {
return
}
}
else {
return
}

const packager = event.packager
const publishConfigs = await getPublishConfigsForUpdateInfo(packager, await getPublishConfigs(packager, null))
if (publishConfigs == null || publishConfigs.length === 0) {
return
Expand All @@ -73,12 +83,12 @@ export class PublishManager implements PublishContext {
let publishConfig = publishConfigs[0]
if ((<GenericServerOptions>publishConfig).url != null) {
publishConfig = Object.assign({}, publishConfig, {
url: packager.expandMacro((<GenericServerOptions>publishConfig).url, packager.platform === Platform.WINDOWS ? null : Arch.x64)
url: packager.expandMacro((<GenericServerOptions>publishConfig).url, null)
})
}

if (packager.platform === Platform.WINDOWS) {
let publisherName = await (<WinPackager>packager).computedPublisherName.value
const publisherName = await (<WinPackager>packager).computedPublisherName.value
if (publisherName != null) {
publishConfig = Object.assign({publisherName: publisherName}, publishConfig)
}
Expand Down Expand Up @@ -123,7 +133,7 @@ export class PublishManager implements PublishContext {

if (target != null && eventFile != null && !this.cancellationToken.cancelled) {
if ((packager.platform === Platform.MAC && target.name === "zip") ||
(packager.platform === Platform.WINDOWS && (target.name === "nsis" || target.name.startsWith("nsis-")) && eventFile.endsWith(".exe"))) {
(packager.platform === Platform.WINDOWS && isSuitableWindowsTarget(target) && eventFile.endsWith(".exe"))) {
this.addTask(writeUpdateInfo(event, publishConfigs))
}
}
Expand Down Expand Up @@ -368,8 +378,12 @@ export async function getPublishConfigs(packager: PlatformPackager<any>, targetS
}
}

if (publishers == null) {
return []
}

debug(`Explicit publish provider: ${JSON.stringify(publishers, null, 2)}`)
return <Promise<Array<PublishConfiguration>>>BluebirdPromise.map(asArray(publishers), it => getResolvedPublishConfig(packager.info, typeof it === "string" ? {provider: it} : it))
return await <Promise<Array<PublishConfiguration>>>BluebirdPromise.map(asArray(publishers), it => getResolvedPublishConfig(packager.info, typeof it === "string" ? {provider: it} : it))
}

function sha256(file: string) {
Expand Down Expand Up @@ -397,4 +411,8 @@ function isPullRequest() {
}

return isSet(process.env.TRAVIS_PULL_REQUEST) || isSet(process.env.CI_PULL_REQUEST) || isSet(process.env.CI_PULL_REQUESTS)
}

function isSuitableWindowsTarget(target: Target) {
return target.name === "nsis" || target.name.startsWith("nsis-")
}
Loading

0 comments on commit d854a2b

Please sign in to comment.