diff --git a/README.md b/README.md
index f2f9c8f..043a03d 100644
--- a/README.md
+++ b/README.md
@@ -17,7 +17,7 @@ var myFunction = function () {
gulp.task('gulpTest',function() {
gulp.src('./mydir/*.something')
.pipe(gulpCallFunction(myFunction,'forEach'))
- .pipe(gulp.dest(./build/))
+ .pipe(gulp.dest("./build/"))
});
```
diff --git a/index.js b/index.js
index da47ab9..9d33ad3 100644
--- a/index.js
+++ b/index.js
@@ -3,14 +3,17 @@ var through = require("through2");
var path = require("path");
var beautylog = require("beautylog");
//important vars
-var executionMode; //can be forEach or atEnd
-var functionsToExecute;
+var gulpCallFunction = {
+ executionMode: 'forEach',
+ functionsToExecute: undefined,
+ logBool: false
+};
var runFunctionNames = function () {
- if (typeof functionsToExecute === "function") {
- functionsToExecute();
+ if (typeof gulpCallFunction.functionsToExecute == "function") {
+ gulpCallFunction.functionsToExecute();
}
- else if (Array.isArray(functionsToExecute)) {
- for (var anyFunction in functionsToExecute) {
+ else if (Array.isArray(gulpCallFunction.functionsToExecute)) {
+ for (var anyFunction in gulpCallFunction.functionsToExecute) {
anyFunction();
}
}
@@ -19,20 +22,26 @@ var runFunctionNames = function () {
}
};
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();
}
//tell gulp that we are complete
return cb(null, file);
};
var atEnd = function () {
- if (executionMode === "atEnd") {
+ if (gulpCallFunction.executionMode == "atEnd") {
runFunctionNames();
}
};
-module.exports = function (functionsToExecute, executionMode) {
+module.exports = function (functionsToExecute, executionMode, logBool) {
if (executionMode === void 0) { executionMode = 'forEach'; }
- this.functionsToExecute = functionsToExecute;
- this.executionMode = executionMode;
+ if (logBool === void 0) { logBool = false; }
+ gulpCallFunction.functionsToExecute = functionsToExecute;
+ gulpCallFunction.executionMode = executionMode;
+ gulpCallFunction.logBool = logBool;
return through.obj(forEach, atEnd);
};
diff --git a/package.json b/package.json
index 0601933..d9d9988 100644
--- a/package.json
+++ b/package.json
@@ -4,7 +4,7 @@
"description": "accepts a function call as parameter to execute in gulp pipeline",
"main": "index.js",
"scripts": {
- "test": "(cd ts/compile && gulp)",
+ "test": "(cd ts/compile && node compile.js) && (node test.js)",
"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)",
"startdev": "(git checkout master && git pull origin master)"
@@ -29,6 +29,7 @@
"gulp-typescript": "^2.9.2"
},
"dependencies": {
- "beautylog": "0.0.15"
+ "beautylog": "0.0.15",
+ "through2": "^2.0.0"
}
}
diff --git a/test.js b/test.js
new file mode 100644
index 0000000..935a5c0
--- /dev/null
+++ b/test.js
@@ -0,0 +1,12 @@
+///
+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']);
diff --git a/test/README.md b/test/README.md
new file mode 100644
index 0000000..7f47122
--- /dev/null
+++ b/test/README.md
@@ -0,0 +1,2 @@
+#Test
+This directory contains files for testing
\ No newline at end of file
diff --git a/test/result/test.md b/test/result/test.md
new file mode 100644
index 0000000..b5fcd02
--- /dev/null
+++ b/test/result/test.md
@@ -0,0 +1,2 @@
+# Test.md
+This is a test file for the test.js gulp pipeline
\ No newline at end of file
diff --git a/test/test.md b/test/test.md
new file mode 100644
index 0000000..b5fcd02
--- /dev/null
+++ b/test/test.md
@@ -0,0 +1,2 @@
+# Test.md
+This is a test file for the test.js gulp pipeline
\ No newline at end of file
diff --git a/ts/compile/gulpfile.js b/ts/compile/compile.js
similarity index 51%
rename from ts/compile/gulpfile.js
rename to ts/compile/compile.js
index ab173d0..1c89d5a 100644
--- a/ts/compile/gulpfile.js
+++ b/ts/compile/compile.js
@@ -11,6 +11,16 @@ gulp.task('compileTS', function() {
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');
-});
\ No newline at end of file
+});
+gulp.start.apply(gulp, ['default']);
\ No newline at end of file
diff --git a/ts/index.ts b/ts/index.ts
index 3e0a4ed..5802d19 100644
--- a/ts/index.ts
+++ b/ts/index.ts
@@ -4,13 +4,17 @@ var path = require("path");
var beautylog = require("beautylog");
//important vars
-var executionMode:string; //can be forEach or atEnd
-var functionsToExecute;
+var gulpCallFunction = {
+ executionMode: 'forEach', //can be forEach or atEnd
+ functionsToExecute: undefined,
+ logBool: false
+};
+
var runFunctionNames = function () {
- if (typeof functionsToExecute === "function" ) {
- functionsToExecute();
- } else if (Array.isArray(functionsToExecute)) {
- for (var anyFunction in functionsToExecute) {
+ if (typeof gulpCallFunction.functionsToExecute == "function" ) {
+ gulpCallFunction.functionsToExecute();
+ } else if (Array.isArray(gulpCallFunction.functionsToExecute)) {
+ for (var anyFunction in gulpCallFunction.functionsToExecute) {
anyFunction();
}
} else {
@@ -20,20 +24,23 @@ var runFunctionNames = function () {
var forEach = function (file, enc, cb) {
- if (executionMode === 'forEach') {
- runFunctionNames();
- }
- //tell gulp that we are complete
- return cb(null, file);
+ if (gulpCallFunction.logBool) beautylog.log(gulpCallFunction.executionMode);
+ if (gulpCallFunction.executionMode === 'forEach') {
+ if(gulpCallFunction.logBool) beautylog.log('is forEach');
+ runFunctionNames();
+ }
+ //tell gulp that we are complete
+ return cb(null, file);
};
var atEnd = function() {
- if (executionMode === "atEnd") {
- runFunctionNames();
- }
+ if (gulpCallFunction.executionMode == "atEnd") {
+ runFunctionNames();
+ }
};
-module.exports = function (functionsToExecute:any|any[],executionMode:string = 'forEach') {
- this.functionsToExecute = functionsToExecute;
- this.executionMode = executionMode;
+module.exports = function (functionsToExecute:any|any[],executionMode:string = 'forEach', logBool = false) {
+ gulpCallFunction.functionsToExecute = functionsToExecute;
+ gulpCallFunction.executionMode = executionMode;
+ gulpCallFunction.logBool = logBool;
return through.obj(forEach,atEnd);
};
diff --git a/ts/test.ts b/ts/test.ts
new file mode 100644
index 0000000..c528c71
--- /dev/null
+++ b/ts/test.ts
@@ -0,0 +1,14 @@
+///
+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']);