2016-02-01 02:33:33 +00:00
|
|
|
/// <reference path="typings/main.d.ts" />
|
2015-10-25 21:45:49 +00:00
|
|
|
var through = require("through2");
|
|
|
|
var path = require("path");
|
2016-02-01 02:33:33 +00:00
|
|
|
var beautylog = require("beautylog");
|
2015-09-17 20:58:19 +00:00
|
|
|
|
2015-10-26 15:18:37 +00:00
|
|
|
|
2015-11-30 08:49:52 +00:00
|
|
|
module.exports = function (functionsToExecuteArg:any|any[],executionModeArg:string = 'forEach', logBoolArg = false) {
|
|
|
|
//important vars
|
2016-02-01 02:33:33 +00:00
|
|
|
var gulpFunction = {
|
2015-11-30 08:49:52 +00:00
|
|
|
executionMode: executionModeArg, //can be forEach or atEnd
|
|
|
|
functionsToExecute: functionsToExecuteArg,
|
|
|
|
logBool: logBoolArg
|
|
|
|
};
|
|
|
|
|
|
|
|
var runFunctionNames = function () {
|
2016-02-01 02:33:33 +00:00
|
|
|
if (typeof gulpFunction.functionsToExecute == "function" ) {
|
|
|
|
gulpFunction.functionsToExecute();
|
|
|
|
} else if (Array.isArray(gulpFunction.functionsToExecute)) {
|
|
|
|
for (var anyFunction in gulpFunction.functionsToExecute) {
|
2015-11-30 08:49:52 +00:00
|
|
|
anyFunction();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
beautylog.error('gulp-callfunction: something is strange with the given arguments');
|
2015-10-25 21:45:49 +00:00
|
|
|
}
|
2015-11-30 08:49:52 +00:00
|
|
|
};
|
2015-09-17 20:58:19 +00:00
|
|
|
|
|
|
|
|
2015-11-30 08:49:52 +00:00
|
|
|
var forEach = function (file, enc, cb) {
|
2016-02-01 02:33:33 +00:00
|
|
|
if (gulpFunction.logBool) beautylog.log(gulpFunction.executionMode);
|
|
|
|
if (gulpFunction.executionMode === 'forEach') {
|
|
|
|
if(gulpFunction.logBool) beautylog.log('is forEach');
|
2015-11-30 08:49:52 +00:00
|
|
|
runFunctionNames();
|
|
|
|
}
|
|
|
|
//tell gulp that we are complete
|
|
|
|
return cb(null, file);
|
|
|
|
};
|
2015-10-25 21:45:49 +00:00
|
|
|
|
2015-11-30 08:49:52 +00:00
|
|
|
var atEnd = function(cb) {
|
2016-02-01 02:33:33 +00:00
|
|
|
if (gulpFunction.executionMode == "atEnd") {
|
2015-11-30 08:49:52 +00:00
|
|
|
runFunctionNames();
|
|
|
|
}
|
|
|
|
cb();
|
|
|
|
};
|
2015-10-25 21:45:49 +00:00
|
|
|
return through.obj(forEach,atEnd);
|
2015-09-17 20:58:19 +00:00
|
|
|
};
|