Compare commits

..

11 Commits

Author SHA1 Message Date
395cb7d8a2 1.1.1 2016-02-14 18:42:55 +01:00
6284fa71d1 update promise 2016-02-14 18:42:45 +01:00
c5ec5fc0f9 1.1.0 2016-02-14 18:40:45 +01:00
17aa25fb61 update README 2016-02-14 18:40:37 +01:00
6e55ed3162 now accepts promises as return of supplied functions 2016-02-14 18:36:34 +01:00
ac9305c480 1.0.4 2016-02-12 05:41:06 +01:00
a51419f2b0 add npmts.json 2016-02-12 05:41:02 +01:00
4b02d17d6d 1.0.3 2016-02-12 05:36:31 +01:00
57350d6fee add better tests and coverage 2016-02-12 05:36:23 +01:00
dcdf0059cc 1.0.2 2016-02-02 15:21:45 +01:00
9cc9e15b04 update deps 2016-02-02 15:21:27 +01:00
12 changed files with 196 additions and 82 deletions

1
.gitignore vendored
View File

@ -1,6 +1,7 @@
node_modules/
.settings/
.idea/
coverage/
ts/*.js
ts/*.js.map

View File

@ -1,26 +1,39 @@
# gulp-function
accepts call to execute in gulp pipeline.
### build status/Dependencies
### Status
[![Build Status](https://travis-ci.org/pushrocks/gulp-function.svg?branch=v0.0.2)](https://travis-ci.org/pushrocks/gulp-function)
[![Dependency Status](https://david-dm.org/pushrocks/gulp-function.svg)](https://david-dm.org/pushrocks/gulp-function)
[![devDependency Status](https://david-dm.org/pushrocks/gulp-function/dev-status.svg)](https://david-dm.org/pushrocks/gulp-function#info=devDependencies)
[![bitHound Code](https://www.bithound.io/github/pushrocks/gulp-function/badges/code.svg)](https://www.bithound.io/github/pushrocks/gulp-function)
[![Coverage Status](https://coveralls.io/repos/github/pushrocks/gulp-function/badge.svg?branch=master)](https://coveralls.io/github/pushrocks/gulp-function?branch=master)
### Usage
```javascript
var gulp = require("gulp");
var gulpFunction = require("gulp-function");
var Q = require("q");
var myFunction = function () {
var done = Q.defer();
console.log("Hello World!")
// NOTE:
// you can use done.resolve as callback function
// of any async tasks within this function
done.resolve();
return done.promise;
}
gulp.task('gulpTest',function() {
gulp.src('./mydir/*.something')
.pipe(gulpFunction(myFunction,'forEach'))
.pipe(gulp.dest("./build/"))
var stream = gulp.src('./mydir/*.something')
.pipe(gulpFunction(myFunction,'forEach')) //read the notes below
.pipe(gulp.dest("./build/"));
return stream; // by returning the stream gulp knows when our task has finished.
});
```
>Note: The first argument of gulpFunction can also be an array of multiple functionnames.
>Note: the second argument can be empty (defaults to 'forEach') or 'atEnd'
> Note: The first argument of gulpFunction can also be an array of multiple functionnames.
Each function can return a promise. the pipe stop will finish when every promise is fullfilled.
> Note: the second argument can be empty (defaults to 'forEach') or 'atEnd'

8
index.d.ts vendored
View File

@ -1,4 +1,6 @@
/// <reference path="ts/typings/main.d.ts" />
declare var through: any;
declare var path: any;
declare var beautylog: any;
declare var plugins: {
beautylog: any;
Q: any;
through: any;
};

View File

@ -1,47 +1,57 @@
#!/usr/bin/env node
/// <reference path="typings/main.d.ts" />
var through = require("through2");
var path = require("path");
var beautylog = require("beautylog");
module.exports = function (functionsToExecuteArg, executionModeArg, logBoolArg) {
var plugins = {
beautylog: require("beautylog"),
Q: require("q"),
through: require("through2")
};
module.exports = function (functionsToExecuteArg, executionModeArg) {
if (executionModeArg === void 0) { executionModeArg = 'forEach'; }
if (logBoolArg === void 0) { logBoolArg = false; }
//important vars
var gulpFunction = {
executionMode: executionModeArg,
functionsToExecute: functionsToExecuteArg,
logBool: logBoolArg
};
var runFunctionNames = function () {
if (typeof gulpFunction.functionsToExecute == "function") {
gulpFunction.functionsToExecute();
var executionMode = executionModeArg; //can be forEach or atEnd
var functionsToExecute = functionsToExecuteArg;
var promiseArray = [];
var runFunction = function (functionArg) {
var returnValue = functionArg();
if (typeof returnValue !== "undefined" && typeof returnValue.then !== "undefined") {
promiseArray.push(returnValue);
}
else if (Array.isArray(gulpFunction.functionsToExecute)) {
for (var anyFunction in gulpFunction.functionsToExecute) {
anyFunction();
};
var checkAndRunFunction = function () {
if (typeof functionsToExecute === "function") {
runFunction(functionsToExecute);
}
else if (Array.isArray(functionsToExecute)) {
for (var anyFunction in functionsToExecute) {
runFunction(functionsToExecute[anyFunction]);
}
}
else {
beautylog.error('gulp-callfunction: something is strange with the given arguments');
plugins.beautylog.error('gulp-callfunction: something is strange with the given arguments');
}
return plugins.Q.all(promiseArray);
};
var forEach = function (file, enc, cb) {
if (gulpFunction.logBool)
beautylog.log(gulpFunction.executionMode);
if (gulpFunction.executionMode === 'forEach') {
if (gulpFunction.logBool)
beautylog.log('is forEach');
runFunctionNames();
if (executionMode === 'forEach') {
checkAndRunFunction().then(function () {
cb(null, file);
});
}
else {
cb(null, file);
}
//tell gulp that we are complete
return cb(null, file);
};
var atEnd = function (cb) {
if (gulpFunction.executionMode == "atEnd") {
runFunctionNames();
}
if (executionMode === "atEnd") {
checkAndRunFunction().then(function () {
cb();
});
}
else {
cb();
}
};
return through.obj(forEach, atEnd);
return plugins.through.obj(forEach, atEnd);
};

4
npmts.json Normal file
View File

@ -0,0 +1,4 @@
{
"mode":"default",
"coveralls":true
}

View File

@ -1,6 +1,6 @@
{
"name": "gulp-function",
"version": "1.0.1",
"version": "1.1.1",
"description": "accepts a function call as parameter to execute in gulp pipeline",
"main": "index.js",
"scripts": {
@ -25,11 +25,12 @@
},
"homepage": "https://github.com/pushrocks/gulp-function",
"dependencies": {
"beautylog": "2.0.4",
"through2": "2.0.0"
"beautylog": "^2.1.1",
"q": "^1.4.1",
"through2": "^2.0.1"
},
"devDependencies": {
"gulp": "^3.9.0",
"npmts": "^2.0.2"
"gulp": "^3.9.1",
"npmts": "^2.2.3"
}
}

8
test/test.d.ts vendored Normal file
View File

@ -0,0 +1,8 @@
/// <reference path="ts/typings/main.d.ts" />
declare var gulp: any;
declare var gulpFunction: any;
declare var beautylog: any;
declare var Q: any;
declare var myFunction: () => any;
declare var myFunction2: () => any;
declare var myFunction3: () => any;

View File

@ -1,17 +1,45 @@
#!/usr/bin/env node
/// <reference path="typings/main.d.ts" />
var gulp = require("gulp");
var gulpFunction = require("../index.js");
var beautylog = require("beautylog");
var Q = require("q");
var myFunction = function () {
beautylog.log("Mocha Test successfull!");
var done = Q.defer();
beautylog.log("Function executed");
done.resolve();
return done.promise;
};
var myFunction2 = function () {
var done = Q.defer();
beautylog.ok("Function2 executed");
done.resolve();
return done.promise;
};
var myFunction3 = function () {
var done = Q.defer();
beautylog.success("Function3 executed");
done.resolve();
return done.promise;
};
describe("gulpFunction", function () {
it("should run through smoothly", function () {
gulp.task('default', function () {
gulp.src('./test/test.md')
it("should run through smoothly with " + "'forEach'".blue, function (done) {
gulp.src('./test/*.md')
.pipe(gulpFunction(myFunction, 'forEach'))
.pipe(gulp.dest("./test/result/"));
gulp.src('./test/*.md')
.pipe(gulpFunction([myFunction2, myFunction3], 'forEach'))
.pipe(gulp.dest("./test/result/"))
.pipe(gulpFunction(done, "atEnd"));
});
gulp.start.apply(gulp, ['default']);
it("should run through smoothly with " + "'atEnd'".blue, function (done) {
gulp.src('./test/*.md')
.pipe(gulpFunction(myFunction, 'atEnd'))
.pipe(gulp.dest("./test/result/"));
gulp.src('./test/*.md')
.pipe(gulpFunction([myFunction2, myFunction3], 'atEnd'))
.pipe(gulp.dest("./test/result/"))
.pipe(gulpFunction(done, "atEnd"));
});
});

2
test/test02.md Normal file
View File

@ -0,0 +1,2 @@
# Test.md
This is another test file for the test.js gulp pipeline

View File

@ -1,45 +1,60 @@
/// <reference path="typings/main.d.ts" />
var through = require("through2");
var path = require("path");
var beautylog = require("beautylog");
var plugins = {
beautylog: require("beautylog"),
Q: require("q"),
through: require("through2")
}
module.exports = function (functionsToExecuteArg:any|any[],executionModeArg:string = 'forEach', logBoolArg = false) {
module.exports = function (functionsToExecuteArg:any|any[],executionModeArg:string = 'forEach') {
//important vars
var gulpFunction = {
executionMode: executionModeArg, //can be forEach or atEnd
functionsToExecute: functionsToExecuteArg,
logBool: logBoolArg
var executionMode = executionModeArg; //can be forEach or atEnd
var functionsToExecute = functionsToExecuteArg;
var promiseArray = [];
var runFunction = function(functionArg){
var returnValue = functionArg();
if (typeof returnValue !== "undefined" && typeof returnValue.then !== "undefined") {
promiseArray.push(returnValue);
}
};
var runFunctionNames = function () {
if (typeof gulpFunction.functionsToExecute == "function" ) {
gulpFunction.functionsToExecute();
} else if (Array.isArray(gulpFunction.functionsToExecute)) {
for (var anyFunction in gulpFunction.functionsToExecute) {
anyFunction();
var checkAndRunFunction = function () {
if (typeof functionsToExecute === "function" ) {
runFunction(functionsToExecute);
} else if (Array.isArray(functionsToExecute)) {
for (var anyFunction in functionsToExecute) {
runFunction(functionsToExecute[anyFunction]);
}
} else {
beautylog.error('gulp-callfunction: something is strange with the given arguments');
plugins.beautylog.error('gulp-callfunction: something is strange with the given arguments');
}
return plugins.Q.all(promiseArray);
};
var forEach = function (file, enc, cb) {
if (gulpFunction.logBool) beautylog.log(gulpFunction.executionMode);
if (gulpFunction.executionMode === 'forEach') {
if(gulpFunction.logBool) beautylog.log('is forEach');
runFunctionNames();
if (executionMode === 'forEach') {
checkAndRunFunction().then(function(){
cb(null, file);
});
} else {
cb(null, file);
}
//tell gulp that we are complete
return cb(null, file);
};
var atEnd = function(cb) {
if (gulpFunction.executionMode == "atEnd") {
runFunctionNames();
}
if (executionMode === "atEnd") {
checkAndRunFunction().then(function(){
cb();
});
} else {
cb();
}
};
return through.obj(forEach,atEnd);
return plugins.through.obj(forEach,atEnd);
};

View File

@ -2,19 +2,49 @@
var gulp = require("gulp");
var gulpFunction = require("../index.js");
var beautylog = require("beautylog");
var Q = require("q");
var myFunction = function () {
beautylog.log("Mocha Test successfull!");
var done = Q.defer()
beautylog.log("Function executed");
done.resolve();
return done.promise;
};
var myFunction2 = function () {
var done = Q.defer();
beautylog.ok("Function2 executed");
done.resolve();
return done.promise;
};
var myFunction3 = function () {
var done = Q.defer();
beautylog.success("Function3 executed");
done.resolve();
return done.promise;
};
describe("gulpFunction",function(){
it("should run through smoothly",function(){
gulp.task('default',function() {
gulp.src('./test/test.md')
it("should run through smoothly with " + "'forEach'".blue,function(done){
gulp.src('./test/*.md')
.pipe(gulpFunction(myFunction,'forEach'))
.pipe(gulp.dest("./test/result/"));
gulp.src('./test/*.md')
.pipe(gulpFunction([myFunction2,myFunction3],'forEach'))
.pipe(gulp.dest("./test/result/"))
.pipe(gulpFunction(done,"atEnd"));
});
gulp.start.apply(gulp, ['default']);
it("should run through smoothly with " + "'atEnd'".blue,function(done){
gulp.src('./test/*.md')
.pipe(gulpFunction(myFunction,'atEnd'))
.pipe(gulp.dest("./test/result/"));
gulp.src('./test/*.md')
.pipe(gulpFunction([myFunction2,myFunction3],'atEnd'))
.pipe(gulp.dest("./test/result/"))
.pipe(gulpFunction(done,"atEnd"));
});
});