add better tests and coverage
This commit is contained in:
parent
dcdf0059cc
commit
57350d6fee
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,6 +1,7 @@
|
|||||||
node_modules/
|
node_modules/
|
||||||
.settings/
|
.settings/
|
||||||
.idea/
|
.idea/
|
||||||
|
coverage/
|
||||||
|
|
||||||
ts/*.js
|
ts/*.js
|
||||||
ts/*.js.map
|
ts/*.js.map
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
# gulp-function
|
# gulp-function
|
||||||
accepts call to execute in gulp pipeline.
|
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)
|
[![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)
|
[![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)
|
[![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
|
### Usage
|
||||||
```javascript
|
```javascript
|
||||||
@ -17,7 +19,7 @@ var myFunction = function () {
|
|||||||
|
|
||||||
gulp.task('gulpTest',function() {
|
gulp.task('gulpTest',function() {
|
||||||
gulp.src('./mydir/*.something')
|
gulp.src('./mydir/*.something')
|
||||||
.pipe(gulpFunction(myFunction,'forEach'))
|
.pipe(gulpFunction(myFunction,'forEach')) //read the notes below
|
||||||
.pipe(gulp.dest("./build/"))
|
.pipe(gulp.dest("./build/"))
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
16
index.js
16
index.js
@ -4,22 +4,20 @@
|
|||||||
var through = require("through2");
|
var through = require("through2");
|
||||||
var path = require("path");
|
var path = require("path");
|
||||||
var beautylog = require("beautylog");
|
var beautylog = require("beautylog");
|
||||||
module.exports = function (functionsToExecuteArg, executionModeArg, logBoolArg) {
|
module.exports = function (functionsToExecuteArg, executionModeArg) {
|
||||||
if (executionModeArg === void 0) { executionModeArg = 'forEach'; }
|
if (executionModeArg === void 0) { executionModeArg = 'forEach'; }
|
||||||
if (logBoolArg === void 0) { logBoolArg = false; }
|
|
||||||
//important vars
|
//important vars
|
||||||
var gulpFunction = {
|
var gulpFunction = {
|
||||||
executionMode: executionModeArg,
|
executionMode: executionModeArg,
|
||||||
functionsToExecute: functionsToExecuteArg,
|
functionsToExecute: functionsToExecuteArg
|
||||||
logBool: logBoolArg
|
|
||||||
};
|
};
|
||||||
var runFunctionNames = function () {
|
var runFunctionNames = function () {
|
||||||
if (typeof gulpFunction.functionsToExecute == "function") {
|
if (typeof gulpFunction.functionsToExecute === "function") {
|
||||||
gulpFunction.functionsToExecute();
|
gulpFunction.functionsToExecute();
|
||||||
}
|
}
|
||||||
else if (Array.isArray(gulpFunction.functionsToExecute)) {
|
else if (Array.isArray(gulpFunction.functionsToExecute)) {
|
||||||
for (var anyFunction in gulpFunction.functionsToExecute) {
|
for (var anyFunction in gulpFunction.functionsToExecute) {
|
||||||
anyFunction();
|
gulpFunction.functionsToExecute[anyFunction]();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -27,18 +25,14 @@ module.exports = function (functionsToExecuteArg, executionModeArg, logBoolArg)
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
var forEach = function (file, enc, cb) {
|
var forEach = function (file, enc, cb) {
|
||||||
if (gulpFunction.logBool)
|
|
||||||
beautylog.log(gulpFunction.executionMode);
|
|
||||||
if (gulpFunction.executionMode === 'forEach') {
|
if (gulpFunction.executionMode === 'forEach') {
|
||||||
if (gulpFunction.logBool)
|
|
||||||
beautylog.log('is forEach');
|
|
||||||
runFunctionNames();
|
runFunctionNames();
|
||||||
}
|
}
|
||||||
//tell gulp that we are complete
|
//tell gulp that we are complete
|
||||||
return cb(null, file);
|
return cb(null, file);
|
||||||
};
|
};
|
||||||
var atEnd = function (cb) {
|
var atEnd = function (cb) {
|
||||||
if (gulpFunction.executionMode == "atEnd") {
|
if (gulpFunction.executionMode === "atEnd") {
|
||||||
runFunctionNames();
|
runFunctionNames();
|
||||||
}
|
}
|
||||||
cb();
|
cb();
|
||||||
|
@ -25,11 +25,11 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/pushrocks/gulp-function",
|
"homepage": "https://github.com/pushrocks/gulp-function",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"beautylog": "2.0.6",
|
"beautylog": "2.1.1",
|
||||||
"through2": "2.0.0"
|
"through2": "2.0.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"gulp": "^3.9.0",
|
"gulp": "^3.9.1",
|
||||||
"npmts": "^2.0.2"
|
"npmts": "^2.2.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
6
test/test.d.ts
vendored
Normal file
6
test/test.d.ts
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
/// <reference path="ts/typings/main.d.ts" />
|
||||||
|
declare var gulp: any;
|
||||||
|
declare var gulpFunction: any;
|
||||||
|
declare var beautylog: any;
|
||||||
|
declare var myFunction: () => void;
|
||||||
|
declare var myFunction2: () => void;
|
23
test/test.js
23
test/test.js
@ -1,17 +1,30 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
/// <reference path="typings/main.d.ts" />
|
/// <reference path="typings/main.d.ts" />
|
||||||
var gulp = require("gulp");
|
var gulp = require("gulp");
|
||||||
var gulpFunction = require("../index.js");
|
var gulpFunction = require("../index.js");
|
||||||
var beautylog = require("beautylog");
|
var beautylog = require("beautylog");
|
||||||
var myFunction = function () {
|
var myFunction = function () {
|
||||||
beautylog.log("Mocha Test successfull!");
|
beautylog.log("Function executed");
|
||||||
|
};
|
||||||
|
var myFunction2 = function () {
|
||||||
|
beautylog.log("Function2 executed");
|
||||||
};
|
};
|
||||||
describe("gulpFunction", function () {
|
describe("gulpFunction", function () {
|
||||||
it("should run through smoothly", function () {
|
it("should run through smoothly with " + "'forEach'".blue, function () {
|
||||||
gulp.task('default', function () {
|
gulp.src('./test/*.md')
|
||||||
gulp.src('./test/test.md')
|
|
||||||
.pipe(gulpFunction(myFunction, 'forEach'))
|
.pipe(gulpFunction(myFunction, 'forEach'))
|
||||||
.pipe(gulp.dest("./test/result/"));
|
.pipe(gulp.dest("./test/result/"));
|
||||||
|
gulp.src('./test/*.md')
|
||||||
|
.pipe(gulpFunction([myFunction, myFunction2], 'forEach'))
|
||||||
|
.pipe(gulp.dest("./test/result/"));
|
||||||
});
|
});
|
||||||
gulp.start.apply(gulp, ['default']);
|
it("should run through smoothly with " + "'atEnd'".blue, function () {
|
||||||
|
gulp.src('./test/*.md')
|
||||||
|
.pipe(gulpFunction(myFunction, 'atEnd'))
|
||||||
|
.pipe(gulp.dest("./test/result/"));
|
||||||
|
gulp.src('./test/*.md')
|
||||||
|
.pipe(gulpFunction([myFunction, myFunction2], 'atEnd'))
|
||||||
|
.pipe(gulp.dest("./test/result/"));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
2
test/test02.md
Normal file
2
test/test02.md
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
# Test.md
|
||||||
|
This is another test file for the test.js gulp pipeline
|
13
ts/index.ts
13
ts/index.ts
@ -4,20 +4,19 @@ var path = require("path");
|
|||||||
var beautylog = require("beautylog");
|
var beautylog = require("beautylog");
|
||||||
|
|
||||||
|
|
||||||
module.exports = function (functionsToExecuteArg:any|any[],executionModeArg:string = 'forEach', logBoolArg = false) {
|
module.exports = function (functionsToExecuteArg:any|any[],executionModeArg:string = 'forEach') {
|
||||||
//important vars
|
//important vars
|
||||||
var gulpFunction = {
|
var gulpFunction = {
|
||||||
executionMode: executionModeArg, //can be forEach or atEnd
|
executionMode: executionModeArg, //can be forEach or atEnd
|
||||||
functionsToExecute: functionsToExecuteArg,
|
functionsToExecute: functionsToExecuteArg
|
||||||
logBool: logBoolArg
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var runFunctionNames = function () {
|
var runFunctionNames = function () {
|
||||||
if (typeof gulpFunction.functionsToExecute == "function" ) {
|
if (typeof gulpFunction.functionsToExecute === "function" ) {
|
||||||
gulpFunction.functionsToExecute();
|
gulpFunction.functionsToExecute();
|
||||||
} else if (Array.isArray(gulpFunction.functionsToExecute)) {
|
} else if (Array.isArray(gulpFunction.functionsToExecute)) {
|
||||||
for (var anyFunction in gulpFunction.functionsToExecute) {
|
for (var anyFunction in gulpFunction.functionsToExecute) {
|
||||||
anyFunction();
|
gulpFunction.functionsToExecute[anyFunction]();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
beautylog.error('gulp-callfunction: something is strange with the given arguments');
|
beautylog.error('gulp-callfunction: something is strange with the given arguments');
|
||||||
@ -26,9 +25,7 @@ module.exports = function (functionsToExecuteArg:any|any[],executionModeArg:stri
|
|||||||
|
|
||||||
|
|
||||||
var forEach = function (file, enc, cb) {
|
var forEach = function (file, enc, cb) {
|
||||||
if (gulpFunction.logBool) beautylog.log(gulpFunction.executionMode);
|
|
||||||
if (gulpFunction.executionMode === 'forEach') {
|
if (gulpFunction.executionMode === 'forEach') {
|
||||||
if(gulpFunction.logBool) beautylog.log('is forEach');
|
|
||||||
runFunctionNames();
|
runFunctionNames();
|
||||||
}
|
}
|
||||||
//tell gulp that we are complete
|
//tell gulp that we are complete
|
||||||
@ -36,7 +33,7 @@ module.exports = function (functionsToExecuteArg:any|any[],executionModeArg:stri
|
|||||||
};
|
};
|
||||||
|
|
||||||
var atEnd = function(cb) {
|
var atEnd = function(cb) {
|
||||||
if (gulpFunction.executionMode == "atEnd") {
|
if (gulpFunction.executionMode === "atEnd") {
|
||||||
runFunctionNames();
|
runFunctionNames();
|
||||||
}
|
}
|
||||||
cb();
|
cb();
|
||||||
|
25
ts/test.ts
25
ts/test.ts
@ -4,17 +4,30 @@ var gulpFunction = require("../index.js");
|
|||||||
var beautylog = require("beautylog");
|
var beautylog = require("beautylog");
|
||||||
|
|
||||||
var myFunction = function () {
|
var myFunction = function () {
|
||||||
beautylog.log("Mocha Test successfull!");
|
beautylog.log("Function executed");
|
||||||
|
};
|
||||||
|
var myFunction2 = function () {
|
||||||
|
beautylog.log("Function2 executed");
|
||||||
};
|
};
|
||||||
|
|
||||||
describe("gulpFunction",function(){
|
describe("gulpFunction",function(){
|
||||||
it("should run through smoothly",function(){
|
it("should run through smoothly with " + "'forEach'".blue,function(){
|
||||||
gulp.task('default',function() {
|
gulp.src('./test/*.md')
|
||||||
gulp.src('./test/test.md')
|
|
||||||
.pipe(gulpFunction(myFunction,'forEach'))
|
.pipe(gulpFunction(myFunction,'forEach'))
|
||||||
.pipe(gulp.dest("./test/result/"))
|
.pipe(gulp.dest("./test/result/"));
|
||||||
|
gulp.src('./test/*.md')
|
||||||
|
.pipe(gulpFunction([myFunction,myFunction2],'forEach'))
|
||||||
|
.pipe(gulp.dest("./test/result/"));
|
||||||
|
|
||||||
});
|
});
|
||||||
gulp.start.apply(gulp, ['default']);
|
|
||||||
|
it("should run through smoothly with " + "'atEnd'".blue,function(){
|
||||||
|
gulp.src('./test/*.md')
|
||||||
|
.pipe(gulpFunction(myFunction,'atEnd'))
|
||||||
|
.pipe(gulp.dest("./test/result/"));
|
||||||
|
gulp.src('./test/*.md')
|
||||||
|
.pipe(gulpFunction([myFunction,myFunction2],'atEnd'))
|
||||||
|
.pipe(gulp.dest("./test/result/"));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user