fix(core): update to latest gitzone standards

This commit is contained in:
2018-12-09 01:19:01 +01:00
parent a05253bdcd
commit 7d35f4c90b
10 changed files with 4149 additions and 1972 deletions

View File

@ -1,8 +1,8 @@
import * as q from "smartq";
import * as through2 from "through2";
import { Transform } from "stream";
import * as smartpromise from '@pushrocks/smartpromise';
import * as through2 from 'through2';
import { Transform } from 'stream';
export type TExecutionMode = "forEach" | "forFirst" | "atEnd";
export type TExecutionMode = 'forEach' | 'forFirst' | 'atEnd';
export interface IPromiseFunction {
(file?, enc?): PromiseLike<any>;
@ -10,30 +10,25 @@ export interface IPromiseFunction {
let defaultExport = (
functionsToExecuteArg: IPromiseFunction | IPromiseFunction[],
executionModeArg: TExecutionMode = "forEach"
executionModeArg: TExecutionMode = 'forEach'
): Transform => {
let promiseArray = [];
let runFunction = function(functionArg, file, enc) {
let returnValue = functionArg(file, enc);
if (
typeof returnValue !== "undefined" &&
typeof returnValue.then !== "undefined"
) {
if (typeof returnValue !== 'undefined' && typeof returnValue.then !== 'undefined') {
promiseArray.push(returnValue);
}
};
let checkAndRunFunction = function(file, enc) {
if (typeof functionsToExecuteArg === "function") {
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"
);
throw new Error('gulp-callfunction: something is strange with the given arguments');
}
return Promise.all(promiseArray);
};
@ -42,12 +37,12 @@ let defaultExport = (
let forEach = function(file, enc, cb) {
// the forEach function is called for every chunk
switch (executionModeArg) {
case "forEach":
case 'forEach':
checkAndRunFunction(file, enc).then(function() {
cb(null, file);
});
break;
case "forFirst":
case 'forFirst':
if (hasExecutedOnce) {
checkAndRunFunction(file, enc).then(function() {
cb(null, file);
@ -57,7 +52,7 @@ let defaultExport = (
}
hasExecutedOnce = true;
break;
case "atEnd":
case 'atEnd':
cb();
break;
default:
@ -66,7 +61,7 @@ let defaultExport = (
};
let atEnd = function(cb) {
if (executionModeArg === "atEnd") {
if (executionModeArg === 'atEnd') {
checkAndRunFunction(null, null).then(function() {
cb();
});
@ -78,15 +73,15 @@ let defaultExport = (
};
export let forEach = (funcArg: IPromiseFunction) => {
return defaultExport(funcArg, "forEach");
return defaultExport(funcArg, 'forEach');
};
export let forFirst = (funcArg: IPromiseFunction) => {
return defaultExport(funcArg, "forFirst");
return defaultExport(funcArg, 'forFirst');
};
export let atEnd = (funcArg: IPromiseFunction) => {
return defaultExport(funcArg, "atEnd");
return defaultExport(funcArg, 'atEnd');
};
export default defaultExport;