Skip to content

Commit

Permalink
fix(dmg): Multiple license files don't seem to work for dmg
Browse files Browse the repository at this point in the history
Close #1982
  • Loading branch information
develar committed Aug 23, 2017
1 parent a83724b commit 4a2c599
Show file tree
Hide file tree
Showing 33 changed files with 7,452 additions and 127 deletions.
4 changes: 4 additions & 0 deletions .idea/dictionaries/develar.xml

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

5 changes: 5 additions & 0 deletions .idea/electron-builder.iml

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"ajv-keywords": "^2.1.0",
"archiver": "^2.0.0",
"async-exit-hook": "^2.0.1",
"aws-sdk": "^2.101.0",
"aws-sdk": "^2.102.0",
"bluebird-lst": "^1.0.3",
"chalk": "^2.1.0",
"chromium-pickle-js": "^0.2.0",
Expand All @@ -46,6 +46,7 @@
"fcopy-pre-bundled": "0.3.4",
"fs-extra-p": "^4.4.0",
"hosted-git-info": "^2.5.0",
"iconv-lite": "^0.4.18",
"ini": "^1.3.4",
"is-ci": "^1.0.10",
"isbinaryfile": "^3.0.2",
Expand Down
3 changes: 2 additions & 1 deletion packages/electron-builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@
"dotenv": "^4.0.0",
"dotenv-expand": "^4.0.1",
"temp-file": "^2.0.2",
"ejs": "^2.5.7"
"ejs": "^2.5.7",
"iconv-lite": "^0.4.18"
},
"typings": "./out/index.d.ts",
"publishConfig": {
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-builder/src/macPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { DIR_TARGET, Platform, Target } from "./core"
import { MacOptions, MasBuildOptions } from "./options/macOptions"
import { Packager } from "./packager"
import { PlatformPackager } from "./platformPackager"
import { DmgTarget } from "./targets/dmg"
import { DmgTarget } from "./targets/dmg/dmg"
import { PkgTarget, prepareProductBuildArgs } from "./targets/pkg"
import { createCommonTarget, NoOpTarget } from "./targets/targetFactory"
import { AsyncTaskManager } from "./util/asyncTaskManager"
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-builder/src/options/macOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export interface DmgOptions extends TargetSpecificOptions {
/**
* The content — to customize icon locations.
*/
readonly contents?: Array<DmgContent>
contents?: Array<DmgContent>

/**
* The disk image format. `ULFO` (lzfse-compressed image (OS X 10.11+ only)).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import BluebirdPromise from "bluebird-lst"
import { Arch, debug, exec, isEmptyOrSpaces, log, spawn, warn } from "electron-builder-util"
import { copyFile, exists, statOrNull } from "electron-builder-util/out/fs"
import { executeFinally } from "electron-builder-util/out/promise"
import { outputFile, readFile, remove, unlink } from "fs-extra-p"
import * as path from "path"
import { deepAssign } from "read-config-file/out/deepAssign"
import sanitizeFileName from "sanitize-filename"
import { Target } from "../core"
import { DmgOptions, MacOptions } from "../options/macOptions"
import { PlatformPackager } from "../platformPackager"
import { DmgOptions, MacOptions } from "../../options/macOptions"
import { PlatformPackager } from "../../platformPackager"
import { addLicenseToDmg } from "./dmgLicense"
import { Target } from "../../core"
import { attachAndExecute, detach } from "./dmgUtil"
import { getTemplatePath, getVendorPath } from "../../util/pathManager"

export class DmgTarget extends Target {
readonly options: DmgOptions = this.packager.config.dmg || Object.create(null)

private helperDir = path.join(__dirname, "..", "..", "templates", "dmg")
private helperDir = getTemplatePath("dmg")

constructor(private readonly packager: PlatformPackager<MacOptions>, readonly outDir: string) {
super("dmg")
Expand All @@ -25,6 +26,9 @@ export class DmgTarget extends Target {
log("Building DMG")

const specification = await this.computeDmgOptions()
const volumeName = sanitizeFileName(this.computeVolumeName(specification.title))
const artifactName = packager.expandArtifactNamePattern(packager.config.dmg, "dmg")
const artifactPath = path.join(this.outDir, artifactName)

const tempDmg = await packager.getTempFile(".dmg")
const backgroundDir = path.join(await packager.getTempDir("dmg"), ".background")
Expand All @@ -44,7 +48,6 @@ export class DmgTarget extends Target {
// allocate space for .DS_Store
await outputFile(path.join(backgroundDir, "DSStorePlaceHolder"), new Buffer(preallocatedSize))

const volumeName = sanitizeFileName(this.computeVolumeName(specification.title))
//noinspection SpellCheckingInspection
await spawn("hdiutil", addVerboseIfNeed(["create",
"-srcfolder", backgroundDir,
Expand All @@ -65,18 +68,6 @@ export class DmgTarget extends Target {
specification.background == null ? remove(`${volumePath}/.background`) : unlink(`${volumePath}/.background/DSStorePlaceHolder`),
]

let contents = specification.contents
if (contents == null) {
contents = [
{
x: 130, y: 220
},
{
x: 410, y: 220, type: "link", path: "/Applications"
}
]
}

const window = specification.window!
const env: any = {
...process.env,
Expand Down Expand Up @@ -125,7 +116,7 @@ export class DmgTarget extends Target {
}

let entries = ""
for (const c of contents) {
for (const c of specification.contents!!) {
if (c.path != null && c.path.endsWith(".app") && c.type !== "link") {
warn(`Do not specify path for application: "${c.path}". Actual path to app will be used instead.`)
}
Expand All @@ -150,7 +141,7 @@ export class DmgTarget extends Target {
await BluebirdPromise.all<any>(promises)

await exec("/usr/bin/perl", [dmgPropertiesFile], {
cwd: path.join(__dirname, "..", "..", "vendor"),
cwd: getVendorPath(),
env
})

Expand All @@ -163,9 +154,6 @@ export class DmgTarget extends Target {
return
}

const artifactName = packager.expandArtifactNamePattern(packager.config.dmg, "dmg")
const artifactPath = path.join(this.outDir, artifactName)

// dmg file must not exist otherwise hdiutil failed (https://github.com/electron-userland/electron-builder/issues/1308#issuecomment-282847594), so, -ov must be specified
//noinspection SpellCheckingInspection
const args = ["convert", tempDmg, "-ov", "-format", specification.format!, "-o", artifactPath]
Expand Down Expand Up @@ -274,46 +262,20 @@ export class DmgTarget extends Target {
}
}

if (specification.contents == null) {
specification.contents = [
{
x: 130, y: 220
},
{
x: 410, y: 220, type: "link", path: "/Applications"
}
]
}
return specification
}
}

async function detach(name: string) {
try {
await exec("hdiutil", ["detach", name])
}
catch (e) {
await new BluebirdPromise((resolve, reject) => {
setTimeout(() => {
exec("hdiutil", ["detach", "-force", name])
.then(resolve)
.catch(reject)
}, 1000)
})
}
}

export async function attachAndExecute(dmgPath: string, readWrite: boolean, task: () => Promise<any>) {
//noinspection SpellCheckingInspection
const args = ["attach", "-noverify", "-noautoopen"]
if (readWrite) {
args.push("-readwrite")
}

// otherwise hangs
// addVerboseIfNeed(args)

args.push(dmgPath)
const attachResult = await exec("hdiutil", args, {maxBuffer: 2 * 1024 * 1024})
const deviceResult = attachResult == null ? null : /^(\/dev\/\w+)/.exec(attachResult)
const device = deviceResult == null || deviceResult.length !== 2 ? null : deviceResult[1]
if (device == null) {
throw new Error(`Cannot mount: ${attachResult}`)
}

return await executeFinally(task(), () => detach(device))
}

function addVerboseIfNeed(args: Array<string>): Array<string> {
if (process.env.DEBUG_DMG === "true") {
args.push("-verbose")
Expand Down
Loading

0 comments on commit 4a2c599

Please sign in to comment.