Skip to content

Commit 192c24c

Browse files
committed
Merge pull request #110 from LinusU/entry-name
Add optional name attribute to entries
2 parents 67fa3f8 + 1b88956 commit 192c24c

File tree

6 files changed

+36
-5
lines changed

6 files changed

+36
-5
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ the JSON file's path.
7575
+ `file` - Adds a file to the DMG
7676
+ `position` - Positions a present file
7777
+ `path` (string, required) - Path to the file
78+
+ `name` (string, optional) - Name of the file within the DMG
7879

7980
`0.1.x` used a different JSON format. This format is still supported but
8081
deprecated, please update your json.

lib/appdmg.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,8 @@ module.exports = exports = function (options) {
322322
}
323323

324324
async.each(global.links, function (entry, cb) {
325-
var title = path.basename(entry.path)
326-
var finalPath = path.join(global.temporaryMountPath, title)
325+
var name = entry.name || path.basename(entry.path)
326+
var finalPath = path.join(global.temporaryMountPath, name)
327327

328328
fs.symlink(entry.path, finalPath, cb)
329329
}, next)
@@ -339,8 +339,8 @@ module.exports = exports = function (options) {
339339
}
340340

341341
async.each(global.files, function (entry, cb) {
342-
var title = path.basename(entry.path)
343-
var finalPath = path.join(global.temporaryMountPath, title)
342+
var name = entry.name || path.basename(entry.path)
343+
var finalPath = path.join(global.temporaryMountPath, name)
344344

345345
util.sh('cp', ['-R', resolvePath(entry.path), finalPath], cb)
346346
}, next)
@@ -378,7 +378,7 @@ module.exports = exports = function (options) {
378378
}
379379

380380
global.opts.contents.forEach(function (e) {
381-
ds.setIconPos(path.basename(e.path), e.x, e.y)
381+
ds.setIconPos(e.name || path.basename(e.path), e.x, e.y)
382382
})
383383

384384
ds.write(path.join(global.temporaryMountPath, '.DS_Store'), function (err) {

schema.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@
8686
},
8787
"path": {
8888
"type": "string"
89+
},
90+
"name": {
91+
"type": "string"
8992
}
9093
},
9194
"required": [

test/accepted-3.png

69.4 KB
Loading

test/accepted-3@2x.png

209 KB
Loading

test/api.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,31 @@ describe('api', function () {
150150

151151
runAppdmg(opts, verify, done)
152152
})
153+
154+
it('creates an image with custom names', function (done) {
155+
this.timeout(60000) // 1 minute
156+
157+
var opts = {
158+
target: targetPath,
159+
basepath: path.join(__dirname, 'assets'),
160+
specification: {
161+
title: 'Test Title',
162+
icon: 'TestIcon.icns',
163+
background: 'TestBkg.png',
164+
contents: [
165+
{ x: 448, y: 344, type: 'link', path: '/Applications', name: 'System Apps' },
166+
{ x: 192, y: 344, type: 'file', path: 'TestApp.app', name: 'My Nice App.app' },
167+
{ x: 512, y: 128, type: 'file', path: 'TestDoc.txt', name: 'Documentation.txt' }
168+
]
169+
}
170+
}
171+
172+
var verify = {
173+
format: 'UDZO',
174+
title: 'Test Title',
175+
visually: 'accepted-3.png'
176+
}
177+
178+
runAppdmg(opts, verify, done)
179+
})
153180
})

0 commit comments

Comments
 (0)