gulp-function/index.js

48 lines
1.6 KiB
JavaScript
Raw Normal View History

2015-10-25 19:02:14 +00:00
/// <reference path="typings/tsd.d.ts" />
2015-10-25 21:45:49 +00:00
var through = require("through2");
var path = require("path");
var beautylog = require("beautylog");
//important vars
2015-10-26 15:18:37 +00:00
var gulpCallFunction = {
executionMode: 'forEach',
functionsToExecute: undefined,
logBool: false
};
2015-10-25 21:45:49 +00:00
var runFunctionNames = function () {
2015-10-26 15:18:37 +00:00
if (typeof gulpCallFunction.functionsToExecute == "function") {
gulpCallFunction.functionsToExecute();
2015-10-25 21:45:49 +00:00
}
2015-10-26 15:18:37 +00:00
else if (Array.isArray(gulpCallFunction.functionsToExecute)) {
for (var anyFunction in gulpCallFunction.functionsToExecute) {
2015-10-25 21:45:49 +00:00
anyFunction();
}
}
else {
beautylog.error('gulp-callfunction: something is strange with the given arguments');
}
};
var forEach = function (file, enc, cb) {
2015-10-26 15:18:37 +00:00
if (gulpCallFunction.logBool)
beautylog.log(gulpCallFunction.executionMode);
if (gulpCallFunction.executionMode === 'forEach') {
if (gulpCallFunction.logBool)
beautylog.log('is forEach');
2015-10-25 21:45:49 +00:00
runFunctionNames();
}
//tell gulp that we are complete
return cb(null, file);
};
var atEnd = function () {
2015-10-26 15:18:37 +00:00
if (gulpCallFunction.executionMode == "atEnd") {
2015-10-25 21:45:49 +00:00
runFunctionNames();
}
};
2015-10-26 15:18:37 +00:00
module.exports = function (functionsToExecute, executionMode, logBool) {
2015-10-25 21:45:49 +00:00
if (executionMode === void 0) { executionMode = 'forEach'; }
2015-10-26 15:18:37 +00:00
if (logBool === void 0) { logBool = false; }
gulpCallFunction.functionsToExecute = functionsToExecute;
gulpCallFunction.executionMode = executionMode;
gulpCallFunction.logBool = logBool;
2015-10-25 21:45:49 +00:00
return through.obj(forEach, atEnd);
2015-10-25 19:02:14 +00:00
};