Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
077834f7a4 | |||
ca348b5475 | |||
2c9ab52cee | |||
7d35f4c90b | |||
a05253bdcd | |||
54b80098d2 | |||
c39a4a6cb0 | |||
f325479a11 | |||
c79f443c18 | |||
14bb4a90bb | |||
98a583bae1 | |||
848d9ac1e0 |
@ -3,84 +3,123 @@ image: hosttoday/ht-docker-node:npmci
|
|||||||
|
|
||||||
cache:
|
cache:
|
||||||
paths:
|
paths:
|
||||||
- .yarn/
|
- .npmci_cache/
|
||||||
key: "$CI_BUILD_STAGE"
|
key: "$CI_BUILD_STAGE"
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- mirror
|
- security
|
||||||
- test
|
- test
|
||||||
- release
|
- release
|
||||||
- trigger
|
- metadata
|
||||||
- pages
|
|
||||||
|
|
||||||
|
# ====================
|
||||||
|
# security stage
|
||||||
|
# ====================
|
||||||
mirror:
|
mirror:
|
||||||
stage: mirror
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci git mirror
|
- npmci git mirror
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
testLEGACY:
|
snyk:
|
||||||
stage: test
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci node install legacy
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci command npm install -g snyk
|
||||||
- npmci npm test
|
- npmci command npm install --ignore-scripts
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
- npmci command snyk test
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
allow_failure: true
|
- notpriv
|
||||||
|
|
||||||
|
# ====================
|
||||||
|
# test stage
|
||||||
|
# ====================
|
||||||
|
|
||||||
testLTS:
|
testLTS:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
- npmci node install lts
|
- npmci node install lts
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci npm test
|
- npmci npm test
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
testSTABLE:
|
testSTABLE:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
- npmci node install stable
|
- npmci node install stable
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci npm test
|
- npmci npm test
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
release:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci node install stable
|
||||||
- npmci npm publish
|
- npmci npm publish
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
|
# ====================
|
||||||
|
# metadata stage
|
||||||
|
# ====================
|
||||||
|
codequality:
|
||||||
|
stage: metadata
|
||||||
|
image: docker:stable
|
||||||
|
allow_failure: true
|
||||||
|
services:
|
||||||
|
- docker:stable-dind
|
||||||
|
script:
|
||||||
|
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
||||||
|
- docker run
|
||||||
|
--env SOURCE_CODE="$PWD"
|
||||||
|
--volume "$PWD":/code
|
||||||
|
--volume /var/run/docker.sock:/var/run/docker.sock
|
||||||
|
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
|
||||||
|
artifacts:
|
||||||
|
paths: [codeclimate.json]
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
- priv
|
||||||
|
|
||||||
trigger:
|
trigger:
|
||||||
stage: trigger
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci trigger
|
- npmci trigger
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
pages:
|
pages:
|
||||||
image: hosttoday/ht-docker-node:npmci
|
image: hosttoday/ht-docker-node:npmci
|
||||||
stage: pages
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci command yarn global add npmpage
|
- npmci command npm install -g typedoc typescript
|
||||||
- npmci command npmpage
|
- npmci npm prepare
|
||||||
|
- npmci npm install
|
||||||
|
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
- notpriv
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
artifacts:
|
artifacts:
|
||||||
expire_in: 1 week
|
expire_in: 1 week
|
||||||
paths:
|
paths:
|
||||||
- public
|
- public
|
||||||
|
allow_failure: true
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2015 Push.Rocks
|
Copyright (c) 2015 Lossless GmbH
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
42
README.md
42
README.md
@ -1,29 +1,61 @@
|
|||||||
# gulp-function
|
# gulp-function
|
||||||
|
|
||||||
accepts a function call as parameter to execute in gulp pipeline
|
accepts a function call as parameter to execute in gulp pipeline
|
||||||
|
|
||||||
## Availabililty
|
## Availabililty
|
||||||
|
|
||||||
[](https://www.npmjs.com/package/gulp-function)
|
[](https://www.npmjs.com/package/gulp-function)
|
||||||
[](https://GitLab.com/pushrocks/gulp-function)
|
[](https://GitLab.com/pushrocks/gulp-function)
|
||||||
[](https://github.com/pushrocks/gulp-function)
|
[](https://github.com/pushrocks/gulp-function)
|
||||||
[](https://pushrocks.gitlab.io/gulp-function/)
|
[](https://pushrocks.gitlab.io/gulp-function/)
|
||||||
|
|
||||||
## Status for master
|
## Status for master
|
||||||
|
|
||||||
[](https://GitLab.com/pushrocks/gulp-function/commits/master)
|
[](https://GitLab.com/pushrocks/gulp-function/commits/master)
|
||||||
[](https://GitLab.com/pushrocks/gulp-function/commits/master)
|
[](https://GitLab.com/pushrocks/gulp-function/commits/master)
|
||||||
[](https://www.npmjs.com/package/gulp-function)
|
[](https://www.npmjs.com/package/gulp-function)
|
||||||
[](https://david-dm.org/pushrocks/gulp-function)
|
[](https://david-dm.org/pushrocks/gulp-function)
|
||||||
[](https://www.bithound.io/github/pushrocks/gulp-function/master/dependencies/npm)
|
|
||||||
[](https://www.bithound.io/github/pushrocks/gulp-function)
|
|
||||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||||
[](http://standardjs.com/)
|
[](http://standardjs.com/)
|
||||||
|
|
||||||
## Usage
|
### Usage
|
||||||
Use TypeScript for best in class instellisense.
|
|
||||||
|
```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(myAsyncFunction, 'forEach')) //read the notes below
|
||||||
|
// .pipe(forEach(myAsyncFunction)) // 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.
|
For further information read the linked docs at the top of this README.
|
||||||
|
|
||||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
> | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
||||||
|
|
||||||
[](https://push.rocks)
|
[](https://push.rocks)
|
||||||
|
12
dist/index.d.ts
vendored
12
dist/index.d.ts
vendored
@ -1,12 +0,0 @@
|
|||||||
/// <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
76
dist/index.js
vendored
@ -1,76 +0,0 @@
|
|||||||
"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();
|
|
||||||
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDBCQUF1QjtBQUV2QixxQ0FBb0M7QUFTcEMsSUFBSSxhQUFhLEdBQUcsQ0FDbEIscUJBQTRELEVBQzVELG1CQUFtQyxTQUFTLEVBQ2pDLEVBQUU7SUFFYixJQUFJLFlBQVksR0FBRyxFQUFFLENBQUE7SUFDckIsSUFBSSxXQUFXLEdBQUcsVUFBVSxXQUFXLEVBQUUsSUFBSSxFQUFFLEdBQUc7UUFDaEQsSUFBSSxXQUFXLEdBQUcsV0FBVyxDQUFDLElBQUksRUFBRSxHQUFHLENBQUMsQ0FBQTtRQUN4QyxFQUFFLENBQUMsQ0FBQyxPQUFPLFdBQVcsS0FBSyxXQUFXLElBQUksT0FBTyxXQUFXLENBQUMsSUFBSSxLQUFLLFdBQ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BQVEsQ0FBQyxHQUFHLENBQUMsT0FBTyxFQUFFLEtBQUssQ0FBQyxDQUFBO0FBQ3JDLENBQUMsQ0FBQTtBQUVVLFFBQUEsT0FBTyxHQUFHLENBQUMsT0FBeUIsRUFBRSxFQUFFO0lBQ2pELE1BQU0sQ0FBQyxhQUFhLENBQUMsT0FBTyxFQUFFLFNBQVMsQ0FBQyxDQUFBO0FBQzFDLENBQUMsQ0FBQTtBQUVVLFFBQUEsUUFBUSxHQUFHLENBQUMsT0FBeUIsRUFBRSxFQUFFO0lBQ2xELE1BQU0sQ0FBQyxhQUFhLENBQUMsT0FBTyxFQUFFLFVBQVUsQ0FBQyxDQUFBO0FBQzNDLENBQUMsQ0FBQTtBQUVVLFFBQUEsS0FBSyxHQUFHLENBQUMsT0FBeUIsRUFBRSxFQUFFO0lBQy9DLE1BQU0sQ0FBQyxhQUFhLENBQUMsT0FBTyxFQUFFLE9BQU8sQ0FBQyxDQUFBO0FBQ3hDLENBQUMsQ0FBQTtBQUVELGtCQUFlLGFBQWEsQ0FBQSJ9
|
|
@ -1,40 +0,0 @@
|
|||||||
### 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**!!!
|
|
@ -3,7 +3,7 @@
|
|||||||
"mode": "default"
|
"mode": "default"
|
||||||
},
|
},
|
||||||
"npmci": {
|
"npmci": {
|
||||||
"globalNpmTools": [
|
"npmGlobalTools": [
|
||||||
"npmts"
|
"npmts"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
4015
package-lock.json
generated
Normal file
4015
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
24
package.json
24
package.json
@ -1,11 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "gulp-function",
|
"name": "gulp-function",
|
||||||
"version": "2.2.11",
|
"version": "2.2.16",
|
||||||
"description": "accepts a function call as parameter to execute in gulp pipeline",
|
"description": "accepts a function call as parameter to execute in gulp pipeline",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist/index.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(npmts)"
|
"test": "(tstest test/)",
|
||||||
|
"build": "(tsbuild)"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -14,7 +15,8 @@
|
|||||||
"keywords": [
|
"keywords": [
|
||||||
"gulpplugin",
|
"gulpplugin",
|
||||||
"gulp",
|
"gulp",
|
||||||
"function"
|
"function",
|
||||||
|
"pushrocks"
|
||||||
],
|
],
|
||||||
"author": "Lossless GmbH <office@lossless.com> (https://lossless.com)",
|
"author": "Lossless GmbH <office@lossless.com> (https://lossless.com)",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
@ -23,14 +25,18 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/gulp-function",
|
"homepage": "https://gitlab.com/pushrocks/gulp-function",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@pushrocks/smartpromise": "^2.0.5",
|
||||||
"@types/through2": "^2.0.32",
|
"@types/through2": "^2.0.32",
|
||||||
"smartq": "^1.1.6",
|
"through2": "^3.0.0"
|
||||||
"through2": "^2.0.3",
|
|
||||||
"typings-global": "^1.0.16"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@gitzone/tsbuild": "^2.1.3",
|
||||||
|
"@gitzone/tstest": "^1.0.18",
|
||||||
|
"@pushrocks/smartgulp": "^2.0.1",
|
||||||
|
"@pushrocks/tapbundle": "^3.0.7",
|
||||||
"gulp": "^3.9.1",
|
"gulp": "^3.9.1",
|
||||||
"smartgulp": "^1.0.1",
|
"tslint": "^5.11.0",
|
||||||
"tapbundle": "^1.0.10"
|
"tslint-config-prettier": "^1.17.0"
|
||||||
}
|
},
|
||||||
|
"private": true
|
||||||
}
|
}
|
||||||
|
54
test/test.ts
54
test/test.ts
@ -1,33 +1,35 @@
|
|||||||
import { expect, tap } from 'tapbundle'
|
import { expect, tap } from '@pushrocks/tapbundle';
|
||||||
|
|
||||||
import * as smartgulp from 'smartgulp'
|
import * as smartgulp from '@pushrocks/smartgulp';
|
||||||
let gulp = require('gulp')
|
let gulp = require('gulp');
|
||||||
import * as gulpFunction from '../ts/index'
|
import * as gulpFunction from '../ts/index';
|
||||||
|
|
||||||
let smartq = require('smartq')
|
import * as smartpromise from '@pushrocks/smartpromise';
|
||||||
|
|
||||||
tap.test('should run through smoothly with ' + "'forEach'", async (tools) => {
|
tap.test('should run through smoothly with ' + "'forEach'", async tools => {
|
||||||
let done = smartq.defer()
|
let done = smartpromise.defer();
|
||||||
let counter = 0
|
let counter = 0;
|
||||||
gulp.src('./test/testfiles/*.md')
|
gulp.src('./test/testfiles/*.md').pipe(
|
||||||
.pipe(gulpFunction.forEach(async () => {
|
gulpFunction.forEach(async () => {
|
||||||
counter++
|
counter++;
|
||||||
if (counter === 2) {
|
if (counter === 2) {
|
||||||
done.resolve()
|
done.resolve();
|
||||||
}
|
}
|
||||||
}))
|
})
|
||||||
await done.promise
|
);
|
||||||
})
|
await done.promise;
|
||||||
|
});
|
||||||
|
|
||||||
tap.test('should run through smoothly with ' + "'forEach'", async (tools) => {
|
tap.test('should run through smoothly with ' + "'forEach'", async tools => {
|
||||||
let done = smartq.defer()
|
let done = smartpromise.defer();
|
||||||
let counter = 0
|
let counter = 0;
|
||||||
smartgulp.src(['./test/testfiles/*.md'])
|
smartgulp.src(['./test/testfiles/*.md']).pipe(
|
||||||
.pipe(gulpFunction.atEnd(async () => {
|
gulpFunction.atEnd(async () => {
|
||||||
console.log('atEnd')
|
console.log('atEnd');
|
||||||
done.resolve()
|
done.resolve();
|
||||||
}))
|
})
|
||||||
await done.promise
|
);
|
||||||
})
|
await done.promise;
|
||||||
|
});
|
||||||
|
|
||||||
tap.start()
|
tap.start();
|
||||||
|
98
ts/index.ts
98
ts/index.ts
@ -1,89 +1,87 @@
|
|||||||
import 'typings-global'
|
import * as smartpromise from '@pushrocks/smartpromise';
|
||||||
import * as q from 'smartq'
|
import * as through2 from 'through2';
|
||||||
import * as through2 from 'through2'
|
import { Transform } from 'stream';
|
||||||
import { Transform } from 'stream'
|
|
||||||
|
|
||||||
export type TExecutionMode = 'forEach' | 'forFirst' | 'atEnd'
|
export type TExecutionMode = 'forEach' | 'forFirst' | 'atEnd';
|
||||||
|
|
||||||
export interface IPromiseFunction {
|
export interface IPromiseFunction {
|
||||||
(file?, enc?): PromiseLike<any>
|
(file?, enc?): PromiseLike<any>;
|
||||||
}
|
}
|
||||||
|
|
||||||
let defaultExport = (
|
let defaultExport = (
|
||||||
functionsToExecuteArg: IPromiseFunction | IPromiseFunction[],
|
functionsToExecuteArg: IPromiseFunction | IPromiseFunction[],
|
||||||
executionModeArg: TExecutionMode = 'forEach'
|
executionModeArg: TExecutionMode = 'forEach'
|
||||||
): Transform => {
|
): Transform => {
|
||||||
|
let promiseArray = [];
|
||||||
let promiseArray = []
|
let runFunction = function(functionArg, file, enc) {
|
||||||
let runFunction = function (functionArg, file, enc) {
|
let returnValue = functionArg(file, enc);
|
||||||
let returnValue = functionArg(file, enc)
|
|
||||||
if (typeof returnValue !== 'undefined' && typeof returnValue.then !== 'undefined') {
|
if (typeof returnValue !== 'undefined' && typeof returnValue.then !== 'undefined') {
|
||||||
promiseArray.push(returnValue)
|
promiseArray.push(returnValue);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
let checkAndRunFunction = function (file, enc) {
|
let checkAndRunFunction = function(file, enc) {
|
||||||
if (typeof functionsToExecuteArg === 'function') {
|
if (typeof functionsToExecuteArg === 'function') {
|
||||||
runFunction(functionsToExecuteArg, file, enc)
|
runFunction(functionsToExecuteArg, file, enc);
|
||||||
} else if (Array.isArray(functionsToExecuteArg)) {
|
} else if (Array.isArray(functionsToExecuteArg)) {
|
||||||
for (let anyFunction in functionsToExecuteArg) {
|
for (let anyFunction in functionsToExecuteArg) {
|
||||||
runFunction(functionsToExecuteArg[ anyFunction ], file, enc)
|
runFunction(functionsToExecuteArg[anyFunction], file, enc);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new Error('gulp-callfunction: something is strange with the given arguments')
|
throw new Error('gulp-callfunction: something is strange with the given arguments');
|
||||||
}
|
}
|
||||||
return Promise.all(promiseArray)
|
return Promise.all(promiseArray);
|
||||||
}
|
};
|
||||||
|
|
||||||
let hasExecutedOnce = false
|
let hasExecutedOnce = false;
|
||||||
let forEach = function (file, enc, cb) { // the forEach function is called for every chunk
|
let forEach = function(file, enc, cb) {
|
||||||
|
// the forEach function is called for every chunk
|
||||||
switch (executionModeArg) {
|
switch (executionModeArg) {
|
||||||
case 'forEach':
|
case 'forEach':
|
||||||
checkAndRunFunction(file, enc).then(function () {
|
checkAndRunFunction(file, enc).then(function() {
|
||||||
cb(null, file)
|
cb(null, file);
|
||||||
})
|
});
|
||||||
break
|
break;
|
||||||
case 'forFirst':
|
case 'forFirst':
|
||||||
if (hasExecutedOnce) {
|
if (hasExecutedOnce) {
|
||||||
checkAndRunFunction(file, enc)
|
checkAndRunFunction(file, enc).then(function() {
|
||||||
.then(function () {
|
cb(null, file);
|
||||||
cb(null, file)
|
});
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
cb(null, file)
|
cb(null, file);
|
||||||
}
|
}
|
||||||
hasExecutedOnce = true
|
hasExecutedOnce = true;
|
||||||
break
|
break;
|
||||||
case 'atEnd':
|
case 'atEnd':
|
||||||
cb()
|
cb();
|
||||||
break
|
break;
|
||||||
default:
|
default:
|
||||||
break
|
break;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
let atEnd = function (cb) {
|
let atEnd = function(cb) {
|
||||||
if (executionModeArg === 'atEnd') {
|
if (executionModeArg === 'atEnd') {
|
||||||
checkAndRunFunction(null, null).then(function () {
|
checkAndRunFunction(null, null).then(function() {
|
||||||
cb()
|
cb();
|
||||||
})
|
});
|
||||||
} else {
|
} else {
|
||||||
cb()
|
cb();
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
return through2.obj(forEach, atEnd)
|
return through2.obj(forEach, atEnd);
|
||||||
}
|
};
|
||||||
|
|
||||||
export let forEach = (funcArg: IPromiseFunction) => {
|
export let forEach = (funcArg: IPromiseFunction) => {
|
||||||
return defaultExport(funcArg, 'forEach')
|
return defaultExport(funcArg, 'forEach');
|
||||||
}
|
};
|
||||||
|
|
||||||
export let forFirst = (funcArg: IPromiseFunction) => {
|
export let forFirst = (funcArg: IPromiseFunction) => {
|
||||||
return defaultExport(funcArg, 'forFirst')
|
return defaultExport(funcArg, 'forFirst');
|
||||||
}
|
};
|
||||||
|
|
||||||
export let atEnd = (funcArg: IPromiseFunction) => {
|
export let atEnd = (funcArg: IPromiseFunction) => {
|
||||||
return defaultExport(funcArg, 'atEnd')
|
return defaultExport(funcArg, 'atEnd');
|
||||||
}
|
};
|
||||||
|
|
||||||
export default defaultExport
|
export default defaultExport;
|
||||||
|
16
tslint.json
16
tslint.json
@ -1,3 +1,17 @@
|
|||||||
{
|
{
|
||||||
"extends": "tslint-config-standard"
|
"extends": ["tslint:latest", "tslint-config-prettier"],
|
||||||
|
"rules": {
|
||||||
|
"semicolon": [true, "always"],
|
||||||
|
"no-console": false,
|
||||||
|
"ordered-imports": false,
|
||||||
|
"object-literal-sort-keys": false,
|
||||||
|
"member-ordering": {
|
||||||
|
"options":{
|
||||||
|
"order": [
|
||||||
|
"static-method"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"defaultSeverity": "warning"
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user