Compare commits

..

105 Commits

Author SHA1 Message Date
c39a4a6cb0 2.2.14 2018-01-29 23:54:02 +01:00
f325479a11 update ci 2018-01-29 23:53:58 +01:00
c79f443c18 2.2.13 2018-01-29 23:30:12 +01:00
14bb4a90bb update README 2018-01-29 23:30:09 +01:00
98a583bae1 2.2.12 2018-01-29 23:28:06 +01:00
848d9ac1e0 update to latest standards 2018-01-29 23:28:03 +01:00
e7ccd9aec4 2.2.11 2017-10-27 12:49:45 +02:00
63bf7204dd update 2017-10-27 12:49:43 +02:00
a34a1b89fe 2.2.10 2017-09-07 22:33:43 +02:00
f4455a9b91 update dependencies 2017-09-07 22:33:40 +02:00
1a01198d7f 2.2.9 2017-04-30 17:28:18 +02:00
b3ec364a1d 2.2.8 2017-04-30 17:23:26 +02:00
5d15c96511 update docs and .gitignore 2017-04-30 17:23:22 +02:00
f6e071156b 2.2.7 2017-04-30 17:11:50 +02:00
63fe7c7423 update README 2017-04-30 17:11:40 +02:00
c8dcdc0df4 update README 2017-04-30 17:11:19 +02:00
743c7a03a5 2.2.6 2017-04-30 01:07:35 +02:00
f9e7bf450b now cleans pipe correctly 2017-04-30 01:07:30 +02:00
b55a511fcb 2.2.5 2017-04-30 00:45:23 +02:00
96c15cb90a update ci 2017-04-30 00:45:19 +02:00
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
38 changed files with 2228 additions and 2152 deletions

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
node_modules/
coverage/
public/
pages/

96
.gitlab-ci.yml Normal file
View File

@ -0,0 +1,96 @@
# gitzone standard
image: hosttoday/ht-docker-node:npmci
cache:
paths:
- .yarn/
key: "$CI_BUILD_STAGE"
stages:
- mirror
- security
- test
- release
- trigger
- pages
mirror:
stage: mirror
script:
- npmci git mirror
tags:
- docker
security:
stage: security
script:
- npmci command yarn global add snyk
- npmci command yarn install --ignore-scripts
- npmci command snyk test
tags:
- docker
testLEGACY:
stage: test
script:
- npmci node install legacy
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
allow_failure: true
testLTS:
stage: test
script:
- npmci node install lts
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
testSTABLE:
stage: test
script:
- npmci node install stable
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
release:
stage: release
script:
- npmci npm prepare
- npmci npm publish
only:
- tags
tags:
- docker
trigger:
stage: trigger
script:
- npmci trigger
only:
- tags
tags:
- docker
pages:
image: hosttoday/ht-docker-node:npmci
stage: pages
script:
- npmci command yarn global add npmpage
- npmci command npmpage
tags:
- docker
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=

63
README.md Normal file
View File

@ -0,0 +1,63 @@
# gulp-function
accepts a function call as parameter to execute in gulp pipeline
## Availabililty
[![npm](https://pushrocks.gitlab.io/assets/repo-button-npm.svg)](https://www.npmjs.com/package/gulp-function)
[![git](https://pushrocks.gitlab.io/assets/repo-button-git.svg)](https://GitLab.com/pushrocks/gulp-function)
[![git](https://pushrocks.gitlab.io/assets/repo-button-mirror.svg)](https://github.com/pushrocks/gulp-function)
[![docs](https://pushrocks.gitlab.io/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)
[![npm downloads per month](https://img.shields.io/npm/dm/gulp-function.svg)](https://www.npmjs.com/package/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 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
```typescript
import gulp = require('gulp');
import gulpFunction from "gulp-function"; // default ES6 export
// import {forFirst, forEach, atEnd} from 'gulp-function'
let myAsyncFunction = async (file, enc) => {
// await some async stuff
};
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**!!!
For further information read the linked docs at the top of this README.
> MIT licensed | **&copy;** [Lossless GmbH](https://lossless.gmbh)
> | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://push.rocks)

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

@ -0,0 +1,11 @@
/// <reference types="node" />
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 });
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) {
// 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();
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) => {
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xFQUFFLE9BQU8sQ0FBQyxDQUFDO0FBQ3pDLENBQUMsQ0FBQztBQUVGLGtCQUFlLGFBQWEsQ0FBQyJ9

10
npmextra.json Normal file
View File

@ -0,0 +1,10 @@
{
"npmts": {
"mode": "default"
},
"npmci": {
"npmGlobalTools": [
"npmts"
]
}
}

View File

@ -1,24 +1,36 @@
{
"name": "gulp-callfunction",
"version": "0.0.2",
"name": "gulp-function",
"version": "2.2.14",
"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": {
"test": "cd ts/compile && gulp"
"test": "(npmts)"
},
"repository": {
"type": "git",
"url": "https://github.com/pushrocks/gulp-callfunction.git"
"url": "https://gitlab.com/pushrocks/gulp-function.git"
},
"keywords": [
"json",
"jade",
"template"
"gulpplugin",
"gulp",
"function",
"pushrocks"
],
"author": "Smart Coordination GmbH <office@push.rocks> (https://push.rocks)",
"author": "Lossless GmbH <office@lossless.com> (https://lossless.com)",
"license": "MIT",
"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.6",
"through2": "^2.0.3"
},
"devDependencies": {
"gulp": "^3.9.1",
"smartgulp": "^1.0.1",
"tapbundle": "^1.0.10"
}
}

2
test/README.md Normal file
View File

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

33
test/test.ts Normal file
View File

@ -0,0 +1,33 @@
import { expect, tap } from 'tapbundle'
import * as smartgulp from 'smartgulp'
let gulp = require('gulp')
import * as gulpFunction from '../ts/index'
let smartq = require('smartq')
tap.test('should run through smoothly with ' + "'forEach'", async (tools) => {
let done = smartq.defer()
let counter = 0
gulp.src('./test/testfiles/*.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
smartgulp.src(['./test/testfiles/*.md'])
.pipe(gulpFunction.atEnd(async () => {
console.log('atEnd')
done.resolve()
}))
await done.promise
})
tap.start()

1
test/testfiles/test01.md Normal file
View File

@ -0,0 +1 @@
# the 1st testfile

1
test/testfiles/test02.md Normal file
View File

@ -0,0 +1 @@
# the second testfile

1
test/testfiles/test03.md Normal file
View File

@ -0,0 +1 @@
# the third testfile

1
test/testfiles/test04.md Normal file
View File

@ -0,0 +1 @@
# the fourth testfile

1
test/testfiles/test05.md Normal file
View File

@ -0,0 +1 @@
# the fifth testfile

1
test/testfiles/test06.md Normal file
View File

@ -0,0 +1 @@
# the sixth testfile

1
test/testfiles/test07.md Normal file
View File

@ -0,0 +1 @@
# the seventh testfile

1
test/testfiles/test08.md Normal file
View File

@ -0,0 +1 @@
# the eighth testfile

1
test/testfiles/test09.md Normal file
View File

@ -0,0 +1 @@
# the nineth testfile

1
test/testfiles/test10.md Normal file
View File

@ -0,0 +1 @@
# the tenth testfile

1
test/testfiles/test11.md Normal file
View File

@ -0,0 +1 @@
# the eleventh testfile

1
test/testfiles/test12.md Normal file
View File

@ -0,0 +1 @@
# the twelveth testfile

1
test/testfiles/test13.md Normal file
View File

@ -0,0 +1 @@
# the second testfile

1
test/testfiles/test14.md Normal file
View File

@ -0,0 +1 @@
# the second testfile

1
test/testfiles/test15.md Normal file
View File

@ -0,0 +1 @@
# the second testfile

1
test/testfiles/test16.md Normal file
View File

@ -0,0 +1 @@
# the second testfile

1
test/testfiles/test17.md Normal file
View File

@ -0,0 +1 @@
# the second testfile

1
test/testfiles/test18.md Normal file
View File

@ -0,0 +1 @@
# the 18th testfile

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,92 @@
/// <reference path="typings/tsd.d.ts" />
var path, through;
import * as q from "smartq";
import * as through2 from "through2";
import { Transform } from "stream";
through = require("through2");
path = require("path");
export type TExecutionMode = "forEach" | "forFirst" | "atEnd";
module.exports = (jsonObject,type = undefined) => {
export interface IPromiseFunction {
(file?, enc?): PromiseLike<any>;
}
return through.obj((file, enc, cb) => {
//tell gulp that we are complete
return cb(null, file);
});
let defaultExport = (
functionsToExecuteArg: IPromiseFunction | IPromiseFunction[],
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();
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"
}

1795
yarn.lock Normal file

File diff suppressed because it is too large Load Diff