Skip to content

Commit bc64791

Browse files
committed
fix: restore dmg.title support
Closes #834
1 parent 1fd9667 commit bc64791

File tree

4 files changed

+28
-12
lines changed

4 files changed

+28
-12
lines changed

docs/Options.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ macOS DMG specific options.
100100
| icon | <a name="DmgOptions-icon"></a>The path to DMG icon (volume icon), which will be shown when mounted. Defaults to application icon (`build/icon.icns`).
101101
| iconSize | <a name="DmgOptions-iconSize"></a>The size of all the icons inside the DMG. Defaults to 80.
102102
| iconTextSize | <a name="DmgOptions-iconTextSize"></a>The size of all the icon texts inside the DMG. Defaults to 12.
103+
| title | <a name="DmgOptions-title"></a><p>The title of the produced DMG, which will be shown when mounted (volume name). Defaults to <code>${productName} ${version}</code></p> <p>Macro <code>${productName}</code>, <code>${version}</code> and <code>${name}</code> are supported.</p>
103104
| contents | <a name="DmgOptions-contents"></a>The content — to customize icon locations.
104105
| format | <a name="DmgOptions-format"></a>The disk image format, one of `UDRW`, `UDRO`, `UDCO`, `UDZO`, `UDBZ`, `ULFO` (lzfse-compressed image (OS X 10.11+ only)). Defaults to `UDBZ` (bzip2-compressed image).
105106
| window | <a name="DmgOptions-window"></a>The DMG windows position and size. See [.build.dmg.window](#DmgWindow).

src/options/macOptions.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,13 @@ export interface DmgOptions {
9090
*/
9191
readonly iconTextSize?: number | null
9292

93+
/*
94+
The title of the produced DMG, which will be shown when mounted (volume name). Defaults to `${productName} ${version}`
95+
96+
Macro `${productName}`, `${version}` and `${name}` are supported.
97+
*/
98+
readonly title?: string | null
99+
93100
/*
94101
The content — to customize icon locations.
95102
*/

src/targets/dmg.ts

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import BluebirdPromise from "bluebird-lst-c"
77
import { debug, use, exec, statOrNull, isEmptyOrSpaces, spawn } from "../util/util"
88
import { copy, unlink, outputFile, remove } from "fs-extra-p"
99
import { executeFinally } from "../util/promise"
10+
import sanitizeFileName from "sanitize-filename"
1011

1112
export class DmgTarget extends Target {
1213
private helperDir = path.join(__dirname, "..", "..", "templates", "dmg")
@@ -41,7 +42,7 @@ export class DmgTarget extends Target {
4142
// allocate space for .DS_Store
4243
await outputFile(path.join(backgroundDir, "DSStorePlaceHolder"), new Buffer(preallocatedSize))
4344

44-
const volumeName = `${appInfo.productFilename} ${appInfo.version}`
45+
const volumeName = sanitizeFileName(this.computeVolumeName(specification.title))
4546
//noinspection SpellCheckingInspection
4647
await spawn("hdiutil", addVerboseIfNeed(["create",
4748
"-srcfolder", backgroundDir,
@@ -156,6 +157,18 @@ export class DmgTarget extends Target {
156157
this.packager.dispatchArtifactCreated(artifactPath, `${appInfo.name}-${appInfo.version}.dmg`)
157158
}
158159

160+
computeVolumeName(custom?: string | null): string {
161+
const appInfo = this.packager.appInfo
162+
if (custom == null) {
163+
return `${appInfo.productFilename} ${appInfo.version}`
164+
}
165+
166+
return custom
167+
.replace(/\$\{version}/g, appInfo.version)
168+
.replace(/\$\{name}/g, appInfo.name)
169+
.replace(/\$\{productName}/g, appInfo.productName)
170+
}
171+
159172
// public to test
160173
async computeDmgOptions(): Promise<DmgOptions> {
161174
const packager = this.packager
@@ -186,15 +199,6 @@ export class DmgTarget extends Target {
186199
warn("dmg.icon-size is deprecated, please use dmg.iconSize instead")
187200
}
188201

189-
if (specification.title != null) {
190-
if (specification.title === packager.appInfo.productName) {
191-
warn(`Do not specify unnecessary dmg.title ("${specification.title}") — application name ("${packager.appInfo.productFilename}") is used by default`)
192-
}
193-
else {
194-
warn("dmg.title is not supported, file issue if need")
195-
}
196-
}
197-
198202
if (!("icon" in specification)) {
199203
use(await packager.getIconPath(), it => {
200204
specification.icon = it
@@ -262,7 +266,10 @@ export async function attachAndExecute(dmgPath: string, readWrite: boolean, task
262266
if (readWrite) {
263267
args.push("-readwrite")
264268
}
265-
addVerboseIfNeed(args)
269+
270+
// otherwise hangs
271+
// addVerboseIfNeed(args)
272+
266273
args.push(dmgPath)
267274
const attachResult = await exec("hdiutil", args, {maxBuffer: 2 * 1024 * 1024})
268275
const deviceResult = attachResult == null ? null : /^(\/dev\/\w+)/.exec(attachResult)
@@ -275,7 +282,7 @@ export async function attachAndExecute(dmgPath: string, readWrite: boolean, task
275282
}
276283

277284
function addVerboseIfNeed(args: Array<string>): Array<string> {
278-
if (debug.enabled) {
285+
if (process.env.DEBUG_DMG === "true") {
279286
args.push("-verbose")
280287
}
281288
return args

test/src/macPackagerTest.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ test.ifOsx("no background", app({
144144
productName: "Test ß",
145145
dmg: {
146146
background: null,
147+
title: "Foo",
147148
},
148149
}
149150
}

0 commit comments

Comments
 (0)