updated structure

This commit is contained in:
Philipp Kunz 2015-11-30 09:49:52 +01:00
parent e0c4a10411
commit e42c5004c2
2 changed files with 69 additions and 71 deletions

View File

@ -2,47 +2,47 @@
var through = require("through2"); var through = require("through2");
var path = require("path"); var path = require("path");
var beautylog = require("beautylog")("os"); var beautylog = require("beautylog")("os");
//important vars
var gulpCallFunction = {
executionMode: 'forEach',
functionsToExecute: undefined,
logBool: false
};
var runFunctionNames = function () {
if (typeof gulpCallFunction.functionsToExecute == "function") {
gulpCallFunction.functionsToExecute();
}
else if (Array.isArray(gulpCallFunction.functionsToExecute)) {
for (var anyFunction in gulpCallFunction.functionsToExecute) {
anyFunction();
}
}
else {
beautylog.error('gulp-callfunction: something is strange with the given arguments');
}
};
var forEach = function (file, enc, cb) {
if (gulpCallFunction.logBool)
beautylog.log(gulpCallFunction.executionMode);
if (gulpCallFunction.executionMode === 'forEach') {
if (gulpCallFunction.logBool)
beautylog.log('is forEach');
runFunctionNames();
}
//tell gulp that we are complete
return cb(null, file);
};
var atEnd = function (cb) {
if (gulpCallFunction.executionMode == "atEnd") {
runFunctionNames();
}
cb();
};
module.exports = function (functionsToExecute, executionMode, logBool) { module.exports = function (functionsToExecute, executionMode, logBool) {
if (executionMode === void 0) { executionMode = 'forEach'; } if (executionMode === void 0) { executionMode = 'forEach'; }
if (logBool === void 0) { logBool = false; } if (logBool === void 0) { logBool = false; }
//important vars
var gulpCallFunction = {
executionMode: 'forEach',
functionsToExecute: undefined,
logBool: false
};
gulpCallFunction.functionsToExecute = functionsToExecute; gulpCallFunction.functionsToExecute = functionsToExecute;
gulpCallFunction.executionMode = executionMode; gulpCallFunction.executionMode = executionMode;
gulpCallFunction.logBool = logBool; gulpCallFunction.logBool = logBool;
var runFunctionNames = function () {
if (typeof gulpCallFunction.functionsToExecute == "function") {
gulpCallFunction.functionsToExecute();
}
else if (Array.isArray(gulpCallFunction.functionsToExecute)) {
for (var anyFunction in gulpCallFunction.functionsToExecute) {
anyFunction();
}
}
else {
beautylog.error('gulp-callfunction: something is strange with the given arguments');
}
};
var forEach = function (file, enc, cb) {
if (gulpCallFunction.logBool)
beautylog.log(gulpCallFunction.executionMode);
if (gulpCallFunction.executionMode === 'forEach') {
if (gulpCallFunction.logBool)
beautylog.log('is forEach');
runFunctionNames();
}
//tell gulp that we are complete
return cb(null, file);
};
var atEnd = function (cb) {
if (gulpCallFunction.executionMode == "atEnd") {
runFunctionNames();
}
cb();
};
return through.obj(forEach, atEnd); return through.obj(forEach, atEnd);
}; };

View File

@ -3,45 +3,43 @@ var through = require("through2");
var path = require("path"); var path = require("path");
var beautylog = require("beautylog")("os"); var beautylog = require("beautylog")("os");
//important vars
var gulpCallFunction = {
executionMode: 'forEach', //can be forEach or atEnd
functionsToExecute: undefined,
logBool: false
};
var runFunctionNames = function () { module.exports = function (functionsToExecuteArg:any|any[],executionModeArg:string = 'forEach', logBoolArg = false) {
if (typeof gulpCallFunction.functionsToExecute == "function" ) { //important vars
gulpCallFunction.functionsToExecute(); var gulpCallFunction = {
} else if (Array.isArray(gulpCallFunction.functionsToExecute)) { executionMode: executionModeArg, //can be forEach or atEnd
for (var anyFunction in gulpCallFunction.functionsToExecute) { functionsToExecute: functionsToExecuteArg,
anyFunction(); logBool: logBoolArg
};
var runFunctionNames = function () {
if (typeof gulpCallFunction.functionsToExecute == "function" ) {
gulpCallFunction.functionsToExecute();
} else if (Array.isArray(gulpCallFunction.functionsToExecute)) {
for (var anyFunction in gulpCallFunction.functionsToExecute) {
anyFunction();
}
} else {
beautylog.error('gulp-callfunction: something is strange with the given arguments');
} }
} else { };
beautylog.error('gulp-callfunction: something is strange with the given arguments');
}
};
var forEach = function (file, enc, cb) { var forEach = function (file, enc, cb) {
if (gulpCallFunction.logBool) beautylog.log(gulpCallFunction.executionMode); if (gulpCallFunction.logBool) beautylog.log(gulpCallFunction.executionMode);
if (gulpCallFunction.executionMode === 'forEach') { if (gulpCallFunction.executionMode === 'forEach') {
if(gulpCallFunction.logBool) beautylog.log('is forEach'); if(gulpCallFunction.logBool) beautylog.log('is forEach');
runFunctionNames(); runFunctionNames();
} }
//tell gulp that we are complete //tell gulp that we are complete
return cb(null, file); return cb(null, file);
}; };
var atEnd = function(cb) { var atEnd = function(cb) {
if (gulpCallFunction.executionMode == "atEnd") { if (gulpCallFunction.executionMode == "atEnd") {
runFunctionNames(); runFunctionNames();
} }
cb(); cb();
}; };
module.exports = function (functionsToExecute:any|any[],executionMode:string = 'forEach', logBool = false) {
gulpCallFunction.functionsToExecute = functionsToExecute;
gulpCallFunction.executionMode = executionMode;
gulpCallFunction.logBool = logBool;
return through.obj(forEach,atEnd); return through.obj(forEach,atEnd);
}; };