2016-02-01 02:33:33 +00:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
/// <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");
|
|
|
|
module.exports = function (functionsToExecuteArg, executionModeArg, logBoolArg) {
|
|
|
|
if (executionModeArg === void 0) { executionModeArg = 'forEach'; }
|
|
|
|
if (logBoolArg === void 0) { logBoolArg = false; }
|
2015-11-30 08:49:52 +00:00
|
|
|
//important vars
|
2016-02-01 02:33:33 +00:00
|
|
|
var gulpFunction = {
|
|
|
|
executionMode: executionModeArg,
|
|
|
|
functionsToExecute: functionsToExecuteArg,
|
|
|
|
logBool: logBoolArg
|
2015-11-30 08:49:52 +00:00
|
|
|
};
|
|
|
|
var runFunctionNames = function () {
|
2016-02-01 02:33:33 +00:00
|
|
|
if (typeof gulpFunction.functionsToExecute == "function") {
|
|
|
|
gulpFunction.functionsToExecute();
|
2015-11-30 08:49:52 +00:00
|
|
|
}
|
2016-02-01 02:33:33 +00:00
|
|
|
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');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
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)
|
2015-11-30 08:49:52 +00:00
|
|
|
beautylog.log('is forEach');
|
|
|
|
runFunctionNames();
|
|
|
|
}
|
|
|
|
//tell gulp that we are complete
|
|
|
|
return cb(null, file);
|
|
|
|
};
|
|
|
|
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-10-25 19:02:14 +00:00
|
|
|
};
|