gulp-function/ts/index.ts

46 lines
1.5 KiB
TypeScript
Raw Normal View History

2015-09-17 20:58:19 +00:00
/// <reference path="typings/tsd.d.ts" />
2015-10-25 21:45:49 +00:00
var through = require("through2");
var path = require("path");
2015-11-24 12:49:02 +00:00
var beautylog = require("beautylog")("os");
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
var gulpCallFunction = {
executionMode: executionModeArg, //can be forEach or atEnd
functionsToExecute: functionsToExecuteArg,
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');
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) {
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);
};
2015-10-25 21:45:49 +00:00
2015-11-30 08:49:52 +00:00
var atEnd = function(cb) {
if (gulpCallFunction.executionMode == "atEnd") {
runFunctionNames();
}
cb();
};
2015-10-25 21:45:49 +00:00
return through.obj(forEach,atEnd);
2015-09-17 20:58:19 +00:00
};