Compare commits

...

52 Commits

Author SHA1 Message Date
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
22 changed files with 491 additions and 180 deletions

4
.gitignore vendored
View File

@ -1,6 +1,10 @@
node_modules/
.settings/
.idea/
coverage/
docs/
public/
pages/
ts/*.js
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/
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: ZgxvXgxlJlDDx4sv2H+M0Z36sZHDKEYRntudQWKLaDt1T2VojfsigNORrDZcHCs6FZo8t2Klsqte8PqDvAn7BxXIo5K86aaZOyulcHnmDQS6rBhJYHm01qJj2B+t03EozcsueYGcQIVyFLBnKl5Yj8GdQ6iVGbimHvgym/Bbo6pKQlKHvv7a+tOSmtRffeG4jZU454MYqc38ZPtKftdknk7m4T0wUP2l9Y1jKva8Zjd4+cw+xOhFAStkySrq8uNBEINN8e5vqvaOxq1d7V8evK7JQLjDtLOaj67cHJ3u7ZjHA2zk1j/Rs7X2jkeqqRbG1zhSHUjjqvnZRzC6ygswOHBBnSzF9P+tN7+jcNcn09PLsKh/HyXq/aRFKsNtvKjUey4cM27yt/LRLis70hrRTgR9EDZ/Q4Aoa/P/ObYf0XDE1rH08nngeASdmGFN+6n6idSq8C7IQ/YfmmQBhIhTSaNSGsYcG827fB5EZLoojCDOuNIrfyMOJHrSy14rgNWiGRj7C0md4yP7qGP53JPU9pPZLzRiD2/y9KuZ4qnE/edj9+POmVCr+uz2ILFQcTkEb9gItfMQGLd5m5MtPHgVFcoslU14O8o5WyFdG80xDHBvyy+1TsqnyRPwwlLwzepqZeUltZKXiOMDRIRurDRC1jtwcf8kJmWboio3GLIdQFU=
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=

View File

@ -1,26 +1,59 @@
# gulp-function
accepts call to execute in gulp pipeline.
### build status/Dependencies
[![Build Status](https://travis-ci.org/pushrocks/gulp-function.svg?branch=v0.0.2)](https://travis-ci.org/pushrocks/gulp-function)
## 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)
[![devDependency Status](https://david-dm.org/pushrocks/gulp-function/dev-status.svg)](https://david-dm.org/pushrocks/gulp-function#info=devDependencies)
[![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
var gulp = require("gulp");
var gulpFunction = require("gulp-function");
import * as gulp from 'gulp';
import gulpFunction from 'gulp-function' // default ES6 export
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
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() {
gulp.src('./mydir/*.something')
.pipe(gulpFunction(myFunction,'forEach'))
.pipe(gulp.dest("./build/"))
let stream = gulp.src('./mydir/*.something')
.pipe(gulpFunction(myFunction,'forEach')) //read the notes below
.pipe(gulp.dest("./build/"));
return stream; // by returning the stream gulp knows when our task has finished.
});
```
>Note: The first argument of gulpFunction can also be an array of multiple functionnames.
>Note: the second argument can be empty (defaults to 'forEach') or 'atEnd'
### 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)

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

@ -0,0 +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;

68
dist/index.js vendored Normal file
View File

@ -0,0 +1,68 @@
"use strict";
require("typings-global");
const q = require("q");
const through2 = require("through2");
let mainExportFunction = (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 q.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);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = mainExportFunction;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBQ3ZCLHVCQUFzQjtBQUN0QixxQ0FBb0M7QUFTcEMsSUFBSSxrQkFBa0IsR0FBRyxDQUNyQixxQkFBNEQsRUFDNUQsZ0JBQWdCLEdBQW1CLFNBQVM7SUFHNUMsSUFBSSxZQUFZLEdBQUcsRUFBRSxDQUFBO0lBQ3JCLElBQUksV0FBVyxHQUFHLFVBQVUsV0FBVyxFQUFFLElBQUksRUFBRSxHQUFHO1FBQzlDLElBQUksV0FBVyxHQUFHLFdBQVcsQ0FBQyxJQUFJLEVBQUUsR0FBRyxDQUFDLENBQUE7UUFDeEMsRUFBRSxDQUFDLENBQUMsT0FBTyxXQUFXLEtBQUssV0FBVyxJQUFJLE9BQU8sV0FBVyxDQUFDLElBQUksS0FBSyxXQUFXLENBQUMsQ0FBQyxDQUFDO1lBQ2hGLFlBQVksQ0FBQyxJQUFJLENBQUMsV0FBVyxDQUFDLENBQUE7UUFDbEMsQ0FBQztJQUNMLENBQUMsQ0FBQTtJQUVELElBQUksbUJBQW1CLEdBQUcsVUFBVSxJQUFJLEVBQUUsR0FBRztRQUN6QyxFQUFFLENBQUMsQ0FBQyxPQUFPLHFCQUFxQixLQUFLLFVBQVUsQ0FBQyxDQUFDLENBQUM7WUFDOUMsV0FBVyxDQUFDLHFCQUFxQixFQUFFLElBQUksRUFBRSxHQUFHLENBQUMsQ0FBQTtRQUNqRCxDQUFDO1FBQUMsSUFBSSxDQUFDLEVBQUUsQ0FBQyxDQUFDLEtBQUssQ0FBQyxPQUFPLENBQUMscUJBQXFCLENBQUMsQ0FBQy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LENBQUMsSUFBSSxFQUFFLElBQUksQ0FBQyxDQUFBO2dCQUNsQixDQUFDO2dCQUNELGVBQWUsR0FBRyxJQUFJLENBQUE7Z0JBQ3RCLEtBQUssQ0FBQTtZQUNULEtBQUssT0FBTztnQkFDUixFQUFFLENBQUMsSUFBSSxFQUFFLElBQUksQ0FBQyxDQUFBO2dCQUNkLEtBQUssQ0FBQTtZQUNUO2dCQUNJLEtBQUssQ0FBQTtRQUNiLENBQUM7SUFDTCxDQUFDLENBQUE7SUFFRCxJQUFJLEtBQUssR0FBRyxVQUFVLEVBQUU7UUFDcEIsRUFBRSxDQUFDLENBQUMsZ0JBQWdCLEtBQUssT0FBTyxDQUFDLENBQUMsQ0FBQztZQUMvQixtQkFBbUIsQ0FBQyxJQUFJLEVBQUUsSUFBSSxDQUFDLENBQUMsSUFBSSxDQUFDO2dCQUNqQyxFQUFFLEVBQUUsQ0FBQTtZQUNSLENBQUMsQ0FBQyxDQUFBO1FBQ04sQ0FBQztRQUFDLElBQUksQ0FBQyxDQUFDO1lBQ0osRUFBRSxFQUFFLENBQUE7UUFDUixDQUFDO0lBQ0wsQ0FBQyxDQUFBO0lBQ0QsTUFBTSxDQUFDLFFBQVEsQ0FBQyxHQUFHLENBQUMsT0FBTyxFQUFFLEtBQUssQ0FBQyxDQUFBO0FBQ3ZDLENBQUMsQ0FBQTs7QUFFRCxrQkFBZSxrQkFBa0IsQ0FBQSJ9

4
index.d.ts vendored
View File

@ -1,4 +0,0 @@
/// <reference path="ts/typings/main.d.ts" />
declare var through: any;
declare var path: any;
declare var beautylog: any;

View File

@ -1,47 +0,0 @@
#!/usr/bin/env node
/// <reference path="typings/main.d.ts" />
var through = require("through2");
var path = require("path");
var beautylog = require("beautylog");
module.exports = function (functionsToExecuteArg, executionModeArg, logBoolArg) {
if (executionModeArg === void 0) { executionModeArg = 'forEach'; }
if (logBoolArg === void 0) { logBoolArg = false; }
//important vars
var gulpFunction = {
executionMode: executionModeArg,
functionsToExecute: functionsToExecuteArg,
logBool: logBoolArg
};
var runFunctionNames = function () {
if (typeof gulpFunction.functionsToExecute == "function") {
gulpFunction.functionsToExecute();
}
else if (Array.isArray(gulpFunction.functionsToExecute)) {
for (var anyFunction in gulpFunction.functionsToExecute) {
anyFunction();
}
}
else {
beautylog.error('gulp-callfunction: something is strange with the given arguments');
}
};
var forEach = function (file, enc, cb) {
if (gulpFunction.logBool)
beautylog.log(gulpFunction.executionMode);
if (gulpFunction.executionMode === 'forEach') {
if (gulpFunction.logBool)
beautylog.log('is forEach');
runFunctionNames();
}
//tell gulp that we are complete
return cb(null, file);
};
var atEnd = function (cb) {
if (gulpFunction.executionMode == "atEnd") {
runFunctionNames();
}
cb();
};
return through.obj(forEach, atEnd);
};

5
npmextra.json Normal file
View File

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

View File

@ -1,8 +1,9 @@
{
"name": "gulp-function",
"version": "1.0.0",
"version": "2.1.0",
"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": "(npmts)",
"reinstall": "(rm -r node_modules && npm install)",
@ -11,24 +12,30 @@
},
"repository": {
"type": "git",
"url": "https://github.com/pushrocks/gulp-function.git"
"url": "https://gitlab.com/pushrocks/gulp-function.git"
},
"keywords": [
"gulpplugin",
"gulp",
"function"
],
"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-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": {
"beautylog": "2.0.4",
"through2": "2.0.0"
"@types/q": "0.0.32",
"@types/through2": "^2.0.31",
"q": "^1.4.1",
"through2": "^2.0.1",
"typings-global": "^1.0.14"
},
"devDependencies": {
"gulp": "^3.9.0"
"beautylog": "^6.0.0",
"gulp": "^3.9.1",
"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

1
test/test.js.map Normal file
View File

@ -0,0 +1 @@
{"version":3,"file":"test.js","sourceRoot":"","sources":["test.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,IAAI,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAC3B,IAAI,YAAY,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;AAC/C,IAAI,SAAS,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;AACrC,IAAI,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;AAErB,IAAI,UAAU,GAAG;IACb,IAAI,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,CAAA;IACpB,SAAS,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IACnC,IAAI,CAAC,OAAO,EAAE,CAAC;IACf,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC;AACxB,CAAC,CAAC;AACF,IAAI,WAAW,GAAG;IACd,IAAI,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC;IACrB,SAAS,CAAC,EAAE,CAAC,oBAAoB,CAAC,CAAC;IACnC,IAAI,CAAC,OAAO,EAAE,CAAC;IACf,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC;AACxB,CAAC,CAAC;AACF,IAAI,WAAW,GAAG;IACd,IAAI,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC;IACrB,SAAS,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC;IACxC,IAAI,CAAC,OAAO,EAAE,CAAC;IACf,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC;AACxB,CAAC,CAAC;AAEF,IAAI,cAAc,GAAG;IACjB,IAAI,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC;IACrB,SAAS,C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AAE,CAAC,qBAAqB,EAAC,UAAS,IAAI;QAClC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACnB,IAAI,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC;aAC/B,IAAI,CAAC,YAAY,CAAC,CAAC,cAAc,EAAC,cAAc,EAAC,cAAc,CAAC,EAAC,OAAO,CAAC,CAAC;aAC1E,IAAI,CAAC,YAAY,CAAC;YACf,SAAS,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;YACnC,IAAI,KAAK,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC;YACtB,KAAK,CAAC,OAAO,EAAE,CAAC;YAChB,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC;QACzB,CAAC,EAAC,SAAS,CAAC,CAAC;aACZ,IAAI,CAAC,YAAY,CAAC;YACf,SAAS,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QAC9B,CAAC,CAAC,CAAC;aACF,IAAI,CAAC,YAAY,CAAC,aAAa,EAAC,OAAO,CAAC,CAAC;aACzC,IAAI,CAAC,YAAY,CAAC,eAAe,EAAC,OAAO,CAAC,CAAC,CAAC;QAEjD,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAC;YACf,SAAS,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;YAClC,IAAI,EAAE,CAAC;QACX,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}

118
test/test.ts Normal file
View File

@ -0,0 +1,118 @@
import 'typings-test'
let gulp = require('gulp');
import gulpFunction from '../dist/index'
let beautylog = require('beautylog')
let Q = require('q')
let myFunction = function () {
let done = Q.defer()
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 myFunction3 = function () {
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 middleFunctionRun = false;
let middleFunction = function () {
let done = Q.defer();
beautylog.success('middleFunction executed');
setTimeout(function(){
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 timeoutFunction = function(){
let done = Q.defer();
setTimeout(function(){
beautylog.log('largeTimeout fired');
done.resolve();
},2000);
return done.promise;
};
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/'));
gulp.src('./test/*.md')
.pipe(gulpFunction([myFunction2,myFunction3],'forEach'))
.pipe(gulp.dest('./test/result/'))
.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/'));
gulp.src('./test/*.md')
.pipe(gulpFunction([myFunction2,myFunction3],'atEnd'))
.pipe(gulp.dest('./test/result/'))
.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'));
});
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');
let done2 = Q.defer();
done2.resolve();
return done2.promise;
},'forEach'))
.pipe(gulpFunction(function(){
beautylog.log('nextStep');
}))
.pipe(gulpFunction(afterFunction,'atEnd'))
.pipe(gulpFunction(timeoutFunction,'atEnd'));
stream.on('finish',function(){
beautylog.info('stream finished');
done();
});
});
});

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,45 +1,77 @@
/// <reference path="typings/main.d.ts" />
var through = require("through2");
var path = require("path");
var beautylog = require("beautylog");
import 'typings-global'
import * as q from 'q'
import * as through2 from 'through2'
import { Transform } from 'stream'
export type TExecutionMode = 'forEach' | 'forFirst' | 'atEnd'
module.exports = function (functionsToExecuteArg:any|any[],executionModeArg:string = 'forEach', logBoolArg = false) {
//important vars
var gulpFunction = {
executionMode: executionModeArg, //can be forEach or atEnd
functionsToExecute: functionsToExecuteArg,
logBool: logBoolArg
};
export interface IPromiseFunction {
(file?, enc?): PromiseLike<any>
}
var runFunctionNames = function () {
if (typeof gulpFunction.functionsToExecute == "function" ) {
gulpFunction.functionsToExecute();
} else if (Array.isArray(gulpFunction.functionsToExecute)) {
for (var anyFunction in gulpFunction.functionsToExecute) {
anyFunction();
let mainExportFunction = (
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 {
beautylog.error('gulp-callfunction: something is strange with the given arguments');
throw new Error('gulp-callfunction: something is strange with the given arguments')
}
};
return q.all(promiseArray)
}
var forEach = function (file, enc, cb) {
if (gulpFunction.logBool) beautylog.log(gulpFunction.executionMode);
if (gulpFunction.executionMode === 'forEach') {
if(gulpFunction.logBool) beautylog.log('is forEach');
runFunctionNames();
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
}
//tell gulp that we are complete
return cb(null, file);
};
}
var atEnd = function(cb) {
if (gulpFunction.executionMode == "atEnd") {
runFunctionNames();
let atEnd = function (cb) {
if (executionModeArg === 'atEnd') {
checkAndRunFunction(null, null).then(function () {
cb()
})
} else {
cb()
}
cb();
};
return through.obj(forEach,atEnd);
};
}
return through2.obj(forEach, atEnd)
}
export default mainExportFunction

View File

@ -1,20 +0,0 @@
/// <reference path="typings/main.d.ts" />
var gulp = require("gulp");
var gulpFunction = require("../index.js");
var beautylog = require("beautylog");
var myFunction = function () {
beautylog.log("Mocha Test successfull!");
};
describe("gulpFunction",function(){
it("should run through smoothly",function(){
gulp.task('default',function() {
gulp.src('./test/test.md')
.pipe(gulpFunction(myFunction,'forEach'))
.pipe(gulp.dest("./test/result/"))
});
gulp.start.apply(gulp, ['default']);
});
});

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"
}