added test

This commit is contained in:
Phil Kunz 2015-10-26 16:18:37 +01:00
parent f9c4fb9887
commit c708f964ec
10 changed files with 92 additions and 33 deletions

View File

@ -17,7 +17,7 @@ var myFunction = function () {
gulp.task('gulpTest',function() { gulp.task('gulpTest',function() {
gulp.src('./mydir/*.something') gulp.src('./mydir/*.something')
.pipe(gulpCallFunction(myFunction,'forEach')) .pipe(gulpCallFunction(myFunction,'forEach'))
.pipe(gulp.dest(./build/)) .pipe(gulp.dest("./build/"))
}); });
``` ```

View File

@ -3,14 +3,17 @@ var through = require("through2");
var path = require("path"); var path = require("path");
var beautylog = require("beautylog"); var beautylog = require("beautylog");
//important vars //important vars
var executionMode; //can be forEach or atEnd var gulpCallFunction = {
var functionsToExecute; executionMode: 'forEach',
functionsToExecute: undefined,
logBool: false
};
var runFunctionNames = function () { var runFunctionNames = function () {
if (typeof functionsToExecute === "function") { if (typeof gulpCallFunction.functionsToExecute == "function") {
functionsToExecute(); gulpCallFunction.functionsToExecute();
} }
else if (Array.isArray(functionsToExecute)) { else if (Array.isArray(gulpCallFunction.functionsToExecute)) {
for (var anyFunction in functionsToExecute) { for (var anyFunction in gulpCallFunction.functionsToExecute) {
anyFunction(); anyFunction();
} }
} }
@ -19,20 +22,26 @@ var runFunctionNames = function () {
} }
}; };
var forEach = function (file, enc, cb) { var forEach = function (file, enc, cb) {
if (executionMode === 'forEach') { if (gulpCallFunction.logBool)
beautylog.log(gulpCallFunction.executionMode);
if (gulpCallFunction.executionMode === 'forEach') {
if (gulpCallFunction.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 () { var atEnd = function () {
if (executionMode === "atEnd") { if (gulpCallFunction.executionMode == "atEnd") {
runFunctionNames(); runFunctionNames();
} }
}; };
module.exports = function (functionsToExecute, executionMode) { module.exports = function (functionsToExecute, executionMode, logBool) {
if (executionMode === void 0) { executionMode = 'forEach'; } if (executionMode === void 0) { executionMode = 'forEach'; }
this.functionsToExecute = functionsToExecute; if (logBool === void 0) { logBool = false; }
this.executionMode = executionMode; gulpCallFunction.functionsToExecute = functionsToExecute;
gulpCallFunction.executionMode = executionMode;
gulpCallFunction.logBool = logBool;
return through.obj(forEach, atEnd); return through.obj(forEach, atEnd);
}; };

View File

@ -4,7 +4,7 @@
"description": "accepts a function call as parameter to execute in gulp pipeline", "description": "accepts a function call as parameter to execute in gulp pipeline",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"test": "(cd ts/compile && gulp)", "test": "(cd ts/compile && node compile.js) && (node test.js)",
"reinstall": "(rm -r node_modules && npm install)", "reinstall": "(rm -r node_modules && npm install)",
"release": "(git pull origin master && npm version patch && git push origin master && git checkout release && git merge master && git push origin release && git checkout master)", "release": "(git pull origin master && npm version patch && git push origin master && git checkout release && git merge master && git push origin release && git checkout master)",
"startdev": "(git checkout master && git pull origin master)" "startdev": "(git checkout master && git pull origin master)"
@ -29,6 +29,7 @@
"gulp-typescript": "^2.9.2" "gulp-typescript": "^2.9.2"
}, },
"dependencies": { "dependencies": {
"beautylog": "0.0.15" "beautylog": "0.0.15",
"through2": "^2.0.0"
} }
} }

12
test.js Normal file
View File

@ -0,0 +1,12 @@
/// <reference path="typings/tsd.d.ts" />
var gulp = require("gulp");
var gulpCallFunction = require("./index.js");
var myFunction = function () {
console.log("Hello World!");
};
gulp.task('default', function () {
gulp.src('./test/test.md')
.pipe(gulpCallFunction(myFunction, 'forEach'))
.pipe(gulp.dest("./test/result/"));
});
gulp.start.apply(gulp, ['default']);

2
test/README.md Normal file
View File

@ -0,0 +1,2 @@
#Test
This directory contains files for testing

2
test/result/test.md Normal file
View File

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

2
test/test.md Normal file
View File

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

View File

@ -11,6 +11,16 @@ gulp.task('compileTS', function() {
return stream; return stream;
}); });
gulp.task('default',['compileTS'], function() { gulp.task('compileTestTS', function() {
var stream = gulp.src('../test.ts')
.pipe(gulpTypescript({
out: "test.js"
}))
.pipe(gulp.dest("../../"));
return stream;
});
gulp.task('default',['compileTS','compileTestTS'], function() {
console.log('Typescript compiled'); console.log('Typescript compiled');
}); });
gulp.start.apply(gulp, ['default']);

View File

@ -4,13 +4,17 @@ var path = require("path");
var beautylog = require("beautylog"); var beautylog = require("beautylog");
//important vars //important vars
var executionMode:string; //can be forEach or atEnd var gulpCallFunction = {
var functionsToExecute; executionMode: 'forEach', //can be forEach or atEnd
functionsToExecute: undefined,
logBool: false
};
var runFunctionNames = function () { var runFunctionNames = function () {
if (typeof functionsToExecute === "function" ) { if (typeof gulpCallFunction.functionsToExecute == "function" ) {
functionsToExecute(); gulpCallFunction.functionsToExecute();
} else if (Array.isArray(functionsToExecute)) { } else if (Array.isArray(gulpCallFunction.functionsToExecute)) {
for (var anyFunction in functionsToExecute) { for (var anyFunction in gulpCallFunction.functionsToExecute) {
anyFunction(); anyFunction();
} }
} else { } else {
@ -20,20 +24,23 @@ var runFunctionNames = function () {
var forEach = function (file, enc, cb) { var forEach = function (file, enc, cb) {
if (executionMode === 'forEach') { if (gulpCallFunction.logBool) beautylog.log(gulpCallFunction.executionMode);
runFunctionNames(); if (gulpCallFunction.executionMode === 'forEach') {
} if(gulpCallFunction.logBool) beautylog.log('is forEach');
//tell gulp that we are complete runFunctionNames();
return cb(null, file); }
//tell gulp that we are complete
return cb(null, file);
}; };
var atEnd = function() { var atEnd = function() {
if (executionMode === "atEnd") { if (gulpCallFunction.executionMode == "atEnd") {
runFunctionNames(); runFunctionNames();
} }
}; };
module.exports = function (functionsToExecute:any|any[],executionMode:string = 'forEach') { module.exports = function (functionsToExecute:any|any[],executionMode:string = 'forEach', logBool = false) {
this.functionsToExecute = functionsToExecute; gulpCallFunction.functionsToExecute = functionsToExecute;
this.executionMode = executionMode; gulpCallFunction.executionMode = executionMode;
gulpCallFunction.logBool = logBool;
return through.obj(forEach,atEnd); return through.obj(forEach,atEnd);
}; };

14
ts/test.ts Normal file
View File

@ -0,0 +1,14 @@
/// <reference path="typings/tsd.d.ts" />
var gulp = require("gulp");
var gulpCallFunction = require("./index.js");
var myFunction = function () {
console.log("Hello World!");
}
gulp.task('default',function() {
gulp.src('./test/test.md')
.pipe(gulpCallFunction(myFunction,'forEach'))
.pipe(gulp.dest("./test/result/"))
});
gulp.start.apply(gulp, ['default']);