Compare commits
55 Commits
Author | SHA1 | Date | |
---|---|---|---|
b55a511fcb | |||
96c15cb90a | |||
0d772e8ab0 | |||
a324deb942 | |||
cb60bec110 | |||
291583b17a | |||
9d54da207f | |||
7aad993847 | |||
c208f04e23 | |||
54d8ef2576 | |||
8b891c74e4 | |||
1d8de68a66 | |||
a2b37a066d | |||
8a2c516274 | |||
e10c31c740 | |||
af68a92702 | |||
a8c3fa048a | |||
bea33fa29f | |||
739542bda1 | |||
63cf7091a1 | |||
04d7f9cf7e | |||
afc9fd122f | |||
a3dec7bb8a | |||
0e725c3fb4 | |||
6cd0ee78a3 | |||
b037dc99df | |||
27439d84cd | |||
ada13619d0 | |||
9ae1a40260 | |||
e19184e29b | |||
36e02502d0 | |||
75219a5474 | |||
8f0ecb3f4a | |||
ec18663137 | |||
a476cf8c99 | |||
5af3185742 | |||
81849dc5eb | |||
51b9088d3e | |||
375b43a11c | |||
5b0a1edaa4 | |||
855e9b48c8 | |||
99db113285 | |||
844812311e | |||
555c696a8e | |||
879248f049 | |||
bb607eca9b | |||
f094f80531 | |||
71bdcce41d | |||
5a9cd96bed | |||
0f659ad60a | |||
395cb7d8a2 | |||
6284fa71d1 | |||
c5ec5fc0f9 | |||
17aa25fb61 | |||
6e55ed3162 |
3
.gitignore
vendored
3
.gitignore
vendored
@ -2,6 +2,9 @@ node_modules/
|
||||
.settings/
|
||||
.idea/
|
||||
coverage/
|
||||
docs/
|
||||
public/
|
||||
pages/
|
||||
|
||||
ts/*.js
|
||||
ts/*.js.map
|
||||
|
71
.gitlab-ci.yml
Normal file
71
.gitlab-ci.yml
Normal file
@ -0,0 +1,71 @@
|
||||
# gitzone standard
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
|
||||
cache:
|
||||
paths:
|
||||
- .yarn/
|
||||
key: "$CI_BUILD_STAGE"
|
||||
|
||||
stages:
|
||||
- test
|
||||
- release
|
||||
- trigger
|
||||
- pages
|
||||
|
||||
testLEGACY:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test legacy
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
allow_failure: true
|
||||
|
||||
testLTS:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test lts
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
|
||||
testSTABLE:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test stable
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
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:npmci
|
||||
stage: pages
|
||||
script:
|
||||
- npmci command yarn global add npmpage
|
||||
- npmci command npmpage
|
||||
tags:
|
||||
- docker
|
||||
only:
|
||||
- tags
|
||||
artifacts:
|
||||
expire_in: 1 week
|
||||
paths:
|
||||
- public
|
@ -1,3 +1,5 @@
|
||||
ts/
|
||||
test/
|
||||
docs/
|
||||
coverage/
|
||||
node_modules/
|
||||
|
14
.travis.yml
14
.travis.yml
@ -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=
|
55
README.md
55
README.md
@ -1,28 +1,61 @@
|
||||
# gulp-function
|
||||
accepts call to execute in gulp pipeline.
|
||||
|
||||
### Status
|
||||
[](https://travis-ci.org/pushrocks/gulp-function)
|
||||
## Availabililty
|
||||
[](https://www.npmjs.com/package/gulp-function)
|
||||
[](https://gitlab.com/pushrocks/gulp-function)
|
||||
[](https://github.com/pushrocks/gulp-function)
|
||||
[](https://pushrocks.gitlab.io/gulp-function/)
|
||||
|
||||
## Status for master
|
||||
[](https://gitlab.com/pushrocks/gulp-function/commits/master)
|
||||
[](https://gitlab.com/pushrocks/gulp-function/commits/master)
|
||||
[](https://david-dm.org/pushrocks/gulp-function)
|
||||
[](https://david-dm.org/pushrocks/gulp-function#info=devDependencies)
|
||||
[](https://www.bithound.io/github/pushrocks/gulp-function/master/dependencies/npm)
|
||||
[](https://www.bithound.io/github/pushrocks/gulp-function)
|
||||
[](https://coveralls.io/github/pushrocks/gulp-function?branch=master)
|
||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||
[](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
|
||||
// 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
|
||||
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')
|
||||
let stream = gulp.src('./mydir/*.something')
|
||||
.pipe(gulpFunction(myFunction,'forEach')) //read the notes below
|
||||
.pipe(gulp.dest("./build/"))
|
||||
// .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.
|
||||
});
|
||||
```
|
||||
|
||||
>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**!!!
|
||||
|
||||
[](https://push.rocks)
|
||||
|
12
dist/index.d.ts
vendored
Normal file
12
dist/index.d.ts
vendored
Normal 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
76
dist/index.js
vendored
Normal 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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDBCQUF1QjtBQUV2QixxQ0FBb0M7QUFTcEMsSUFBSSxhQUFhLEdBQUcsQ0FDbEIscUJBQTRELEVBQzVELG1CQUFtQyxTQUFTO0lBRzVDLElBQUksWUFBWSxHQUFHLEVBQUUsQ0FBQTtJQUNyQixJQUFJLFdBQVcsR0FBRyxVQUFVLFdBQVcsRUFBRSxJQUFJLEVBQUUsR0FBRztRQUNoRCxJQUFJLFdBQVcsR0FBRyxXQUFXLENBQUMsSUFBSSxFQUFFLEdBQUcsQ0FBQyxDQUFBO1FBQ3hDLEVBQUUsQ0FBQyxDQUFDLE9BQU8sV0FBVyxLQUFLLFdBQVcsSUFBSSxPQUFPLFdBQVcsQ0FBQyxJQUFJLEtBQUssV0FBVyxDQUFDLENBQUMsQ0FBQztZQUNsRixZQUFZLENBQUMsSUFBSSxDQUFDLFdBQVcsQ0FBQyxDQUFBO1FBQ2hDLENBQUM7SUFDSCxDQUFDLENBQUE7SUFFRCxJQUFJLG1CQUFtQixHQUFHLFVBQVUsSUFBSSxFQUFFLEdBQUc7UUFDM0MsRUFBRSxDQUFDLENBQUMsT0FBTyxxQkFBcUIsS0FBSyxVQUFVLENBQUMsQ0FBQyxDQUFDO1lBQ2hELFdBQVcsQ0FBQyxxQkFBcUIsRUFB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FBTSxDQUFDLGFBQWEsQ0FBQyxPQUFPLEVBQUUsVUFBVSxDQUFDLENBQUE7QUFDM0MsQ0FBQyxDQUFBO0FBRVUsUUFBQSxLQUFLLEdBQUcsQ0FBQyxPQUF5QjtJQUMzQyxNQUFNLENBQUMsYUFBYSxDQUFDLE9BQU8sRUFBRSxPQUFPLENBQUMsQ0FBQTtBQUN4QyxDQUFDLENBQUE7QUFFRCxrQkFBZSxhQUFhLENBQUEifQ==
|
4
index.d.ts
vendored
4
index.d.ts
vendored
@ -1,4 +0,0 @@
|
||||
/// <reference path="ts/typings/main.d.ts" />
|
||||
declare var through: any;
|
||||
declare var path: any;
|
||||
declare var beautylog: any;
|
41
index.js
41
index.js
@ -1,41 +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) {
|
||||
if (executionModeArg === void 0) { executionModeArg = 'forEach'; }
|
||||
//important vars
|
||||
var gulpFunction = {
|
||||
executionMode: executionModeArg,
|
||||
functionsToExecute: functionsToExecuteArg
|
||||
};
|
||||
var runFunctionNames = function () {
|
||||
if (typeof gulpFunction.functionsToExecute === "function") {
|
||||
gulpFunction.functionsToExecute();
|
||||
}
|
||||
else if (Array.isArray(gulpFunction.functionsToExecute)) {
|
||||
for (var anyFunction in gulpFunction.functionsToExecute) {
|
||||
gulpFunction.functionsToExecute[anyFunction]();
|
||||
}
|
||||
}
|
||||
else {
|
||||
beautylog.error('gulp-callfunction: something is strange with the given arguments');
|
||||
}
|
||||
};
|
||||
var forEach = function (file, enc, cb) {
|
||||
if (gulpFunction.executionMode === '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);
|
||||
};
|
10
npmextra.json
Normal file
10
npmextra.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"npmts": {
|
||||
"mode": "default"
|
||||
},
|
||||
"npmci": {
|
||||
"globalNpmTools": [
|
||||
"npmts"
|
||||
]
|
||||
}
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"mode":"default",
|
||||
"coveralls":true
|
||||
}
|
22
package.json
22
package.json
@ -1,8 +1,9 @@
|
||||
{
|
||||
"name": "gulp-function",
|
||||
"version": "1.0.4",
|
||||
"version": "2.2.5",
|
||||
"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,25 +12,28 @@
|
||||
},
|
||||
"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.1.1",
|
||||
"through2": "2.0.1"
|
||||
"@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",
|
||||
"npmts": "^2.2.3"
|
||||
"tapbundle": "^1.0.10"
|
||||
}
|
||||
}
|
||||
|
6
test/test.d.ts
vendored
6
test/test.d.ts
vendored
@ -1,6 +0,0 @@
|
||||
/// <reference path="ts/typings/main.d.ts" />
|
||||
declare var gulp: any;
|
||||
declare var gulpFunction: any;
|
||||
declare var beautylog: any;
|
||||
declare var myFunction: () => void;
|
||||
declare var myFunction2: () => void;
|
30
test/test.js
30
test/test.js
@ -1,30 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/// <reference path="typings/main.d.ts" />
|
||||
var gulp = require("gulp");
|
||||
var gulpFunction = require("../index.js");
|
||||
var beautylog = require("beautylog");
|
||||
var myFunction = function () {
|
||||
beautylog.log("Function executed");
|
||||
};
|
||||
var myFunction2 = function () {
|
||||
beautylog.log("Function2 executed");
|
||||
};
|
||||
describe("gulpFunction", function () {
|
||||
it("should run through smoothly with " + "'forEach'".blue, function () {
|
||||
gulp.src('./test/*.md')
|
||||
.pipe(gulpFunction(myFunction, 'forEach'))
|
||||
.pipe(gulp.dest("./test/result/"));
|
||||
gulp.src('./test/*.md')
|
||||
.pipe(gulpFunction([myFunction, myFunction2], 'forEach'))
|
||||
.pipe(gulp.dest("./test/result/"));
|
||||
});
|
||||
it("should run through smoothly with " + "'atEnd'".blue, function () {
|
||||
gulp.src('./test/*.md')
|
||||
.pipe(gulpFunction(myFunction, 'atEnd'))
|
||||
.pipe(gulp.dest("./test/result/"));
|
||||
gulp.src('./test/*.md')
|
||||
.pipe(gulpFunction([myFunction, myFunction2], 'atEnd'))
|
||||
.pipe(gulp.dest("./test/result/"));
|
||||
});
|
||||
});
|
34
test/test.ts
Normal file
34
test/test.ts
Normal 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()
|
115
ts/index.ts
115
ts/index.ts
@ -1,42 +1,89 @@
|
||||
/// <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 'smartq'
|
||||
import * as through2 from 'through2'
|
||||
import { Transform } from 'stream'
|
||||
|
||||
export type TExecutionMode = 'forEach' | 'forFirst' | 'atEnd'
|
||||
|
||||
module.exports = function (functionsToExecuteArg:any|any[],executionModeArg:string = 'forEach') {
|
||||
//important vars
|
||||
var gulpFunction = {
|
||||
executionMode: executionModeArg, //can be forEach or atEnd
|
||||
functionsToExecute: functionsToExecuteArg
|
||||
};
|
||||
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) {
|
||||
gulpFunction.functionsToExecute[anyFunction]();
|
||||
}
|
||||
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 {
|
||||
beautylog.error('gulp-callfunction: something is strange with the given arguments');
|
||||
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)
|
||||
}
|
||||
|
||||
var forEach = function (file, enc, cb) {
|
||||
if (gulpFunction.executionMode === 'forEach') {
|
||||
runFunctionNames();
|
||||
}
|
||||
//tell gulp that we are complete
|
||||
return cb(null, file);
|
||||
};
|
||||
export let forEach = (funcArg: IPromiseFunction) => {
|
||||
return defaultExport(funcArg, 'forEach')
|
||||
}
|
||||
|
||||
var atEnd = function(cb) {
|
||||
if (gulpFunction.executionMode === "atEnd") {
|
||||
runFunctionNames();
|
||||
}
|
||||
cb();
|
||||
};
|
||||
return through.obj(forEach,atEnd);
|
||||
};
|
||||
export let forFirst = (funcArg: IPromiseFunction) => {
|
||||
return defaultExport(funcArg, 'forFirst')
|
||||
}
|
||||
|
||||
export let atEnd = (funcArg: IPromiseFunction) => {
|
||||
return defaultExport(funcArg, 'atEnd')
|
||||
}
|
||||
|
||||
export default defaultExport
|
||||
|
33
ts/test.ts
33
ts/test.ts
@ -1,33 +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("Function executed");
|
||||
};
|
||||
var myFunction2 = function () {
|
||||
beautylog.log("Function2 executed");
|
||||
};
|
||||
|
||||
describe("gulpFunction",function(){
|
||||
it("should run through smoothly with " + "'forEach'".blue,function(){
|
||||
gulp.src('./test/*.md')
|
||||
.pipe(gulpFunction(myFunction,'forEach'))
|
||||
.pipe(gulp.dest("./test/result/"));
|
||||
gulp.src('./test/*.md')
|
||||
.pipe(gulpFunction([myFunction,myFunction2],'forEach'))
|
||||
.pipe(gulp.dest("./test/result/"));
|
||||
|
||||
});
|
||||
|
||||
it("should run through smoothly with " + "'atEnd'".blue,function(){
|
||||
gulp.src('./test/*.md')
|
||||
.pipe(gulpFunction(myFunction,'atEnd'))
|
||||
.pipe(gulp.dest("./test/result/"));
|
||||
gulp.src('./test/*.md')
|
||||
.pipe(gulpFunction([myFunction,myFunction2],'atEnd'))
|
||||
.pipe(gulp.dest("./test/result/"));
|
||||
});
|
||||
});
|
||||
|
15
ts/tsd.json
15
ts/tsd.json
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
@ -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
3
tslint.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "tslint-config-standard"
|
||||
}
|
Reference in New Issue
Block a user