76 lines
5.5 KiB
JavaScript
76 lines
5.5 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
require("typings-global");
|
|
const through2 = require("through2");
|
|
let defaultExport = (functionsToExecuteArg, executionModeArg = 'forEach') => {
|
|
let promiseArray = [];
|
|
let runFunction = function (functionArg, file, enc) {
|
|
let returnValue = functionArg(file, enc);
|
|
if (typeof returnValue !== 'undefined' && typeof returnValue.then !== 'undefined') {
|
|
promiseArray.push(returnValue);
|
|
}
|
|
};
|
|
let checkAndRunFunction = function (file, enc) {
|
|
if (typeof functionsToExecuteArg === 'function') {
|
|
runFunction(functionsToExecuteArg, file, enc);
|
|
}
|
|
else if (Array.isArray(functionsToExecuteArg)) {
|
|
for (let anyFunction in functionsToExecuteArg) {
|
|
runFunction(functionsToExecuteArg[anyFunction], file, enc);
|
|
}
|
|
}
|
|
else {
|
|
throw new Error('gulp-callfunction: something is strange with the given arguments');
|
|
}
|
|
return Promise.all(promiseArray);
|
|
};
|
|
let hasExecutedOnce = false;
|
|
let forEach = function (file, enc, cb) {
|
|
switch (executionModeArg) {
|
|
case 'forEach':
|
|
checkAndRunFunction(file, enc).then(function () {
|
|
cb(null, file);
|
|
});
|
|
break;
|
|
case 'forFirst':
|
|
if (hasExecutedOnce) {
|
|
checkAndRunFunction(file, enc)
|
|
.then(function () {
|
|
cb(null, file);
|
|
});
|
|
}
|
|
else {
|
|
cb(null, file);
|
|
}
|
|
hasExecutedOnce = true;
|
|
break;
|
|
case 'atEnd':
|
|
cb();
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
};
|
|
let atEnd = function (cb) {
|
|
if (executionModeArg === 'atEnd') {
|
|
checkAndRunFunction(null, null).then(function () {
|
|
cb();
|
|
});
|
|
}
|
|
else {
|
|
cb();
|
|
}
|
|
};
|
|
return through2.obj(forEach, atEnd);
|
|
};
|
|
exports.forEach = (funcArg) => {
|
|
return defaultExport(funcArg, 'forEach');
|
|
};
|
|
exports.forFirst = (funcArg) => {
|
|
return defaultExport(funcArg, 'forFirst');
|
|
};
|
|
exports.atEnd = (funcArg) => {
|
|
return defaultExport(funcArg, 'atEnd');
|
|
};
|
|
exports.default = defaultExport;
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDBCQUF1QjtBQUV2QixxQ0FBb0M7QUFTcEMsSUFBSSxhQUFhLEdBQUcsQ0FDbEIscUJBQTRELEVBQzVELG1CQUFtQyxTQUFTO0lBRzVDLElBQUksWUFBWSxHQUFHLEVBQUUsQ0FBQTtJQUNyQixJQUFJLFdBQVcsR0FBRyxVQUFVLFdBQVcsRUFBRSxJQUFJLEVBQUUsR0FBRztRQUNoRCxJQUFJLFdBQVcsR0FBRyxXQUFXLENBQUMsSUFBSSxFQUFFLEdBQUcsQ0FBQyxDQUFBO1FBQ3hDLEVBQUUsQ0FBQyxDQUFDLE9BQU8sV0FBVyxLQUFLLFdBQVcsSUFBSSxPQUFPLFdBQVcsQ0FBQyxJQUFJLEtBQUssV0FBVyxDQUFDLENBQUMsQ0FBQztZQUNsRixZQUFZLENBQUMsSUFBSSxDQUFDLFdBQVcsQ0FBQyxDQUFBO1FBQ2hDLENBQUM7SUFDSCxDQUFDLENBQUE7SUFFRCxJQUFJLG1CQUFtQixHQUFHLFVBQVUsSUFBSSxFQUFFLEdBQUc7UUFDM0MsRUFBRSxDQUFDLENBQUMsT0FBTyxxQkFBcUIsS0FBSyxVQUFVLENBQUMsQ0FBQyxDQUFDO1lBQ2hELFdBQVcsQ0FBQyxxQkFBcUIsRUFBRSxJQUFJLEVBQUUsR0FBRyxDQUFDLENBQUE7UUFDL0MsQ0FBQztRQUFDLElBQUksQ0FBQyxFQUFFLENBQUMsQ0FBQyxLQUFLLENBQUMsT0FBTyxDQUFDLHF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