Compare commits

..

85 Commits

Author SHA1 Message Date
0d772e8ab0 2.2.4 2017-04-30 00:44:14 +02:00
a324deb942 clean up 2017-04-30 00:44:11 +02:00
cb60bec110 2.2.3 2016-12-04 21:33:05 +01:00
291583b17a update tests 2016-12-04 21:32:56 +01:00
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
99db113285 1.2.2 2016-04-04 22:43:38 +02:00
844812311e fix Readme issue 2016-04-04 22:43:26 +02:00
555c696a8e 1.2.1 2016-04-04 22:39:24 +02:00
879248f049 update deps and update coverage badge to use codecov.io 2016-04-04 22:39:18 +02:00
bb607eca9b fixes #3 and removes beautylog dependency 2016-04-04 22:32:30 +02:00
f094f80531 1.2.0 2016-03-26 17:23:00 +01:00
71bdcce41d added forFirst 2016-03-26 17:22:46 +01:00
5a9cd96bed update badges 2016-02-14 19:01:24 +01:00
0f659ad60a add Version badges 2016-02-14 18:58:59 +01:00
395cb7d8a2 1.1.1 2016-02-14 18:42:55 +01:00
6284fa71d1 update promise 2016-02-14 18:42:45 +01:00
c5ec5fc0f9 1.1.0 2016-02-14 18:40:45 +01:00
17aa25fb61 update README 2016-02-14 18:40:37 +01:00
6e55ed3162 now accepts promises as return of supplied functions 2016-02-14 18:36:34 +01:00
ac9305c480 1.0.4 2016-02-12 05:41:06 +01:00
a51419f2b0 add npmts.json 2016-02-12 05:41:02 +01:00
4b02d17d6d 1.0.3 2016-02-12 05:36:31 +01:00
57350d6fee add better tests and coverage 2016-02-12 05:36:23 +01:00
dcdf0059cc 1.0.2 2016-02-02 15:21:45 +01:00
9cc9e15b04 update deps 2016-02-02 15:21:27 +01:00
6a19698617 1.0.1 2016-02-01 03:45:38 +01:00
bc53520869 update travis 2016-02-01 03:45:13 +01:00
752dec8fea update npmts 2016-02-01 03:43:29 +01:00
ffc12d3fd5 1.0.0 2016-02-01 03:40:45 +01:00
0c0f0b78e1 update keywords 2016-02-01 03:40:30 +01:00
3d01801df6 0.0.12 2016-02-01 03:35:23 +01:00
5355fd4e83 update package.json 2016-02-01 03:35:09 +01:00
27a97c1bde cleanup 2016-02-01 03:33:33 +01:00
c1f1500ffc 0.0.10 2015-11-30 09:49:58 +01:00
e42c5004c2 updated structure 2015-11-30 09:49:52 +01:00
e0c4a10411 0.0.9 2015-11-24 13:51:07 +01:00
6deab0541f update deps 2015-11-24 13:49:02 +01:00
22e3dc6136 0.0.8 2015-11-24 13:44:38 +01:00
e69e8df875 fix:added callback to function() atEnd 2015-11-24 13:44:32 +01:00
4cb24a4a6d add dev dependency badge 2015-10-26 16:25:08 +01:00
ebac042791 0.0.7 2015-10-26 16:22:29 +01:00
d8fc992ba3 0.0.6 2015-10-26 16:21:33 +01:00
82def89388 0.0.5 2015-10-26 16:20:49 +01:00
4b832bbf95 added automatic version release through travis for npm 2015-10-26 16:20:41 +01:00
cf8182b86a 0.0.4 2015-10-26 16:18:52 +01:00
c708f964ec added test 2015-10-26 16:18:37 +01:00
f9c4fb9887 small fix 2015-10-25 22:46:22 +01:00
c6c352f587 0.0.3 2015-10-25 22:45:57 +01:00
3930912f25 now working 2015-10-25 22:45:49 +01:00
b6a6c62962 added gitignore 2015-10-25 20:02:14 +01:00
e43c627307 add Readme 2015-09-17 21:06:35 +00:00
22 changed files with 1664 additions and 2153 deletions

13
.gitignore vendored Normal file
View File

@ -0,0 +1,13 @@
node_modules/
.settings/
.idea/
coverage/
docs/
public/
pages/
ts/*.js
ts/*.js.map
ts/typings/
test/result/

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

5
.npmignore Normal file
View File

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

View File

@ -1,19 +0,0 @@
language: node_js
before_install:
- nvm install stable
- node -v
- npm -v
- npm install -g gulp
- npm install gulp
- npm install gulp-typescript
deploy:
provider: npm
email: npm@smart-coordination.com
api_key:
secure: AcM6ooFjEIaWOC84QMxxugV3GtkMEoMI6zxy4oB9u9xihLopVZnm6c8FxIr+Wl2Ykjwj2deOuC7Q7QLtfH8/n4cVj1x7c32DJ21XJsE6uGm2opT7bSMm/NgcIvbkzWdPSyG8OpJEu8l///+YTceLdLV2Tn4lPobZRgu0KIF3Pg0Fo2V/0kSH/gSjlbLBgMBx1QrO2y52VHMdqWs3VwMIv1lEEicUsbnBg1z03I/Ka+JZQPCDYGgHu7y62zgB36mdkNVg8pyvGrrTSWeMVyHc8SSvBoqszVUeXfs4d4tcw0+vPsIJD5hDzAGOtH+3KO2Bgi87UB/Dgd5xw92+zQxhKnKewFiyTvANFXoag5UooPupWKhu5DljZ27CkgLX/N/AF6eTuQR0ffW92Bvz2YWis5JC75+HGFV2tBI7hRinScc00J0vOAqqVpp81PD6BXQDX2y5y77arArJVQTC5irOYL20x3UMBB7fOpTkYV9T2NxzR6OBv4P6MLWPbnmFr+zpjkzBxHeJMOosb+9W6TAbVmouM5SfnFU5bBYh2gF52Yz2FnfpDzclVZW/OI0YcAtIdozbHRcJ1s6pVkPqZIqKcCM+jVhzvt8NTnehSOqjFyIV9rcbsYQplLs8b9ntmcuRLCPatXMGFQM/y9Sjw4is0gHhRMjxQo32bfIiX1CTqVo=
on:
tags: true
repo: pushrocks/gulp-callfunction
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=

61
README.md Normal file
View File

@ -0,0 +1,61 @@
# gulp-function
accepts call to execute in gulp pipeline.
## Availabililty
[![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)
[![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)
[![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/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
### Usage
```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
let done = Q.defer();
console.log("Hello World!")
// NOTE:
// you can use done.resolve as callback function
// of any async tasks within this function
done.resolve();
return done.promise;
}
gulp.task('gulpTest',function() {
let stream = gulp.src('./mydir/*.something')
.pipe(gulpFunction(myFunction,'forEach')) //read the notes below
// .pipe(forEach(myFunction)) // if imported as >> import { forEach } from 'gulp-function' <<
.pipe(gulp.dest("./build/"));
return stream; // by returning the stream gulp knows when our task has finished.
});
```
### Notes:
* 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.
When providing an array of functions be careful with modifying the file object -> race condition
* 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.
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;
* "atEnd" - executes after all chunks have passed and are processed in full.
That means the stream's "finish" event fires **before "atLast" is executed**!!!
[![npm](https://push.rocks/assets/repo-header.svg)](https://push.rocks)

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;

76
dist/index.js vendored Normal file
View File

@ -0,0 +1,76 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("typings-global");
const through2 = require("through2");
let defaultExport = (functionsToExecuteArg, executionModeArg = 'forEach') => {
let promiseArray = [];
let runFunction = function (functionArg, file, enc) {
let returnValue = functionArg(file, enc);
if (typeof returnValue !== 'undefined' && typeof returnValue.then !== 'undefined') {
promiseArray.push(returnValue);
}
};
let checkAndRunFunction = function (file, enc) {
if (typeof functionsToExecuteArg === 'function') {
runFunction(functionsToExecuteArg, file, enc);
}
else if (Array.isArray(functionsToExecuteArg)) {
for (let anyFunction in functionsToExecuteArg) {
runFunction(functionsToExecuteArg[anyFunction], file, enc);
}
}
else {
throw new Error('gulp-callfunction: something is strange with the given arguments');
}
return Promise.all(promiseArray);
};
let hasExecutedOnce = false;
let forEach = function (file, enc, cb) {
switch (executionModeArg) {
case 'forEach':
checkAndRunFunction(file, enc).then(function () {
cb(null, file);
});
break;
case 'forFirst':
if (hasExecutedOnce) {
checkAndRunFunction(file, enc)
.then(function () {
cb(null, file);
});
}
else {
cb(null, file);
}
hasExecutedOnce = true;
break;
case 'atEnd':
cb(null, file);
break;
default:
break;
}
};
let atEnd = function (cb) {
if (executionModeArg === 'atEnd') {
checkAndRunFunction(null, null).then(function () {
cb();
});
}
else {
cb();
}
};
return through2.obj(forEach, atEnd);
};
exports.forEach = (funcArg) => {
return defaultExport(funcArg, 'forEach');
};
exports.forFirst = (funcArg) => {
return defaultExport(funcArg, 'forFirst');
};
exports.atEnd = (funcArg) => {
return defaultExport(funcArg, 'atEnd');
};
exports.default = defaultExport;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDBCQUF1QjtBQUV2QixxQ0FBb0M7QUFTcEMsSUFBSSxhQUFhLEdBQUcsQ0FDbEIscUJBQTRELEVBQzVELG1CQUFtQyxTQUFTO0lBRzVDLElBQUksWUFBWSxHQUFHLEVBQUUsQ0FBQTtJQUNyQixJQUFJLFdBQVcsR0FBRyxVQUFVLFdBQVcsRUFBRSxJQUFJLEVBQUUsR0FBRztRQUNoRCxJQUFJLFdBQVcsR0FBRyxXQUFXLENBQUMsSUFBSSxFQUFFLEdBQUcsQ0FBQyxDQUFBO1FBQ3hDLEVBQUUsQ0FBQyxDQUFDLE9BQU8sV0FBVyxLQUFLLFdBQVcsSUFBSSxPQUFPLFdBQVcsQ0FBQyxJQUFJLEtBQUssV0FBVyxDQUFDLENBQUMsQ0FBQztZQUNsRixZQUFZLENBQUMsSUFBSSxDQUFDLFdBQVcsQ0FBQyxDQUFBO1FBQ2hDLENBQUM7SUFDSCxDQUFDLENBQUE7SUFFRCxJQUFJLG1CQUFtQixHQUFHLFVBQVUsSUFBSSxFQUFFLEdBQUc7UUFDM0MsRUFBRSxDQUFDLENBQUMsT0FBTyxxQkFBcUIsS0FBSyxVQUFVLENBQUMsQ0FBQyxDQUFDO1lBQ2hELFdBQVcsQ0FBQyxxQkFBcUIsRUFBRSxJQUFJLEVBQUUsR0FBRyxDQUFDLENBQUE7UUFDL0MsQ0FBQztRQUFDLElBQUksQ0FBQyxFQUFFLENBQUMsQ0FBQyxLQUFLLENBQUMsT0FBTyxDQUFDLHFCQUFxQixDQUFDLENBQUMs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NLENBQUMsYUFBYSxDQUFDLE9BQU8sRUFBRSxPQUFPLENBQUMsQ0FBQTtBQUN4QyxDQUFDLENBQUE7QUFFRCxrQkFBZSxhQUFhLENBQUEifQ==

5
npmextra.json Normal file
View File

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

View File

@ -1,24 +1,39 @@
{ {
"name": "gulp-callfunction", "name": "gulp-function",
"version": "0.0.2", "version": "2.2.4",
"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": "dist/index.js",
"typings": "dist/index.d.ts",
"scripts": { "scripts": {
"test": "cd ts/compile && gulp" "test": "(npmts)",
"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)"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/pushrocks/gulp-callfunction.git" "url": "https://gitlab.com/pushrocks/gulp-function.git"
}, },
"keywords": [ "keywords": [
"json", "gulpplugin",
"jade", "gulp",
"template" "function"
], ],
"author": "Smart Coordination GmbH <office@push.rocks> (https://push.rocks)", "author": "Lossless GmbH <office@lossless.com> (https://lossless.com)",
"license": "MIT", "license": "MIT",
"bugs": { "bugs": {
"url": "https://github.com/pushrocks/gulp-callfunction/issues" "url": "https://gitlab.com/pushrocks/gulp-function/issues"
}, },
"homepage": "https://github.com/pushrocks/gulp-callfunction" "homepage": "https://gitlab.com/pushrocks/gulp-function",
"dependencies": {
"@types/through2": "^2.0.32",
"smartq": "^1.1.1",
"through2": "^2.0.3",
"typings-global": "^1.0.16"
},
"devDependencies": {
"beautylog": "^6.1.10",
"gulp": "^3.9.1",
"tapbundle": "^1.0.10"
}
} }

2
test/README.md Normal file
View File

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

34
test/test.ts Normal file
View File

@ -0,0 +1,34 @@
import { expect, tap } from 'tapbundle'
let gulp = require('gulp')
import * as gulpFunction from '../dist/index'
import * as beautylog from 'beautylog'
let smartq = require('smartq')
tap.test('should run through smoothly with ' + "'forEach'", async (tools) => {
let done = smartq.defer()
let counter = 0
gulp.src('./test/*.md')
.pipe(gulpFunction.forEach(async () => {
counter++
if (counter === 2) {
done.resolve()
}
}))
await done.promise
})
tap.test('should run through smoothly with ' + "'forEach'", async (tools) => {
let done = smartq.defer()
let counter = 0
gulp.src('./test/*.md')
.pipe(gulpFunction.atEnd(async () => {
console.log('atEnd')
done.resolve()
}))
await done.promise
})
tap.start()

2
test/test01.md Normal file
View File

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

2
test/test02.md Normal file
View File

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

View File

@ -1,2 +0,0 @@
nvm use v0.12.7
gulp

View File

@ -1,16 +0,0 @@
// import gulp
var gulp = require("gulp"),
gulpTypescript = require("gulp-typescript");
gulp.task('compileTS', function() {
var stream = gulp.src('../index.ts')
.pipe(gulpTypescript({
out: "index.js"
}))
.pipe(gulp.dest("../../"));
return stream;
});
gulp.task('default',['compileTS'], function() {
console.log('Typescript compiled');
});

View File

@ -1,2 +0,0 @@
# How to compile.
Make sure gulp and gulp-taypescript from npm are available. Then run the gulpfile in this directory.

View File

@ -1,14 +1,89 @@
/// <reference path="typings/tsd.d.ts" /> import 'typings-global'
var path, through; import * as q from 'smartq'
import * as through2 from 'through2'
import { Transform } from 'stream'
through = require("through2"); export type TExecutionMode = 'forEach' | 'forFirst' | 'atEnd'
path = require("path");
module.exports = (jsonObject,type = undefined) => { export interface IPromiseFunction {
(file?, enc?): PromiseLike<any>
}
return through.obj((file, enc, cb) => { let defaultExport = (
//tell gulp that we are complete functionsToExecuteArg: IPromiseFunction | IPromiseFunction[],
return cb(null, file); executionModeArg: TExecutionMode = 'forEach'
}); ): Transform => {
};
let promiseArray = []
let runFunction = function (functionArg, file, enc) {
let returnValue = functionArg(file, enc)
if (typeof returnValue !== 'undefined' && typeof returnValue.then !== 'undefined') {
promiseArray.push(returnValue)
}
}
let checkAndRunFunction = function (file, enc) {
if (typeof functionsToExecuteArg === 'function') {
runFunction(functionsToExecuteArg, file, enc)
} else if (Array.isArray(functionsToExecuteArg)) {
for (let anyFunction in functionsToExecuteArg) {
runFunction(functionsToExecuteArg[ anyFunction ], file, enc)
}
} else {
throw new Error('gulp-callfunction: something is strange with the given arguments')
}
return Promise.all(promiseArray)
}
let hasExecutedOnce = false
let forEach = function (file, enc, cb) { // the forEach function is called for every chunk
switch (executionModeArg) {
case 'forEach':
checkAndRunFunction(file, enc).then(function () {
cb(null, file)
})
break
case 'forFirst':
if (hasExecutedOnce) {
checkAndRunFunction(file, enc)
.then(function () {
cb(null, file)
})
} else {
cb(null, file)
}
hasExecutedOnce = true
break
case 'atEnd':
cb(null, file)
break
default:
break
}
}
let atEnd = function (cb) {
if (executionModeArg === 'atEnd') {
checkAndRunFunction(null, null).then(function () {
cb()
})
} else {
cb()
}
}
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,12 +0,0 @@
{
"version": "v4",
"repo": "borisyankov/DefinitelyTyped",
"ref": "master",
"path": "typings",
"bundle": "typings/tsd.d.ts",
"installed": {
"node/node.d.ts": {
"commit": "efa0c1196d7280640e624ac1e7fa604502e7bd63"
}
}
}

File diff suppressed because it is too large Load Diff

1
ts/typings/tsd.d.ts vendored
View File

@ -1 +0,0 @@
/// <reference path="node/node.d.ts" />

3
tslint.json Normal file
View File

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

1284
yarn.lock Normal file

File diff suppressed because it is too large Load Diff