Compare commits

..

35 Commits

Author SHA1 Message Date
9d54da207f 2.2.2 2016-11-25 11:21:59 +01:00
7aad993847 improve README 2016-11-25 11:21:55 +01:00
c208f04e23 2.2.1 2016-11-25 11:19:16 +01:00
54d8ef2576 fixed .forEach return 2016-11-25 11:19:12 +01:00
8b891c74e4 2.2.0 2016-10-19 07:36:42 +02:00
1d8de68a66 add .forEach .atEnd .forFirst 2016-10-19 07:36:32 +02:00
a2b37a066d 2.1.0 2016-10-19 01:11:06 +02:00
8a2c516274 switched to ES6 default import 2016-10-19 01:10:45 +02:00
e10c31c740 2.0.2 2016-10-19 00:47:33 +02:00
af68a92702 improve README 2016-10-19 00:47:29 +02:00
a8c3fa048a 2.0.1 2016-10-19 00:44:06 +02:00
bea33fa29f fix base image for CI 2016-10-19 00:39:34 +02:00
739542bda1 2.0.0 2016-10-19 00:35:46 +02:00
63cf7091a1 add possibility to modify the file object 2016-10-19 00:35:41 +02:00
04d7f9cf7e 1.3.6 2016-06-11 23:06:29 +02:00
afc9fd122f update gitlab-yml 2016-06-11 21:41:16 +02:00
a3dec7bb8a now using npmts-g 2016-06-11 21:36:21 +02:00
0e725c3fb4 1.3.5 2016-06-04 01:26:11 +02:00
6cd0ee78a3 update README and remove travis 2016-06-04 01:25:55 +02:00
b037dc99df 1.3.4 2016-06-04 01:22:26 +02:00
27439d84cd fix missing dependency 2016-06-04 01:22:20 +02:00
ada13619d0 1.3.3 2016-06-04 01:15:54 +02:00
9ae1a40260 add gitlab ci 2016-06-04 01:15:48 +02:00
e19184e29b 1.3.2 2016-06-04 01:14:30 +02:00
36e02502d0 update dependencies 2016-06-04 01:14:25 +02:00
75219a5474 1.3.1 2016-04-07 13:56:23 +02:00
8f0ecb3f4a added beautylog back as dev dependency 2016-04-07 13:56:09 +02:00
ec18663137 1.3.0 2016-04-07 13:50:12 +02:00
a476cf8c99 fixed package.json 2016-04-07 13:50:00 +02:00
5af3185742 1.2.5 2016-04-05 00:59:22 +02:00
81849dc5eb updated deps 2016-04-05 00:59:21 +02:00
51b9088d3e 1.2.4 2016-04-05 00:27:13 +02:00
375b43a11c update deps 2016-04-05 00:27:08 +02:00
5b0a1edaa4 1.2.3 2016-04-04 22:55:10 +02:00
855e9b48c8 update deps 2016-04-04 22:55:06 +02:00
19 changed files with 381 additions and 300 deletions

2
.gitignore vendored
View File

@ -3,6 +3,8 @@ node_modules/
.idea/ .idea/
coverage/ coverage/
docs/ docs/
public/
pages/
ts/*.js ts/*.js
ts/*.js.map ts/*.js.map

53
.gitlab-ci.yml Normal file
View File

@ -0,0 +1,53 @@
image: hosttoday/ht-docker-node:npmts
stages:
- test
- release
- trigger
- pages
testLEGACY:
stage: test
script:
- npmci test legacy
tags:
- docker
allow_failure: true
testLTS:
stage: test
script:
- npmci test lts
tags:
- docker
testSTABLE:
stage: test
script:
- npmci test stable
tags:
- docker
release:
stage: release
script:
- npmci publish
only:
- tags
tags:
- docker
trigger:
stage: trigger
script:
- npmci trigger
only:
- tags
tags:
- docker
pages:
image: hosttoday/ht-docker-node:npmpage
stage: pages
script:
- npmci command npmpage --host gitlab
only:
- tags
artifacts:
expire_in: 1 week
paths:
- public

View File

@ -1,3 +1,5 @@
ts/ ts/
test/ test/
docs/
coverage/
node_modules/ node_modules/

View File

@ -1,14 +0,0 @@
language: node_js
node_js:
- 4.2.4
deploy:
provider: npm
email: npm@lossless.digital
api_key:
secure: TWN/oiICeNbAhGTbwf75FnKhXnIvyA66FhNF7C0jpjn2SChSgTANai87r0f9oU9ZP3307XdGHB+fTTCJnk3upNiBoWZnkV8skkAlseOY4mVzF9mS0ZEkxVR32FjJDWfqzv6hC+Y9qNDsGs2+Avsm6fQUOispLXYAk6VzSQC1HgIfyOJtIWT5LqEyXyT6oJIZ7xwt1CYcIeEpHUiAaPYsMEpwF5OBDFByVmNV38VdRGIBsoQd3lixso7/zOOgYvjR4b/onz5WzeWYlhzAuyzOnRGr1r/9eXAzzkYydvgFx3ix5OlrreKVFB6OtMpz4jmHdu9YDGT5bcvL2bSU2SGVQM5Bx8zZXkAxACQR8ZvWmPaWYAWCu9wrW5oovjqFUV0iR26z/sTABJqz4GaXf/vFcll2EdTfUT6xj2kCodfxljaudjPUF27FSt1UJBC7jQky08wHb6+onrE8WoQXteIE2oxtHWEGOlV/GAz0+q4ih0bdOSKfThmux0iEFmeF16sWH9UdL2jBBKuus+fBPdhA3V6uwYQtsCAurhquQLISkf7kT3KujdLS302bEbkut+D1Kd22IYA1J0wYd87th88TZHx7wgQyC+8lVHG+B1R20xGLxyHVEOfyZtChfBRdn53EcUiA2XriJbfiIym4dAMUtOg2iRJamHAL7jebQEUu7oA=
on:
tags: true
repo: pushrocks/gulp-function
notifications:
slack:
secure: Bb8P3fboL52CugSsp0RhOkGCeWVbgjb+QDpnMHdSOa0Nequj8V4kvrzBLZOBOjaSB0/gMvdoB4Slv2bls1dAxXW1IX1DdRb3RLMKj/Owje7eTd4IoUuSs49y6/yEkVK+E1wicdwjlMmvsk8fQE/owDRMRXYoXxhN2ZOVSQvAQ3iBO0eokFvWO7yj/VSxKoITymCXA3LfyzXXUuhvxuQd3BPZCe25xa6GWuHtaa5fbJg17pp8jJX6VZYLSRcSYyJxMU8SLdkrOsQZKj0+/Yfpu7XTmPbqxjNapuE7Zm70mi+aB26IQCnmwkdcEQNJVxQOKoP2+/ZnDfcTLQROwH1PJVzol0hneH6DdOlWt9bvBJcUvFRwaDgIb5xXQV8bGsRe5ayE/4MgCgfvdBTvevu6n12fmPx74prIv4pOPMwlALjjP8XavGL4A6amOuV7fJiSyGAku8aUe1rlUXyfoHJswMyOfkIsvnGDE3eEfq1WUIjn8tW1ZozJyoCTAIh6IHPI3Nsg3LkTRvDHPYq25/xCKWxGb2OaJc3JeqVREqm0auDqj6HoVAi/mW/uyvwX9jEVX8fNoQ69ac5VUMFfn2Mx3sU6aHKgZe/tdrtql6NYtIA+g5/ZDnHE1mnbl6MfrYiKwRbrICH5v/u1xK+4+yh09BUqazi3PzOhyTRfba/gRUg=

View File

@ -1,25 +1,31 @@
# gulp-function # gulp-function
accepts call to execute in gulp pipeline. accepts call to execute in gulp pipeline.
### Status ## Availabililty
[![Build Status](https://travis-ci.org/pushrocks/gulp-function.svg?branch=v0.0.2)](https://travis-ci.org/pushrocks/gulp-function) [![npm](https://push.rocks/assets/repo-button-npm.svg)](https://www.npmjs.com/package/gulp-function)
[![git](https://push.rocks/assets/repo-button-git.svg)](https://gitlab.com/pushrocks/gulp-function)
[![git](https://push.rocks/assets/repo-button-mirror.svg)](https://github.com/pushrocks/gulp-function)
[![docs](https://push.rocks/assets/repo-button-docs.svg)](https://pushrocks.gitlab.io/gulp-function/)
## Status for master
[![build status](https://gitlab.com/pushrocks/gulp-function/badges/master/build.svg)](https://gitlab.com/pushrocks/gulp-function/commits/master)
[![coverage report](https://gitlab.com/pushrocks/gulp-function/badges/master/coverage.svg)](https://gitlab.com/pushrocks/gulp-function/commits/master)
[![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)
[![bitHound Dependencies](https://www.bithound.io/github/pushrocks/gulp-function/badges/dependencies.svg)](https://www.bithound.io/github/pushrocks/gulp-function/master/dependencies/npm) [![bitHound Dependencies](https://www.bithound.io/github/pushrocks/gulp-function/badges/dependencies.svg)](https://www.bithound.io/github/pushrocks/gulp-function/master/dependencies/npm)
[![bitHound Code](https://www.bithound.io/github/pushrocks/gulp-function/badges/code.svg)](https://www.bithound.io/github/pushrocks/gulp-function) [![bitHound Code](https://www.bithound.io/github/pushrocks/gulp-function/badges/code.svg)](https://www.bithound.io/github/pushrocks/gulp-function)
[![codecov.io](https://codecov.io/github/pushrocks/gulp-function/coverage.svg?branch=master)](https://codecov.io/github/pushrocks/gulp-function?branch=master) [![TypeScript](https://img.shields.io/badge/TypeScript-2.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%206.x.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
### Version [![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
[![GitHub version](https://badge.fury.io/gh/pushrocks%2Fgulp-function.svg)](https://badge.fury.io/gh/pushrocks%2Fgulp-function)
[![npm version](https://badge.fury.io/js/gulp-function.svg)](https://badge.fury.io/js/gulp-function)
### Usage ### Usage
```javascript ```javascript
var gulp = require("gulp"); import * as gulp from 'gulp';
var gulpFunction = require("gulp-function"); import gulpFunction from 'gulp-function' // default ES6 export
var Q = require("q"); // import {forFirst, forEach, atEnd} from 'gulp-function'
let Q = require("q");
var myFunction = function () { let myFunction = function (file, enc) { // file and enc are optional in case you want to modify the file object
var done = Q.defer(); let done = Q.defer();
console.log("Hello World!") console.log("Hello World!")
// NOTE: // NOTE:
@ -31,8 +37,9 @@ var myFunction = function () {
} }
gulp.task('gulpTest',function() { gulp.task('gulpTest',function() {
var stream = gulp.src('./mydir/*.something') let stream = gulp.src('./mydir/*.something')
.pipe(gulpFunction(myFunction,'forEach')) //read the notes below .pipe(gulpFunction(myFunction,'forEach')) //read the notes below
// .pipe(forEach(myFunction)) // if imported as >> import { forEach } from 'gulp-function' <<
.pipe(gulp.dest("./build/")); .pipe(gulp.dest("./build/"));
return stream; // by returning the stream gulp knows when our task has finished. return stream; // by returning the stream gulp knows when our task has finished.
}); });
@ -41,11 +48,14 @@ gulp.task('gulpTest',function() {
### Notes: ### Notes:
* The first argument of gulpFunction can also be an **array of multiple functionnames**. * The first argument of gulpFunction can also be an **array of multiple functionnames**.
Each function can return a promise. the pipe stop will finish when every promise is fullfilled. Each function can return a promise. The pipe stop will finish when every promise is fullfilled.
* the second argument can be empty, it defaults to "forEach" When providing an array of functions be careful with modifying the file object -> race condition
* the following options are available: * The second argument can be empty, it defaults to "forEach"
* The following options are available:
* "forFirst" - executes when first chunk/vinylfile of the stream reaches the pipestop. * "forFirst" - executes when first chunk/vinylfile of the stream reaches the pipestop.
file is pushed further down the line when function's returned promise is fullfilled. file is pushed further down the line when function's returned promise is fullfilled.
* "forEach" - executes like "forFirst" but with every chunk/vinylfile in the stream; * "forEach" - executes like "forFirst" but with every chunk/vinylfile in the stream;
* "atEnd" - executes after all chunks have passed and are processed in full. * "atEnd" - executes after all chunks have passed and are processed in full.
That means the stream's "finish" event fires **before "atLast" is executed**!!! That means the stream's "finish" event fires **before "atLast" is executed**!!!
[![npm](https://push.rocks/assets/repo-header.svg)](https://push.rocks)

View File

@ -1,6 +0,0 @@
/// <reference path="typings/main.d.ts" />
"use strict";
exports.Q = require("q");
exports.through2 = require("through2");
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImd1bHBmdW5jdGlvbi5wbHVnaW5zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLDBDQUEwQzs7QUFFL0IsU0FBQyxHQUFHLE9BQU8sQ0FBQyxHQUFHLENBQUMsQ0FBQztBQUNqQixnQkFBUSxHQUFHLE9BQU8sQ0FBQyxVQUFVLENBQUMsQ0FBQyIsImZpbGUiOiJndWxwZnVuY3Rpb24ucGx1Z2lucy5qcyIsInNvdXJjZXNDb250ZW50IjpbIi8vLyA8cmVmZXJlbmNlIHBhdGg9XCJ0eXBpbmdzL21haW4uZC50c1wiIC8+XG5cbmV4cG9ydCBsZXQgUSA9IHJlcXVpcmUoXCJxXCIpO1xuZXhwb3J0IGxldCB0aHJvdWdoMiA9IHJlcXVpcmUoXCJ0aHJvdWdoMlwiKTtcbiJdLCJzb3VyY2VSb290IjoiL3NvdXJjZS8ifQ==

12
dist/index.d.ts vendored Normal file
View File

@ -0,0 +1,12 @@
/// <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 defaultExport: (functionsToExecuteArg: IPromiseFunction | IPromiseFunction[], executionModeArg?: TExecutionMode) => Transform;
export declare let forEach: (funcArg: IPromiseFunction) => Transform;
export declare let forFirst: (funcArg: IPromiseFunction) => Transform;
export declare let atEnd: (funcArg: IPromiseFunction) => Transform;
export default defaultExport;

81
dist/index.js vendored

File diff suppressed because one or more lines are too long

5
npmextra.json Normal file
View File

@ -0,0 +1,5 @@
{
"npmts": {
"mode": "default"
}
}

View File

@ -1,4 +0,0 @@
{
"mode":"default",
"coveralls":true
}

View File

@ -1,8 +1,9 @@
{ {
"name": "gulp-function", "name": "gulp-function",
"version": "1.2.2", "version": "2.2.2",
"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": "dist/index.js", "main": "dist/index.js",
"typings": "dist/index.d.ts",
"scripts": { "scripts": {
"test": "(npmts)", "test": "(npmts)",
"reinstall": "(rm -r node_modules && npm install)", "reinstall": "(rm -r node_modules && npm install)",
@ -11,7 +12,7 @@
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/pushrocks/gulp-function.git" "url": "https://gitlab.com/pushrocks/gulp-function.git"
}, },
"keywords": [ "keywords": [
"gulpplugin", "gulpplugin",
@ -21,16 +22,20 @@
"author": "Lossless GmbH <office@lossless.com> (https://lossless.com)", "author": "Lossless GmbH <office@lossless.com> (https://lossless.com)",
"license": "MIT", "license": "MIT",
"bugs": { "bugs": {
"url": "https://github.com/pushrocks/gulp-function/issues" "url": "https://gitlab.com/pushrocks/gulp-function/issues"
}, },
"homepage": "https://github.com/pushrocks/gulp-function", "homepage": "https://gitlab.com/pushrocks/gulp-function",
"dependencies": { "dependencies": {
"beautylog": "^3.1.2", "@types/q": "0.0.32",
"@types/through2": "^2.0.31",
"q": "^1.4.1", "q": "^1.4.1",
"through2": "^2.0.1" "through2": "^2.0.1",
"typings-global": "^1.0.14"
}, },
"devDependencies": { "devDependencies": {
"beautylog": "^6.0.0",
"gulp": "^3.9.1", "gulp": "^3.9.1",
"npmts": "^4.0.2" "npmts-g": "^5.2.8",
"typings-test": "^1.0.3"
} }
} }

1
test/test.d.ts vendored Normal file
View File

@ -0,0 +1 @@
import 'typings-test';

File diff suppressed because one or more lines are too long

View File

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

View File

@ -1,4 +0,0 @@
/// <reference path="typings/main.d.ts" />
export let Q = require("q");
export let through2 = require("through2");

View File

@ -1,65 +1,89 @@
/// <reference path="typings/main.d.ts" /> import 'typings-global'
import * as q from 'q'
import * as through2 from 'through2'
import { Transform } from 'stream'
import plugins = require("./gulpfunction.plugins"); export type TExecutionMode = 'forEach' | 'forFirst' | 'atEnd'
export interface IPromiseFunction {
(file?, enc?): PromiseLike<any>
}
let defaultExport = (
functionsToExecuteArg: IPromiseFunction | IPromiseFunction[],
executionModeArg: TExecutionMode = 'forEach'
): Transform => {
let promiseArray = []
module.exports = function (functionsToExecuteArg:any|any[],executionModeArg:string = 'forEach') { let runFunction = function (functionArg, file, enc) {
//important vars let returnValue = functionArg(file, enc)
let executionMode = executionModeArg; //can be forEach or atEnd if (typeof returnValue !== 'undefined' && typeof returnValue.then !== 'undefined') {
let functionsToExecute = functionsToExecuteArg; promiseArray.push(returnValue)
let promiseArray = [];
let runFunction = function(functionArg){
let returnValue = functionArg();
if (typeof returnValue !== "undefined" && typeof returnValue.then !== "undefined") {
promiseArray.push(returnValue);
} }
}; }
let checkAndRunFunction = function () { let checkAndRunFunction = function (file, enc) {
if (typeof functionsToExecute === "function" ) { if (typeof functionsToExecuteArg === 'function') {
runFunction(functionsToExecute); runFunction(functionsToExecuteArg, file, enc)
} else if (Array.isArray(functionsToExecute)) { } else if (Array.isArray(functionsToExecuteArg)) {
for (let anyFunction in functionsToExecute) { for (let anyFunction in functionsToExecuteArg) {
runFunction(functionsToExecute[anyFunction]); runFunction(functionsToExecuteArg[anyFunction], file, enc)
} }
} else { } else {
throw new Error("gulp-callfunction: something is strange with the given arguments"); throw new Error('gulp-callfunction: something is strange with the given arguments')
} }
return plugins.Q.all(promiseArray); return q.all(promiseArray)
}; }
let hasExecutedOnce = false; let hasExecutedOnce = false
let forEach = function (file, enc, cb) { //the forEach function is called for every chunk let forEach = function (file, enc, cb) { // the forEach function is called for every chunk
switch (executionMode){ switch (executionModeArg) {
case "forEach": case 'forEach':
checkAndRunFunction().then(function(){ checkAndRunFunction(file, enc).then(function () {
cb(null, file); cb(null, file)
}); })
break; break
case "forFirst": case 'forFirst':
!hasExecutedOnce ? checkAndRunFunction().then(function(){ if (hasExecutedOnce) {
cb(null, file); checkAndRunFunction(file, enc)
}) : cb(null, file); .then(function () {
hasExecutedOnce = true; cb(null, file)
break; })
case "atEnd": } else {
cb(null, file); cb(null, file)
break; }
hasExecutedOnce = true
break
case 'atEnd':
cb(null, file)
break
default: default:
break; break
} }
}; }
let atEnd = function(cb) { let atEnd = function (cb) {
if (executionMode === "atEnd") { if (executionModeArg === 'atEnd') {
checkAndRunFunction().then(function(){ checkAndRunFunction(null, null).then(function () {
cb(); cb()
}); })
} else { } else {
cb(); cb()
} }
}; }
return plugins.through2.obj(forEach,atEnd); return through2.obj(forEach, atEnd)
}; }
export let forEach = (funcArg: IPromiseFunction) => {
return defaultExport(funcArg, 'forEach')
}
export let forFirst = (funcArg: IPromiseFunction) => {
return defaultExport(funcArg, 'forFirst')
}
export let atEnd = (funcArg: IPromiseFunction) => {
return defaultExport(funcArg, 'atEnd')
}
export default defaultExport

View File

@ -1,15 +0,0 @@
{
"version": "v4",
"repo": "borisyankov/DefinitelyTyped",
"ref": "master",
"path": "typings",
"bundle": "typings/tsd.d.ts",
"installed": {
"node/node.d.ts": {
"commit": "efa0c1196d7280640e624ac1e7fa604502e7bd63"
},
"colors/colors.d.ts": {
"commit": "3191f6e0088eee07c4d8fd24e4d27a40a60d9eb9"
}
}
}

View File

@ -1,7 +0,0 @@
{
"ambientDependencies": {
"node": "github:DefinitelyTyped/DefinitelyTyped/node/node.d.ts",
"mocha": "github:Bartvds/tsd-deftools/typings/DefinitelyTyped/mocha/mocha.d.ts",
"colors": "github:DefinitelyTyped/DefinitelyTyped/colors/colors.d.ts"
}
}

3
tslint.json Normal file
View File

@ -0,0 +1,3 @@
{
"extends": "tslint-config-standard"
}