gulp-function/ts/index.ts

43 lines
1.3 KiB
TypeScript
Raw Normal View History

2016-02-01 02:33:33 +00:00
/// <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");
2015-09-17 20:58:19 +00:00
2015-10-26 15:18:37 +00:00
2016-02-12 04:36:23 +00:00
module.exports = function (functionsToExecuteArg:any|any[],executionModeArg:string = 'forEach') {
2015-11-30 08:49:52 +00:00
//important vars
2016-02-01 02:33:33 +00:00
var gulpFunction = {
2015-11-30 08:49:52 +00:00
executionMode: executionModeArg, //can be forEach or atEnd
2016-02-12 04:36:23 +00:00
functionsToExecute: functionsToExecuteArg
2015-11-30 08:49:52 +00:00
};
var runFunctionNames = function () {
2016-02-12 04:36:23 +00:00
if (typeof gulpFunction.functionsToExecute === "function" ) {
2016-02-01 02:33:33 +00:00
gulpFunction.functionsToExecute();
} else if (Array.isArray(gulpFunction.functionsToExecute)) {
for (var anyFunction in gulpFunction.functionsToExecute) {
2016-02-12 04:36:23 +00:00
gulpFunction.functionsToExecute[anyFunction]();
2015-11-30 08:49:52 +00:00
}
} 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) {
2016-02-01 02:33:33 +00:00
if (gulpFunction.executionMode === 'forEach') {
2015-11-30 08:49:52 +00:00
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) {
2016-02-12 04:36:23 +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-09-17 20:58:19 +00:00
};