Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for creating APFS disk images #221

Merged
merged 9 commits into from
Feb 3, 2023
Merged
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ the JSON file's path.
- `UDBZ` - UDIF bzip2-compressed image (OS X 10.4+ only)
- `ULFO` - UDIF lzfse-compressed image (OS X 10.11+ only)
- `ULMO` - UDIF lzma-compressed image (macOS 10.15+ only)
- `filesystem` (enum[string], optional) - Disk image filesystem
- `HFS+`
- `APFS` (macOS 10.13+ only)
- `contents` (array[object], required) - This is the contents of your DMG.
- `x` (number, required) - X position relative to icon center
- `y` (number, required) - Y position relative to icon center
Expand Down
21 changes: 13 additions & 8 deletions lib/appdmg.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ module.exports = exports = function (options) {
**/

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

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

pipeline.addStep('Blessing image', function (next) {
const args = [
'--folder', global.temporaryMountPath
]
// Blessing does not work for APFS disk images
if (global.opts.filesystem != "APFS") {
const args = [
'--folder', global.temporaryMountPath
]

if (os.arch() !== 'arm64') {
args.push('--openfolder', global.temporaryMountPath)
}

if (os.arch() !== 'arm64') {
args.push('--openfolder', global.temporaryMountPath)
util.sh('bless', args, next)
} else {
next.skip()
}

util.sh('bless', args, next)
})

/**
Expand Down
6 changes: 3 additions & 3 deletions lib/hdiutil.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ exports.convert = function (source, format, target, cb) {
})
}

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

const args = [
'create', outname,
'-ov',
'-fs', 'HFS+',
'-fs', filesystem || 'HFS+',
'-size', size,
'-volname', volname
]
Expand All @@ -53,7 +53,7 @@ exports.attach = function (path, cb) {
util.sh('hdiutil', args, function (err, res) {
if (err) return cb(err)

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

cb(null, m[1])
Expand Down
7 changes: 7 additions & 0 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@
"UDBZ"
]
},
"filesystem": {
"type": "string",
"enum": [
"HFS+",
"APFS"
]
},
"contents": {
"type": "array",
"items": {
Expand Down