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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDBCQUF1QjtBQUV2QixxQ0FBb0M7QUFTcEMsSUFBSSxhQUFhLEdBQUcsQ0FDbEIscUJBQTRELEVBQzVELG1CQUFtQyxTQUFTLEVBQ2pDLEVBQUU7SUFFYixJQUFJLFlBQVksR0FBRyxFQUFFLENBQUE7SUFDckIsSUFBSSxXQUFXLEdBQUcsVUFBVSxXQUFXLEVBQUUsSUFBSSxFQUFFLEdBQUc7UUFDaEQsSUFBSSxXQUFXLEdBQUcsV0FBVyxDQUFDLElBQUksRUFBRSxHQUFHLENBQUMsQ0FBQTtRQUN4QyxFQUFFLENBQUMsQ0FBQyxPQUFPLFdBQVcsS0FBSyxXQUFXLElBQUksT0FBTyxXQUFXLENBQUMsSUFBSSxLQUFLLFdBQVcsQ0FBQyxDQUFDLENBQUM7WUFDbEYsWUFBWSxDQUFDLElBQUksQ0FBQyxXQUFXLENBQUMsQ0FBQTtRQUNoQyxDQUFDO0lBQ0gsQ0FBQyxDQUFBO0lBRUQsSUFBSSxtQkFBbUIsR0FBRyxVQUFVLElBQUksRUFBRSxHQUFHO1FBQzNDLEVBQUUsQ0FBQyxDQUFDLE9BQU8scUJBQXFCLEtBQUssVUFBVSxDQUFDLENBQUMsQ0FBQztZQUNoRCxXQUFXLENBQUMscUJBQXFCLEVBQUUsSUFBSSxFQUFFLEdBQUcsQ0FBQyxDQUFBO1FBQy9DLENBQUM7UUFBQyxJQUFJLENBQUMsRUFBRSxDQUFDLENBQUMsS0FBSyxDQUFDLE9BQU8sQ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