gulp-function/ts/index.ts

47 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");
var beautylog = require("beautylog");
2015-09-17 20:58:19 +00:00
2015-10-25 21:45:49 +00:00
//important vars
2015-10-26 15:18:37 +00:00
var gulpCallFunction = {
executionMode: 'forEach', //can be forEach or atEnd
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();
} 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');
}
};
2015-09-17 20:58:19 +00:00
2015-10-25 21:45:49 +00:00
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');
runFunctionNames();
}
//tell gulp that we are complete
return cb(null, file);
2015-10-25 21:45:49 +00:00
};
var atEnd = function() {
2015-10-26 15:18:37 +00:00
if (gulpCallFunction.executionMode == "atEnd") {
runFunctionNames();
}
2015-10-25 21:45:49 +00:00
};
2015-10-26 15:18:37 +00:00
module.exports = function (functionsToExecute:any|any[],executionMode:string = 'forEach', 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-09-17 20:58:19 +00:00
};