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 pausing, aborting, and promisifying appdmg execution #184

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

argv-minus-one
Copy link

This PR adds some new methods and properties to the object returned by the appdmg function (that is, the pipeline object):


ee.waitFor(promise)

Pauses execution until the given Promise completes. If the promise rejects, then the appdmg run is aborted. This lets you do custom asynchronous work on the disk image while it's being built.

For example, suppose your disk image will contain a folder called “Super Secret Folder”, which you want to be hidden from the Finder. Here's how to do it, using the Xcode command-line tools:

const appdmg = require('appdmg');
const execa = require('execa');
const path = require('path');
const ee = appdmg({
  // appdmg options go here
});
async function hideSecretFolder () {
  // Use the SetFile program (it comes with Xcode) to hide `Super Secret Folder` from the Finder.
  await execa('SetFile', [
    '-a',
    'V',
    path.join(ee.temporaryMountPath, 'Super Secret Folder')
  ]);
}
ee.on('progress', info => {
  if (info.type === 'step-begin' && info.title === 'Unmounting temporary image') {
    ee.waitFor(hideSecretFolder());
    // appdmg will now wait, until hideSecretFolder() is finished, before unmounting the temporary image.
  }
})

ee.abort(err)

Abort the appdmg run with err as the reason. It must be a truthy value, preferably an Error.

ee.asPromise

A Promise that completes when appdmg is finished.

ee.temporaryImagePath

Path to the temporary disk image. This is a writable disk image that appdmg creates and mounts while it's working.

ee.temporaryMountPath

Path where the temporary disk image is currently mounted. This property is set when it's mounted, and deleted when it's unmounted.

Previously, if the appdmg pipeline errored out during one of the tests, the error was swallowed and the test simply timed out after 60 seconds. Now, the test fails with the actual error.
• Document Pipeline#hasErrored. Set it to true before emitting step error events, rather than after, so that event handlers know that appdmg has entered an error state.
• Make Pipeline#abort() do nothing if hasErrored is already true.
• When the pipeline is waiting on multiple promises, wait for all of them, even if some of them reject. That way, no one gets surprised by appdmg starting cleanup too soon.
• Don't throw rejections (just log them) from waitFor'd promises when hasErrored is already true. Prevents infinite loops.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant