// The default parameter is a workaround for https://github.com/Tapppi/async-exit-hook/issues/9 exitHook((callback = () => {}) => { if (options.preview) { callback(); } else if (publishStatus === 'FAILED') { (async () => { await rollback(); callback(); })(); } else if (publishStatus === 'SUCCESS') { callback(); } else { console.log('\nAborted!'); callback(); } });
tasks.add([ { title: `Publishing package using ${pkgManagerName}`, skip: () => { if (options.preview) { const args = publish.getPackagePublishArguments(options); return `[Preview] Command not executed: ${pkgManager} ${args.join(' ')}.`; } }, task: (context, task) => { let hasError = false; return publish(context, pkgManager, task, options) .pipe( catchError(async error => { hasError = true; await rollback(); throw new Error(`Error publishing package:\n${error.message}\n\nThe project was rolled back to its previous state.`); }), finalize(() => { publishStatus = hasError ? 'FAILED' : 'SUCCESS'; }) ); } } ]);