switched to ES6 default import

This commit is contained in:
Philipp Kunz 2016-10-19 01:10:45 +02:00
parent e10c31c740
commit 8a2c516274
7 changed files with 118 additions and 110 deletions

View File

@ -19,8 +19,8 @@ accepts call to execute in gulp pipeline.
### Usage
```javascript
let gulp = require("gulp");
let gulpFunction = require("gulp-function");
import * as gulp from 'gulp';
import gulpFunction from 'gulp-function' // default ES6 export
let Q = require("q");
let myFunction = function (file, enc) { // file and enc are optional in case you want to modify the file object

4
dist/index.d.ts vendored
View File

@ -1,5 +1,9 @@
/// <reference types="node" />
import 'typings-global';
import { Transform } from 'stream';
export declare type TExecutionMode = 'forEach' | 'forFirst' | 'atEnd';
export interface IPromiseFunction {
(file?: any, enc?: any): PromiseLike<any>;
}
declare let mainExportFunction: (functionsToExecuteArg: IPromiseFunction | IPromiseFunction[], executionModeArg?: TExecutionMode) => Transform;
export default mainExportFunction;

6
dist/index.js vendored
View File

@ -2,7 +2,7 @@
require("typings-global");
const q = require("q");
const through2 = require("through2");
module.exports = (functionsToExecuteArg, executionModeArg = 'forEach') => {
let mainExportFunction = (functionsToExecuteArg, executionModeArg = 'forEach') => {
let promiseArray = [];
let runFunction = function (functionArg, file, enc) {
let returnValue = functionArg(file, enc);
@ -63,4 +63,6 @@ module.exports = (functionsToExecuteArg, executionModeArg = 'forEach') => {
};
return through2.obj(forEach, atEnd);
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBQ3ZCLHVCQUFzQjtBQUN0QixxQ0FBb0M7QUFTcEMsTUFBTSxDQUFDLE9BQU8sR0FBRyxDQUNiLHFCQUE0RCxFQUM1RCxnQkFBZ0IsR0FBbUIsU0FBUztJQUc1QyxJQUFJLFlBQVksR0FBRyxFQUFFLENBQUE7SUFDckIsSUFB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sQ0FBQyxDQUFDO1lBQy9CLG1CQUFtQixDQUFDLElBQUksRUFBRSxJQUFJLENBQUMsQ0FBQyxJQUFJLENBQUM7Z0JBQ2pDLEVBQUUsRUFBRSxDQUFBO1lBQ1IsQ0FBQyxDQUFDLENBQUE7UUFDTixDQUFDO1FBQUMsSUFBSSxDQUFDLENBQUM7WUFDSixFQUFFLEVBQUUsQ0FBQTtRQUNSLENBQUM7SUFDTCxDQUFDLENBQUE7SUFDRCxNQUFNLENBQUMsUUFBUSxDQUFDLEdBQUcsQ0FBQyxPQUFPLEVBQUUsS0FBSyxDQUFDLENBQUE7QUFDdkMsQ0FBQyxDQUFBIn0=
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = mainExportFunction;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBQ3ZCLHVCQUFzQjtBQUN0QixxQ0FBb0M7QUFTcEMsSUFBSSxrQkFBa0IsR0FBRyxDQUNyQixxQkFBNEQsRUFDNUQsZ0JBQWdCLEdBQW1CLFNBQVM7SUFHNUMsSUFBSSxZQUFZLEdBQUcsRUFBRSxDQUFBO0lBQ3JCLElBQUksV0FBVyxHQUFHLFVBQVUsV0FBVyxFQUFFLElBQUksRUFBRSxHQUFHO1FBQzlDLElBQUksV0FBVyxHQUFHLFdBQVcsQ0FBQyxJQUFJLEVBQUUsR0FBRyxDQUFDLENBQUE7UUFDeEMsRUFBRSxDQUFDLENBQUMsT0FBTyxXQUFXLEtBQUssV0FBVyxJQUFJLE9BQU8sV0FBVyxDQUFDLElBQUksS0FBSyxXQUFXLENBQUMsQ0FBQyxDQUFDO1lBQ2hGLFlBQVksQ0FBQyxJQUFJLENBQUMsV0FBVyxDQUFDLENBQUE7UUFDbEMsQ0FBQztJQU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kFBZSxrQkFBa0IsQ0FBQSJ9

2
test/test.d.ts vendored
View File

@ -1 +1 @@
import "typings-test";
import 'typings-test';

File diff suppressed because one or more lines are too long

View File

@ -1,59 +1,59 @@
import "typings-test"
var gulp = require("gulp");
var gulpFunction = require("../dist/index.js");
var beautylog = require("beautylog");
var Q = require("q");
import 'typings-test'
let gulp = require('gulp');
import gulpFunction from '../dist/index'
let beautylog = require('beautylog')
let Q = require('q')
var myFunction = function () {
var done = Q.defer()
beautylog.log("Function executed");
let myFunction = function () {
let done = Q.defer()
beautylog.log('Function executed');
done.resolve();
return done.promise;
};
var myFunction2 = function () {
var done = Q.defer();
beautylog.ok("Function2 executed");
let myFunction2 = function () {
let done = Q.defer();
beautylog.ok('Function2 executed');
done.resolve();
return done.promise;
};
var myFunction3 = function () {
var done = Q.defer();
beautylog.success("Function3 executed");
let myFunction3 = function () {
let done = Q.defer();
beautylog.success('Function3 executed');
done.resolve();
return done.promise;
};
var beforeFunction = function () {
var done = Q.defer();
beautylog.success("beforeFunction executed");
let beforeFunction = function () {
let done = Q.defer();
beautylog.success('beforeFunction executed');
done.resolve();
return done.promise;
};
var middleFunctionRun = false;
let middleFunctionRun = false;
var middleFunction = function () {
var done = Q.defer();
beautylog.success("middleFunction executed");
let middleFunction = function () {
let done = Q.defer();
beautylog.success('middleFunction executed');
setTimeout(function(){
beautylog.log("timeout fired");
beautylog.log('timeout fired');
middleFunctionRun = true;
done.resolve();
}, 500);
return done.promise;
};
var afterFunction = function () {
var done = Q.defer();
beautylog.success("afterFunction executed");
let afterFunction = function () {
let done = Q.defer();
beautylog.success('afterFunction executed');
done.resolve();
return done.promise;
};
let timeoutFunction = function(){
var done = Q.defer();
let done = Q.defer();
setTimeout(function(){
beautylog.log("largeTimeout fired");
beautylog.log('largeTimeout fired');
done.resolve();
},2000);
return done.promise;
@ -61,56 +61,56 @@ let timeoutFunction = function(){
describe("gulpFunction",function(){
it("should run through smoothly with " + "'forEach'".blue,function(done){
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(gulp.dest('./test/result/'))
.pipe(gulpFunction(done,'atEnd'));
});
it("should run through smoothly with " + "'atEnd'".blue,function(done){
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(gulp.dest('./test/result/'))
.pipe(gulpFunction(done,'atEnd'));
});
it("should run through smoothly once with " + "'atFirst'".blue,function(done){
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(gulp.dest('./test/result/'))
.pipe(gulpFunction(done,'atEnd'));
});
it("should run in order",function(done){
it('should run in order',function(done){
this.timeout(5000);
let stream = gulp.src('./test/*.md')
.pipe(gulpFunction([beforeFunction,middleFunction,middleFunction],'atEnd'))
.pipe(gulpFunction(function(){
beautylog.log("stream progressed");
var done2 = Q.defer();
beautylog.log('stream progressed');
let done2 = Q.defer();
done2.resolve();
return done2.promise;
},"forEach"))
},'forEach'))
.pipe(gulpFunction(function(){
beautylog.log("nextStep");
beautylog.log('nextStep');
}))
.pipe(gulpFunction(afterFunction,"atEnd"))
.pipe(gulpFunction(timeoutFunction,"atEnd"));
.pipe(gulpFunction(afterFunction,'atEnd'))
.pipe(gulpFunction(timeoutFunction,'atEnd'));
stream.on("finish",function(){
beautylog.info("stream finished");
stream.on('finish',function(){
beautylog.info('stream finished');
done();
});
});

View File

@ -9,7 +9,7 @@ export interface IPromiseFunction {
(file?, enc?): PromiseLike<any>
}
module.exports = (
let mainExportFunction = (
functionsToExecuteArg: IPromiseFunction | IPromiseFunction[],
executionModeArg: TExecutionMode = 'forEach'
): Transform => {
@ -73,3 +73,5 @@ module.exports = (
}
return through2.obj(forEach, atEnd)
}
export default mainExportFunction