From 1d8de68a667187aef232b432f833cbb91c53b9e7 Mon Sep 17 00:00:00 2001 From: PhilKunz Date: Wed, 19 Oct 2016 07:36:32 +0200 Subject: [PATCH] add .forEach .atEnd .forFirst --- README.md | 2 + dist/index.d.ts | 7 ++- dist/index.js | 15 ++++-- test/test.js | 4 +- test/test.ts | 123 ++++++++++++++++++++++++------------------------ ts/index.ts | 16 ++++++- 6 files changed, 97 insertions(+), 70 deletions(-) diff --git a/README.md b/README.md index b14784d..3ff7940 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ accepts call to execute in gulp pipeline. ```javascript import * as gulp from 'gulp'; import gulpFunction from 'gulp-function' // default ES6 export +// import {forFirst, forEach, atEnd} from 'gulp-function' let Q = require("q"); let myFunction = function (file, enc) { // file and enc are optional in case you want to modify the file object @@ -38,6 +39,7 @@ let myFunction = function (file, enc) { // file and enc are optional in case you gulp.task('gulpTest',function() { let stream = gulp.src('./mydir/*.something') .pipe(gulpFunction(myFunction,'forEach')) //read the notes below + // .pipe(gulpFunction.forEach(myFunction)) .pipe(gulp.dest("./build/")); return stream; // by returning the stream gulp knows when our task has finished. }); diff --git a/dist/index.d.ts b/dist/index.d.ts index 79dfac2..9571fc5 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -5,5 +5,8 @@ export declare type TExecutionMode = 'forEach' | 'forFirst' | 'atEnd'; export interface IPromiseFunction { (file?: any, enc?: any): PromiseLike; } -declare let mainExportFunction: (functionsToExecuteArg: IPromiseFunction | IPromiseFunction[], executionModeArg?: TExecutionMode) => Transform; -export default mainExportFunction; +declare let defaultExport: (functionsToExecuteArg: IPromiseFunction | IPromiseFunction[], executionModeArg?: TExecutionMode) => Transform; +export declare let forEach: (funcArg: IPromiseFunction) => void; +export declare let forFirst: (funcArg: IPromiseFunction) => void; +export declare let atEnd: (funcArg: IPromiseFunction) => void; +export default defaultExport; diff --git a/dist/index.js b/dist/index.js index 4f8e791..6465b48 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2,7 +2,7 @@ require("typings-global"); const q = require("q"); const through2 = require("through2"); -let mainExportFunction = (functionsToExecuteArg, executionModeArg = 'forEach') => { +let defaultExport = (functionsToExecuteArg, executionModeArg = 'forEach') => { let promiseArray = []; let runFunction = function (functionArg, file, enc) { let returnValue = functionArg(file, enc); @@ -63,6 +63,15 @@ let mainExportFunction = (functionsToExecuteArg, executionModeArg = 'forEach') = }; return through2.obj(forEach, atEnd); }; +exports.forEach = (funcArg) => { + defaultExport(funcArg, 'forEach'); +}; +exports.forFirst = (funcArg) => { + defaultExport(funcArg, 'forFirst'); +}; +exports.atEnd = (funcArg) => { + defaultExport(funcArg, 'atEnd'); +}; Object.defineProperty(exports, "__esModule", { value: true }); -exports.default = mainExportFunction; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBQ3ZCLHVCQUFzQjtBQUN0QixxQ0FBb0M7QUFTcEMsSUFBSSxrQkFBa0IsR0FBRyxDQUNyQixxQkFBNEQsRUFDNUQsZ0JBQWdCLEdBQW1CLFNBQVM7SUFHNUMsSUFBSSxZQUFZLEdBQUcsRUFBRSxDQUFBO0lBQ3JCLElBQUksV0FBVyxHQUFHLFVBQVUsV0FBVyxFQUFFLElBQUksRUFBRSxHQUFHO1FBQzlDLElBQUksV0FBVyxHQUFHLFdBQVcsQ0FBQyxJQUFJLEVBQUUsR0FBRyxDQUFDLENBQUE7UUFDeEMsRUFBRSxDQUFDLENBQUMsT0FBTyxXQUFXLEtBQUssV0FBVyxJQUFJLE9BQU8sV0FBVyxDQUFDLElBQUksS0FBSyxXQUFXLENBQUMsQ0FBQyxDQUFDO1lBQ2hGLFlBQVksQ0FBQyxJQUFJLENBQUMsV0FBVyxDQUFDLENBQUE7UUFDbEMsQ0FB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BQTtBQUNuQyxDQUFDLENBQUE7O0FBRUQsa0JBQWUsYUFBYSxDQUFBIn0= \ No newline at end of file diff --git a/test/test.js b/test/test.js index 37c3465..fccff0e 100644 --- a/test/test.js +++ b/test/test.js @@ -2,7 +2,7 @@ require("typings-test"); let gulp = require('gulp'); const index_1 = require("../dist/index"); -let beautylog = require('beautylog'); +const beautylog = require("beautylog"); let Q = require('q'); let myFunction = function () { let done = Q.defer(); @@ -99,4 +99,4 @@ describe('gulpFunction', function () { }); }); }); -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHdCQUFxQjtBQUNyQixJQUFJLElBQUksR0FBRyxPQUFPLENBQUMsTUFBTSxDQUFDLENBQUM7QUFDM0IseUNBQXdDO0FBQ3hDLElBQUksU0FBUyxHQUFHLE9BQU8sQ0FBQyxXQUFXLENBQUMsQ0FBQTtBQUNwQyxJQUFJLENBQUMsR0FBRyxPQUFPLENBQUMsR0FBRyxDQUFDLENBQUE7QUFFcEIsSUFBSSxVQUFVLEdBQUc7SUFDYixJQUFJLElBQUksR0FBRyxDQUFDLENBQUMsS0FBSyxFQUFFLENBQUE7SUFDcEIsU0FBUyxDQUFDLEdBQUcsQ0FBQyxtQkFBbUIsQ0FBQyxDQUFDO0lBQ25DLElBQUksQ0FBQyxPQUFPLEVBQUUsQ0FBQztJQUNmLE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDO0FBQ3hCLENBQUMsQ0FBQztBQUNGLElBQUksV0FBVyxHQUFHO0lBQ2QsSUFBSSxJQUFJLEdBQUcsQ0FBQyxDQUFDLEtBQUssRUFBRSxDQUFDO0lBQ3JCLFNBQVMsQ0FBQyxFQUFFLENBQUMsb0JBQW9CLENBQUMsQ0FBQztJQUNuQyxJQUFJLENBQUMsT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sY0FBYyxDQUFDLEVBQUMsT0FBTyxDQUFDLENBQUM7YUFDMUUsSUFBSSxDQUFDLGVBQVksQ0FBQztZQUNmLFNBQVMsQ0FBQyxHQUFHLENBQUMsbUJBQW1CLENBQUMsQ0FBQTtZQUNsQyxJQUFJLEtBQUssR0FBRyxDQUFDLENBQUMsS0FBSyxFQUFFLENBQUE7WUFDckIsS0FBSyxDQUFDLE9BQU8sRUFBRSxDQUFBO1lBQ2YsTUFBTSxDQUFDLEtBQUssQ0FBQyxPQUFPLENBQUE7UUFDeEIsQ0FBQyxFQUFDLFNBQVMsQ0FBQyxDQUFDO2FBQ1osSUFBSSxDQUFDLGVBQVksQ0FBQztZQUNmLFNBQVMsQ0FBQyxHQUFHLENBQUMsVUFBVSxDQUFDLENBQUE7UUFDN0IsQ0FBQyxDQUFDLENBQUM7YUFDRixJQUFJLENBQUMsZUFBWSxDQUFDLGFBQWEsRUFBQyxPQUFPLENBQUMsQ0FBQzthQUN6QyxJQUFJLENBQUMsZUFBWSxDQUFDLGVBQWUsRUFBQyxPQUFPLENBQUMsQ0FBQyxDQUFBO1FBRWhELE1BQU0sQ0FBQyxFQUFFLENBQUMsUUFBUSxFQUFDO1lBQ2YsU0FBUyxDQUFDLElBQUksQ0FBQyxpQkFBaUIsQ0FBQyxDQUFBO1lBQ2pDLElBQUksRUFBRSxDQUFBO1FBQ1YsQ0FBQyxDQUFDLENBQUE7SUFDTixDQUFDLENBQUMsQ0FBQTtBQUNOLENBQUMsQ0FBQyxDQUFBIn0= \ No newline at end of file diff --git a/test/test.ts b/test/test.ts index 0c2a1dc..63dc5ac 100644 --- a/test/test.ts +++ b/test/test.ts @@ -1,63 +1,64 @@ import 'typings-test' -let gulp = require('gulp'); +let gulp = require('gulp') import gulpFunction from '../dist/index' -let beautylog = require('beautylog') + +import * as beautylog from 'beautylog' let Q = require('q') let myFunction = function () { let done = Q.defer() - beautylog.log('Function executed'); - done.resolve(); - return done.promise; -}; + beautylog.log('Function executed') + done.resolve() + return done.promise +} let myFunction2 = function () { - let done = Q.defer(); - beautylog.ok('Function2 executed'); - done.resolve(); - return done.promise; -}; + let done = Q.defer() + beautylog.ok('Function2 executed') + done.resolve() + return done.promise +} let myFunction3 = function () { - let done = Q.defer(); - beautylog.success('Function3 executed'); - done.resolve(); - return done.promise; -}; + let done = Q.defer() + beautylog.success('Function3 executed') + done.resolve() + return done.promise +} let beforeFunction = function () { - let done = Q.defer(); - beautylog.success('beforeFunction executed'); - done.resolve(); - return done.promise; -}; + let done = Q.defer() + beautylog.success('beforeFunction executed') + done.resolve() + return done.promise +} -let middleFunctionRun = false; +let middleFunctionRun = false let middleFunction = function () { - let done = Q.defer(); - beautylog.success('middleFunction executed'); + let done = Q.defer() + beautylog.success('middleFunction executed') setTimeout(function(){ - beautylog.log('timeout fired'); - middleFunctionRun = true; - done.resolve(); - }, 500); - return done.promise; -}; + beautylog.log('timeout fired') + middleFunctionRun = true + done.resolve() + }, 500) + return done.promise +} let afterFunction = function () { - let done = Q.defer(); - beautylog.success('afterFunction executed'); - done.resolve(); - return done.promise; -}; + let done = Q.defer() + beautylog.success('afterFunction executed') + done.resolve() + return done.promise +} let timeoutFunction = function(){ - let done = Q.defer(); + let done = Q.defer() setTimeout(function(){ - beautylog.log('largeTimeout fired'); - done.resolve(); - },2000); - return done.promise; -}; + beautylog.log('largeTimeout fired') + done.resolve() + },2000) + return done.promise +} @@ -65,54 +66,54 @@ describe('gulpFunction',function(){ it('should run through smoothly with ' + "'forEach'",function(done){ gulp.src('./test/*.md') .pipe(gulpFunction(myFunction,'forEach')) - .pipe(gulp.dest('./test/result/')); + .pipe(gulp.dest('./test/result/')) gulp.src('./test/*.md') .pipe(gulpFunction([myFunction2,myFunction3],'forEach')) .pipe(gulp.dest('./test/result/')) - .pipe(gulpFunction(done,'atEnd')); + .pipe(gulpFunction(done,'atEnd')) - }); + }) it('should run through smoothly with ' + "'atEnd'",function(done){ gulp.src('./test/*.md') .pipe(gulpFunction(myFunction,'atEnd')) - .pipe(gulp.dest('./test/result/')); + .pipe(gulp.dest('./test/result/')) gulp.src('./test/*.md') .pipe(gulpFunction([myFunction2,myFunction3],'atEnd')) .pipe(gulp.dest('./test/result/')) - .pipe(gulpFunction(done,'atEnd')); - }); + .pipe(gulpFunction(done,'atEnd')) + }) it('should run through smoothly once with ' + "'atFirst'",function(done){ gulp.src('./test/*.md') .pipe(gulpFunction([myFunction2,myFunction3],'forFirst')) .pipe(gulp.dest('./test/result/')) - .pipe(gulpFunction(done,'atEnd')); - }); + .pipe(gulpFunction(done,'atEnd')) + }) it('should run in order',function(done){ - this.timeout(5000); + this.timeout(5000) let stream = gulp.src('./test/*.md') .pipe(gulpFunction([beforeFunction,middleFunction,middleFunction],'atEnd')) .pipe(gulpFunction(function(){ - beautylog.log('stream progressed'); - let done2 = Q.defer(); - done2.resolve(); - return done2.promise; + beautylog.log('stream progressed') + let done2 = Q.defer() + done2.resolve() + return done2.promise },'forEach')) .pipe(gulpFunction(function(){ - beautylog.log('nextStep'); + beautylog.log('nextStep') })) .pipe(gulpFunction(afterFunction,'atEnd')) - .pipe(gulpFunction(timeoutFunction,'atEnd')); + .pipe(gulpFunction(timeoutFunction,'atEnd')) stream.on('finish',function(){ - beautylog.info('stream finished'); - done(); - }); - }); -}); + beautylog.info('stream finished') + done() + }) + }) +}) diff --git a/ts/index.ts b/ts/index.ts index e30f44e..761b311 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -9,7 +9,7 @@ export interface IPromiseFunction { (file?, enc?): PromiseLike } -let mainExportFunction = ( +let defaultExport = ( functionsToExecuteArg: IPromiseFunction | IPromiseFunction[], executionModeArg: TExecutionMode = 'forEach' ): Transform => { @@ -74,4 +74,16 @@ let mainExportFunction = ( return through2.obj(forEach, atEnd) } -export default mainExportFunction +export let forEach = (funcArg: IPromiseFunction) => { + defaultExport(funcArg, 'forEach') +} + +export let forFirst = (funcArg: IPromiseFunction) => { + defaultExport(funcArg, 'forFirst') +} + +export let atEnd = (funcArg: IPromiseFunction) => { + defaultExport(funcArg, 'atEnd') +} + +export default defaultExport