Skip to content

Commit e872086

Browse files
zorgiepooLinusU
andauthored
🎉 Add support for creating APFS disk images (#221)
Co-authored-by: Linus Unnebäck <linus@folkdatorn.se>
1 parent bf121ca commit e872086

4 files changed

Lines changed: 26 additions & 11 deletions

File tree

‎README.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ the JSON file's path.
6868
- `UDBZ` - UDIF bzip2-compressed image (OS X 10.4+ only)
6969
- `ULFO` - UDIF lzfse-compressed image (OS X 10.11+ only)
7070
- `ULMO` - UDIF lzma-compressed image (macOS 10.15+ only)
71+
- `filesystem` (enum[string], optional) - Disk image filesystem
72+
- `HFS+`
73+
- `APFS` (macOS 10.13+ only)
7174
- `contents` (array[object], required) - This is the contents of your DMG.
7275
- `x` (number, required) - X position relative to icon center
7376
- `y` (number, required) - Y position relative to icon center

‎lib/appdmg.js‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ module.exports = exports = function (options) {
206206
**/
207207

208208
pipeline.addStep('Creating temporary image', function (next) {
209-
hdiutil.create(global.opts.title, `${global.megabytes}m`, function (err, temporaryImagePath) {
209+
hdiutil.create(global.opts.title, `${global.megabytes}m`, global.opts.filesystem, function (err, temporaryImagePath) {
210210
if (err) return next(err)
211211

212212
pipeline.addCleanupStep('unlink-temporary-image', 'Removing temporary image', function (next) {
@@ -396,15 +396,20 @@ module.exports = exports = function (options) {
396396
**/
397397

398398
pipeline.addStep('Blessing image', function (next) {
399-
const args = [
400-
'--folder', global.temporaryMountPath
401-
]
399+
// Blessing does not work for APFS disk images
400+
if (global.opts.filesystem != "APFS") {
401+
const args = [
402+
'--folder', global.temporaryMountPath
403+
]
404+
405+
if (os.arch() !== 'arm64') {
406+
args.push('--openfolder', global.temporaryMountPath)
407+
}
402408

403-
if (os.arch() !== 'arm64') {
404-
args.push('--openfolder', global.temporaryMountPath)
409+
util.sh('bless', args, next)
410+
} else {
411+
next.skip()
405412
}
406-
407-
util.sh('bless', args, next)
408413
})
409414

410415
/**

‎lib/hdiutil.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ exports.convert = function (source, format, target, cb) {
2222
})
2323
}
2424

25-
exports.create = function (volname, size, cb) {
25+
exports.create = function (volname, size, filesystem, cb) {
2626
temp.template('%s.dmg').writeFile('', function (err, outname) {
2727
if (err) return cb(err)
2828

2929
const args = [
3030
'create', outname,
3131
'-ov',
32-
'-fs', 'HFS+',
32+
'-fs', filesystem || 'HFS+',
3333
'-size', size,
3434
'-volname', volname
3535
]
@@ -53,7 +53,7 @@ exports.attach = function (path, cb) {
5353
util.sh('hdiutil', args, function (err, res) {
5454
if (err) return cb(err)
5555

56-
const m = /Apple_HFS\s+(.*)\s*$/.exec(res.stdout)
56+
const m = /\s+(\/Volumes\/.+)$/m.exec(res.stdout)
5757
if (m === null) return cb(new Error('Failed to mount image'))
5858

5959
cb(null, m[1])

‎schema.json‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@
6666
"UDBZ"
6767
]
6868
},
69+
"filesystem": {
70+
"type": "string",
71+
"enum": [
72+
"HFS+",
73+
"APFS"
74+
]
75+
},
6976
"contents": {
7077
"type": "array",
7178
"items": {

0 commit comments

Comments
 (0)