gulp-function/ts/index.ts

40 lines
1.1 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
var executionMode:string; //can be forEach or atEnd
var functionsToExecute;
var runFunctionNames = function () {
if (typeof functionsToExecute === "function" ) {
functionsToExecute();
} else if (Array.isArray(functionsToExecute)) {
for (var anyFunction in functionsToExecute) {
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) {
if (executionMode === 'forEach') {
runFunctionNames();
}
2015-09-17 20:58:19 +00:00
//tell gulp that we are complete
return cb(null, file);
2015-10-25 21:45:49 +00:00
};
var atEnd = function() {
if (executionMode === "atEnd") {
runFunctionNames();
}
};
module.exports = function (functionsToExecute:any|any[],executionMode:string = 'forEach') {
this.functionsToExecute = functionsToExecute;
this.executionMode = executionMode;
return through.obj(forEach,atEnd);
2015-09-17 20:58:19 +00:00
};