[6a3a178] | 1 | /*
|
---|
| 2 | MIT License http://www.opensource.org/licenses/mit-license.php
|
---|
| 3 | Author Tobias Koppers @sokra
|
---|
| 4 | */
|
---|
| 5 | "use strict";
|
---|
| 6 |
|
---|
| 7 | const Hook = require("./Hook");
|
---|
| 8 | const HookCodeFactory = require("./HookCodeFactory");
|
---|
| 9 |
|
---|
| 10 | class AsyncSeriesBailHookCodeFactory extends HookCodeFactory {
|
---|
| 11 | content({ onError, onResult, resultReturns, onDone }) {
|
---|
| 12 | return this.callTapsSeries({
|
---|
| 13 | onError: (i, err, next, doneBreak) => onError(err) + doneBreak(true),
|
---|
| 14 | onResult: (i, result, next) =>
|
---|
| 15 | `if(${result} !== undefined) {\n${onResult(
|
---|
| 16 | result
|
---|
| 17 | )}\n} else {\n${next()}}\n`,
|
---|
| 18 | resultReturns,
|
---|
| 19 | onDone
|
---|
| 20 | });
|
---|
| 21 | }
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | const factory = new AsyncSeriesBailHookCodeFactory();
|
---|
| 25 |
|
---|
| 26 | const COMPILE = function(options) {
|
---|
| 27 | factory.setup(this, options);
|
---|
| 28 | return factory.create(options);
|
---|
| 29 | };
|
---|
| 30 |
|
---|
| 31 | function AsyncSeriesBailHook(args = [], name = undefined) {
|
---|
| 32 | const hook = new Hook(args, name);
|
---|
| 33 | hook.constructor = AsyncSeriesBailHook;
|
---|
| 34 | hook.compile = COMPILE;
|
---|
| 35 | hook._call = undefined;
|
---|
| 36 | hook.call = undefined;
|
---|
| 37 | return hook;
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | AsyncSeriesBailHook.prototype = null;
|
---|
| 41 |
|
---|
| 42 | module.exports = AsyncSeriesBailHook;
|
---|