Compare commits
34 Commits
Author | SHA1 | Date | |
---|---|---|---|
2c9ab52cee | |||
7d35f4c90b | |||
a05253bdcd | |||
54b80098d2 | |||
c39a4a6cb0 | |||
f325479a11 | |||
c79f443c18 | |||
14bb4a90bb | |||
98a583bae1 | |||
848d9ac1e0 | |||
e7ccd9aec4 | |||
63bf7204dd | |||
a34a1b89fe | |||
f4455a9b91 | |||
1a01198d7f | |||
b3ec364a1d | |||
5d15c96511 | |||
f6e071156b | |||
63fe7c7423 | |||
c8dcdc0df4 | |||
743c7a03a5 | |||
f9e7bf450b | |||
b55a511fcb | |||
96c15cb90a | |||
0d772e8ab0 | |||
a324deb942 | |||
cb60bec110 | |||
291583b17a | |||
9d54da207f | |||
7aad993847 | |||
c208f04e23 | |||
54d8ef2576 | |||
8b891c74e4 | |||
1d8de68a66 |
8
.gitignore
vendored
8
.gitignore
vendored
@ -1,13 +1,5 @@
|
||||
node_modules/
|
||||
.settings/
|
||||
.idea/
|
||||
coverage/
|
||||
docs/
|
||||
public/
|
||||
pages/
|
||||
|
||||
ts/*.js
|
||||
ts/*.js.map
|
||||
ts/typings/
|
||||
test/result/
|
||||
|
||||
|
118
.gitlab-ci.yml
118
.gitlab-ci.yml
@ -1,53 +1,125 @@
|
||||
image: hosttoday/ht-docker-node:npmts
|
||||
# gitzone standard
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
|
||||
cache:
|
||||
paths:
|
||||
- .npmci_cache/
|
||||
key: "$CI_BUILD_STAGE"
|
||||
|
||||
stages:
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- trigger
|
||||
- pages
|
||||
testLEGACY:
|
||||
stage: test
|
||||
- metadata
|
||||
|
||||
# ====================
|
||||
# security stage
|
||||
# ====================
|
||||
mirror:
|
||||
stage: security
|
||||
script:
|
||||
- npmci test legacy
|
||||
- npmci git mirror
|
||||
tags:
|
||||
- docker
|
||||
allow_failure: true
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
snyk:
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install -g snyk
|
||||
- npmci command npm install --ignore-scripts
|
||||
- npmci command snyk test
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
# ====================
|
||||
# test stage
|
||||
# ====================
|
||||
|
||||
testLTS:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test lts
|
||||
- npmci npm prepare
|
||||
- npmci node install lts
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
testSTABLE:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test stable
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
release:
|
||||
stage: release
|
||||
script:
|
||||
- npmci publish
|
||||
- npmci node install stable
|
||||
- npmci npm publish
|
||||
only:
|
||||
- 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:
|
||||
stage: trigger
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci trigger
|
||||
- npmci trigger
|
||||
only:
|
||||
- tags
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
pages:
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci command npm install -g typedoc typescript
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
|
||||
tags:
|
||||
- docker
|
||||
pages:
|
||||
image: hosttoday/ht-docker-node:npmpage
|
||||
stage: pages
|
||||
script:
|
||||
- npmci command npmpage --host gitlab
|
||||
- notpriv
|
||||
only:
|
||||
- tags
|
||||
artifacts:
|
||||
expire_in: 1 week
|
||||
paths:
|
||||
- public
|
||||
allow_failure: true
|
||||
|
82
README.md
82
README.md
@ -1,59 +1,61 @@
|
||||
# gulp-function
|
||||
accepts call to execute in gulp pipeline.
|
||||
|
||||
accepts a function call as parameter to execute in gulp pipeline
|
||||
|
||||
## 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/)
|
||||
|
||||
[](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://GitLab.com/pushrocks/gulp-function/commits/master)
|
||||
[](https://GitLab.com/pushrocks/gulp-function/commits/master)
|
||||
[](https://www.npmjs.com/package/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/)
|
||||
[](http://standardjs.com/)
|
||||
|
||||
### Usage
|
||||
```javascript
|
||||
import * as gulp from 'gulp';
|
||||
import gulpFunction from 'gulp-function' // default ES6 export
|
||||
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!")
|
||||
```typescript
|
||||
import gulp = require('gulp');
|
||||
import gulpFunction from 'gulp-function'; // default ES6 export
|
||||
// import {forFirst, forEach, atEnd} from 'gulp-function'
|
||||
|
||||
// NOTE:
|
||||
// you can use done.resolve as callback function
|
||||
// of any async tasks within this function
|
||||
done.resolve();
|
||||
let myAsyncFunction = async (file, enc) => {
|
||||
// await some async stuff
|
||||
};
|
||||
|
||||
return done.promise;
|
||||
}
|
||||
|
||||
gulp.task('gulpTest',function() {
|
||||
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.
|
||||
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:
|
||||
### 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**!!!
|
||||
- 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)
|
||||
For further information read the linked docs at the top of this README.
|
||||
|
||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||
> | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
||||
|
||||
[](https://push.rocks)
|
||||
|
9
dist/index.d.ts
vendored
9
dist/index.d.ts
vendored
@ -1,9 +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 mainExportFunction: (functionsToExecuteArg: IPromiseFunction | IPromiseFunction[], executionModeArg?: TExecutionMode) => Transform;
|
||||
export default mainExportFunction;
|
68
dist/index.js
vendored
68
dist/index.js
vendored
@ -1,68 +0,0 @@
|
||||
"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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291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sSUFBSSxFQUFFLElBQUksQ0FBQyxDQUFBO2dCQUNkLEtBQUssQ0FBQTtZQUNUO2dCQUNJLEtBQUssQ0FBQTtRQUNiLENBQUM7SUFDTCxDQUFDLENBQUE7SUFFRCxJQUFJLEtBQUssR0FBRyxVQUFVLEVBQUU7UUFDcEIsRUFBRSxDQUFDLENBQUMsZ0JBQWdCLEtBQUssT0FBTyxDQUFDLENBQUMsQ0FBQztZQUMvQixtQkFBbUIsQ0FBQyxJQUFJLEVBQUUsSUFBSSxDQUFDLENBQUMsSUFBSSxDQUFDO2dCQUNqQyxFQUFFLEVBQUUsQ0FBQTtZQUNSLENBQUMsQ0FBQyxDQUFBO1FBQ04sQ0FBQztRQUFDLElBQUksQ0FBQyxDQUFDO1lBQ0osRUFBRSxFQUFFLENBQUE7UUFDUixDQUFDO0lBQ0wsQ0FBQyxDQUFBO0lBQ0QsTUFBTSxDQUFDLFFBQVEsQ0FBQyxHQUFHLENBQUMsT0FBTyxFQUFFLEtBQUssQ0FBQyxDQUFBO0FBQ3ZDLENBQUMsQ0FBQTs7QUFFRCxrQkFBZSxrQkFBa0IsQ0FBQSJ9
|
@ -1,5 +1,10 @@
|
||||
{
|
||||
"npmts": {
|
||||
"mode": "default"
|
||||
},
|
||||
"npmci": {
|
||||
"npmGlobalTools": [
|
||||
"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
31
package.json
31
package.json
@ -1,14 +1,12 @@
|
||||
{
|
||||
"name": "gulp-function",
|
||||
"version": "2.1.0",
|
||||
"version": "2.2.15",
|
||||
"description": "accepts a function call as parameter to execute in gulp pipeline",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"scripts": {
|
||||
"test": "(npmts)",
|
||||
"reinstall": "(rm -r node_modules && npm install)",
|
||||
"release": "(git pull origin master && npm version patch && git push origin master && git checkout release && git merge master && git push origin release && git checkout master)",
|
||||
"startdev": "(git checkout master && git pull origin master)"
|
||||
"test": "(tstest test/)",
|
||||
"build": "(tsbuild)"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -17,7 +15,8 @@
|
||||
"keywords": [
|
||||
"gulpplugin",
|
||||
"gulp",
|
||||
"function"
|
||||
"function",
|
||||
"pushrocks"
|
||||
],
|
||||
"author": "Lossless GmbH <office@lossless.com> (https://lossless.com)",
|
||||
"license": "MIT",
|
||||
@ -26,16 +25,18 @@
|
||||
},
|
||||
"homepage": "https://gitlab.com/pushrocks/gulp-function",
|
||||
"dependencies": {
|
||||
"@types/q": "0.0.32",
|
||||
"@types/through2": "^2.0.31",
|
||||
"q": "^1.4.1",
|
||||
"through2": "^2.0.1",
|
||||
"typings-global": "^1.0.14"
|
||||
"@pushrocks/smartpromise": "^2.0.5",
|
||||
"@types/through2": "^2.0.32",
|
||||
"through2": "^3.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"beautylog": "^6.0.0",
|
||||
"@gitzone/tsbuild": "^2.1.3",
|
||||
"@gitzone/tstest": "^1.0.18",
|
||||
"@pushrocks/smartgulp": "^2.0.1",
|
||||
"@pushrocks/tapbundle": "^3.0.7",
|
||||
"gulp": "^3.9.1",
|
||||
"npmts-g": "^5.2.8",
|
||||
"typings-test": "^1.0.3"
|
||||
}
|
||||
"tslint": "^5.11.0",
|
||||
"tslint-config-prettier": "^1.17.0"
|
||||
},
|
||||
"private": true
|
||||
}
|
||||
|
1
test/test.d.ts
vendored
1
test/test.d.ts
vendored
@ -1 +0,0 @@
|
||||
import 'typings-test';
|
102
test/test.js
102
test/test.js
File diff suppressed because one or more lines are too long
@ -1 +0,0 @@
|
||||
{"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;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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"}
|
141
test/test.ts
141
test/test.ts
@ -1,118 +1,35 @@
|
||||
import 'typings-test'
|
||||
import { expect, tap } from '@pushrocks/tapbundle';
|
||||
|
||||
import * as smartgulp from '@pushrocks/smartgulp';
|
||||
let gulp = require('gulp');
|
||||
import gulpFunction from '../dist/index'
|
||||
let beautylog = require('beautylog')
|
||||
let Q = require('q')
|
||||
import * as gulpFunction from '../ts/index';
|
||||
|
||||
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;
|
||||
};
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
|
||||
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;
|
||||
tap.test('should run through smoothly with ' + "'forEach'", async tools => {
|
||||
let done = smartpromise.defer();
|
||||
let counter = 0;
|
||||
gulp.src('./test/testfiles/*.md').pipe(
|
||||
gulpFunction.forEach(async () => {
|
||||
counter++;
|
||||
if (counter === 2) {
|
||||
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();
|
||||
});
|
||||
});
|
||||
}
|
||||
})
|
||||
);
|
||||
await done.promise;
|
||||
});
|
||||
|
||||
tap.test('should run through smoothly with ' + "'forEach'", async tools => {
|
||||
let done = smartpromise.defer();
|
||||
let counter = 0;
|
||||
smartgulp.src(['./test/testfiles/*.md']).pipe(
|
||||
gulpFunction.atEnd(async () => {
|
||||
console.log('atEnd');
|
||||
done.resolve();
|
||||
})
|
||||
);
|
||||
await done.promise;
|
||||
});
|
||||
|
||||
tap.start();
|
||||
|
@ -1,2 +0,0 @@
|
||||
# Test.md
|
||||
This is a test file for the test.js gulp pipeline
|
@ -1,2 +0,0 @@
|
||||
# Test.md
|
||||
This is another test file for the test.js gulp pipeline
|
1
test/testfiles/test01.md
Normal file
1
test/testfiles/test01.md
Normal file
@ -0,0 +1 @@
|
||||
# the 1st testfile
|
1
test/testfiles/test02.md
Normal file
1
test/testfiles/test02.md
Normal file
@ -0,0 +1 @@
|
||||
# the second testfile
|
1
test/testfiles/test03.md
Normal file
1
test/testfiles/test03.md
Normal file
@ -0,0 +1 @@
|
||||
# the third testfile
|
1
test/testfiles/test04.md
Normal file
1
test/testfiles/test04.md
Normal file
@ -0,0 +1 @@
|
||||
# the fourth testfile
|
1
test/testfiles/test05.md
Normal file
1
test/testfiles/test05.md
Normal file
@ -0,0 +1 @@
|
||||
# the fifth testfile
|
1
test/testfiles/test06.md
Normal file
1
test/testfiles/test06.md
Normal file
@ -0,0 +1 @@
|
||||
# the sixth testfile
|
1
test/testfiles/test07.md
Normal file
1
test/testfiles/test07.md
Normal file
@ -0,0 +1 @@
|
||||
# the seventh testfile
|
1
test/testfiles/test08.md
Normal file
1
test/testfiles/test08.md
Normal file
@ -0,0 +1 @@
|
||||
# the eighth testfile
|
1
test/testfiles/test09.md
Normal file
1
test/testfiles/test09.md
Normal file
@ -0,0 +1 @@
|
||||
# the nineth testfile
|
1
test/testfiles/test10.md
Normal file
1
test/testfiles/test10.md
Normal file
@ -0,0 +1 @@
|
||||
# the tenth testfile
|
1
test/testfiles/test11.md
Normal file
1
test/testfiles/test11.md
Normal file
@ -0,0 +1 @@
|
||||
# the eleventh testfile
|
1
test/testfiles/test12.md
Normal file
1
test/testfiles/test12.md
Normal file
@ -0,0 +1 @@
|
||||
# the twelveth testfile
|
1
test/testfiles/test13.md
Normal file
1
test/testfiles/test13.md
Normal file
@ -0,0 +1 @@
|
||||
# the second testfile
|
1
test/testfiles/test14.md
Normal file
1
test/testfiles/test14.md
Normal file
@ -0,0 +1 @@
|
||||
# the second testfile
|
1
test/testfiles/test15.md
Normal file
1
test/testfiles/test15.md
Normal file
@ -0,0 +1 @@
|
||||
# the second testfile
|
1
test/testfiles/test16.md
Normal file
1
test/testfiles/test16.md
Normal file
@ -0,0 +1 @@
|
||||
# the second testfile
|
1
test/testfiles/test17.md
Normal file
1
test/testfiles/test17.md
Normal file
@ -0,0 +1 @@
|
||||
# the second testfile
|
1
test/testfiles/test18.md
Normal file
1
test/testfiles/test18.md
Normal file
@ -0,0 +1 @@
|
||||
# the 18th testfile
|
134
ts/index.ts
134
ts/index.ts
@ -1,77 +1,87 @@
|
||||
import 'typings-global'
|
||||
import * as q from 'q'
|
||||
import * as through2 from 'through2'
|
||||
import { Transform } from 'stream'
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
import * as through2 from 'through2';
|
||||
import { Transform } from 'stream';
|
||||
|
||||
export type TExecutionMode = 'forEach' | 'forFirst' | 'atEnd'
|
||||
export type TExecutionMode = 'forEach' | 'forFirst' | 'atEnd';
|
||||
|
||||
export interface IPromiseFunction {
|
||||
(file?, enc?): PromiseLike<any>
|
||||
(file?, enc?): PromiseLike<any>;
|
||||
}
|
||||
|
||||
let mainExportFunction = (
|
||||
functionsToExecuteArg: IPromiseFunction | IPromiseFunction[],
|
||||
executionModeArg: TExecutionMode = 'forEach'
|
||||
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 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)
|
||||
}
|
||||
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 {
|
||||
throw new Error('gulp-callfunction: something is strange with the given arguments')
|
||||
cb(null, file);
|
||||
}
|
||||
return q.all(promiseArray)
|
||||
hasExecutedOnce = true;
|
||||
break;
|
||||
case 'atEnd':
|
||||
cb();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
let hasExecutedOnce = false
|
||||
let forEach = function (file, enc, cb) { // the forEach function is called for every chunk
|
||||
switch (executionModeArg) {
|
||||
case 'forEach':
|
||||
checkAndRunFunction(file, enc).then(function () {
|
||||
cb(null, file)
|
||||
})
|
||||
break
|
||||
case 'forFirst':
|
||||
if (hasExecutedOnce) {
|
||||
checkAndRunFunction(file, enc)
|
||||
.then(function () {
|
||||
cb(null, file)
|
||||
})
|
||||
} else {
|
||||
cb(null, file)
|
||||
}
|
||||
hasExecutedOnce = true
|
||||
break
|
||||
case 'atEnd':
|
||||
cb(null, file)
|
||||
break
|
||||
default:
|
||||
break
|
||||
}
|
||||
let atEnd = function(cb) {
|
||||
if (executionModeArg === 'atEnd') {
|
||||
checkAndRunFunction(null, null).then(function() {
|
||||
cb();
|
||||
});
|
||||
} else {
|
||||
cb();
|
||||
}
|
||||
};
|
||||
return through2.obj(forEach, atEnd);
|
||||
};
|
||||
|
||||
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 default mainExportFunction
|
||||
export let forFirst = (funcArg: IPromiseFunction) => {
|
||||
return defaultExport(funcArg, 'forFirst');
|
||||
};
|
||||
|
||||
export let atEnd = (funcArg: IPromiseFunction) => {
|
||||
return defaultExport(funcArg, 'atEnd');
|
||||
};
|
||||
|
||||
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