Compare commits
16 Commits
Author | SHA1 | Date | |
---|---|---|---|
e7ccd9aec4 | |||
63bf7204dd | |||
a34a1b89fe | |||
f4455a9b91 | |||
1a01198d7f | |||
b3ec364a1d | |||
5d15c96511 | |||
f6e071156b | |||
63fe7c7423 | |||
c8dcdc0df4 | |||
743c7a03a5 | |||
f9e7bf450b | |||
b55a511fcb | |||
96c15cb90a | |||
0d772e8ab0 | |||
a324deb942 |
8
.gitignore
vendored
8
.gitignore
vendored
@ -1,13 +1,5 @@
|
|||||||
node_modules/
|
node_modules/
|
||||||
.settings/
|
|
||||||
.idea/
|
|
||||||
coverage/
|
coverage/
|
||||||
docs/
|
|
||||||
public/
|
public/
|
||||||
pages/
|
pages/
|
||||||
|
|
||||||
ts/*.js
|
|
||||||
ts/*.js.map
|
|
||||||
ts/typings/
|
|
||||||
test/result/
|
|
||||||
|
|
||||||
|
@ -1,53 +1,86 @@
|
|||||||
image: hosttoday/ht-docker-node:npmts
|
# gitzone standard
|
||||||
|
image: hosttoday/ht-docker-node:npmci
|
||||||
|
|
||||||
|
cache:
|
||||||
|
paths:
|
||||||
|
- .yarn/
|
||||||
|
key: "$CI_BUILD_STAGE"
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
|
- mirror
|
||||||
- test
|
- test
|
||||||
- release
|
- release
|
||||||
- trigger
|
- trigger
|
||||||
- pages
|
- pages
|
||||||
|
|
||||||
|
mirror:
|
||||||
|
stage: mirror
|
||||||
|
script:
|
||||||
|
- npmci git mirror
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
|
||||||
testLEGACY:
|
testLEGACY:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci test legacy
|
- npmci node install legacy
|
||||||
|
- npmci npm install
|
||||||
|
- npmci npm test
|
||||||
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
|
|
||||||
testLTS:
|
testLTS:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci test lts
|
- npmci node install lts
|
||||||
|
- npmci npm install
|
||||||
|
- npmci npm test
|
||||||
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
|
||||||
testSTABLE:
|
testSTABLE:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci test stable
|
- npmci node install stable
|
||||||
|
- npmci npm install
|
||||||
|
- npmci npm test
|
||||||
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
|
||||||
release:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
script:
|
script:
|
||||||
- npmci publish
|
- npmci npm prepare
|
||||||
|
- npmci npm publish
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
|
||||||
trigger:
|
trigger:
|
||||||
stage: trigger
|
stage: trigger
|
||||||
script:
|
script:
|
||||||
- npmci trigger
|
- npmci trigger
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
|
||||||
pages:
|
pages:
|
||||||
image: hosttoday/ht-docker-node:npmpage
|
image: hosttoday/ht-docker-node:npmci
|
||||||
stage: pages
|
stage: pages
|
||||||
script:
|
script:
|
||||||
- npmci command npmpage --host gitlab
|
- npmci command yarn global add npmpage
|
||||||
|
- npmci command npmpage
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
artifacts:
|
artifacts:
|
||||||
expire_in: 1 week
|
expire_in: 1 week
|
||||||
paths:
|
paths:
|
||||||
- public
|
- public
|
||||||
|
60
README.md
60
README.md
@ -1,15 +1,16 @@
|
|||||||
# gulp-function
|
# gulp-function
|
||||||
accepts call 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://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/master/dependencies/npm)
|
||||||
[](https://www.bithound.io/github/pushrocks/gulp-function)
|
[](https://www.bithound.io/github/pushrocks/gulp-function)
|
||||||
@ -17,45 +18,12 @@ accepts call to execute in gulp pipeline.
|
|||||||
[](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
|
||||||
```javascript
|
Use TypeScript for best in class instellisense.
|
||||||
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
|
For further information read the linked docs at the top of this README.
|
||||||
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() {
|
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||||
let stream = gulp.src('./mydir/*.something')
|
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
||||||
.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:
|
[](https://push.rocks)
|
||||||
|
|
||||||
* 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)
|
|
||||||
|
9
dist/index.js
vendored
9
dist/index.js
vendored
@ -1,6 +1,6 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
require("typings-global");
|
require("typings-global");
|
||||||
const q = require("q");
|
|
||||||
const through2 = require("through2");
|
const through2 = require("through2");
|
||||||
let defaultExport = (functionsToExecuteArg, executionModeArg = 'forEach') => {
|
let defaultExport = (functionsToExecuteArg, executionModeArg = 'forEach') => {
|
||||||
let promiseArray = [];
|
let promiseArray = [];
|
||||||
@ -22,7 +22,7 @@ let defaultExport = (functionsToExecuteArg, executionModeArg = 'forEach') => {
|
|||||||
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 q.all(promiseArray);
|
return Promise.all(promiseArray);
|
||||||
};
|
};
|
||||||
let hasExecutedOnce = false;
|
let hasExecutedOnce = false;
|
||||||
let forEach = function (file, enc, cb) {
|
let forEach = function (file, enc, cb) {
|
||||||
@ -45,7 +45,7 @@ let defaultExport = (functionsToExecuteArg, executionModeArg = 'forEach') => {
|
|||||||
hasExecutedOnce = true;
|
hasExecutedOnce = true;
|
||||||
break;
|
break;
|
||||||
case 'atEnd':
|
case 'atEnd':
|
||||||
cb(null, file);
|
cb();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -72,6 +72,5 @@ exports.forFirst = (funcArg) => {
|
|||||||
exports.atEnd = (funcArg) => {
|
exports.atEnd = (funcArg) => {
|
||||||
return defaultExport(funcArg, 'atEnd');
|
return defaultExport(funcArg, 'atEnd');
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
|
||||||
exports.default = defaultExport;
|
exports.default = defaultExport;
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBQ3ZCLHVCQUFzQjtBQUN0QixxQ0FBb0M7QUFTcEMsSUFBSSxhQUFhLEdBQUcsQ0FDaEIscUJBQTREL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yxVQUFVLEVBQUU7UUFDdEIsRUFBRSxDQUFDLENBQUMsZ0JBQWdCLEtBQUssT0FBTyxDQUFDLENBQUMsQ0FBQztZQUNqQyxtQkFBbUIsQ0FBQyxJQUFJLEVBQUUsSUFBSSxDQUFDLENBQUMsSUFBSSxDQUFDO2dCQUNuQyxFQUFFLEVBQUUsQ0FBQTtZQUNOLENBQUMsQ0FBQyxDQUFBO1FBQ0osQ0FBQztRQUFDLElBQUksQ0FBQyxDQUFDO1lBQ04sRUFBRSxFQUFFLENBQUE7UUFDTixDQUFDO0lBQ0gsQ0FBQyxDQUFBO0lBQ0QsTUFBTSxDQUFDLFFBQVEsQ0FBQyxHQUFHLENBQUMsT0FBTyxFQUFFLEtBQUssQ0FBQyxDQUFBO0FBQ3JDLENBQUMsQ0FBQTtBQUVVLFFBQUEsT0FBTyxHQUFHLENBQUMsT0FBeUIsRUFBRSxFQUFFO0lBQ2pELE1BQU0sQ0FBQyxhQUFhLENBQUMsT0FBTyxFQUFFLFNBQVMsQ0FBQyxDQUFBO0FBQzFDLENBQUMsQ0FBQTtBQUVVLFFBQUEsUUFBUSxHQUFHLENBQUMsT0FBeUIsRUFBRSxFQUFFO0lBQ2xELE1BQU0sQ0FBQyxhQUFhLENBQUMsT0FBTyxFQUFFLFVBQVUsQ0FBQyxDQUFBO0FBQzNDLENBQUMsQ0FBQTtBQUVVLFFBQUEsS0FBSyxHQUFHLENBQUMsT0FBeUIsRUFBRSxFQUFFO0lBQy9DLE1BQU0sQ0FBQyxhQUFhLENBQUMsT0FBTyxFQUFFLE9BQU8sQ0FBQyxDQUFBO0FBQ3hDLENBQUMsQ0FBQTtBQUVELGtCQUFlLGFBQWEsQ0FBQSJ9
|
40
docs/index.md
Normal file
40
docs/index.md
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
### 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**!!!
|
@ -1,5 +1,10 @@
|
|||||||
{
|
{
|
||||||
"npmts": {
|
"npmts": {
|
||||||
"mode": "default"
|
"mode": "default"
|
||||||
|
},
|
||||||
|
"npmci": {
|
||||||
|
"globalNpmTools": [
|
||||||
|
"npmts"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
21
package.json
21
package.json
@ -1,14 +1,11 @@
|
|||||||
{
|
{
|
||||||
"name": "gulp-function",
|
"name": "gulp-function",
|
||||||
"version": "2.2.3",
|
"version": "2.2.11",
|
||||||
"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": "(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)"
|
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -26,16 +23,14 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/gulp-function",
|
"homepage": "https://gitlab.com/pushrocks/gulp-function",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/q": "0.0.32",
|
"@types/through2": "^2.0.32",
|
||||||
"@types/through2": "^2.0.31",
|
"smartq": "^1.1.6",
|
||||||
"q": "^1.4.1",
|
"through2": "^2.0.3",
|
||||||
"through2": "^2.0.1",
|
"typings-global": "^1.0.16"
|
||||||
"typings-global": "^1.0.14"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"beautylog": "^6.0.0",
|
|
||||||
"gulp": "^3.9.1",
|
"gulp": "^3.9.1",
|
||||||
"npmts-g": "^5.2.8",
|
"smartgulp": "^1.0.1",
|
||||||
"typings-test": "^1.0.3"
|
"tapbundle": "^1.0.10"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
1
test/test.d.ts
vendored
1
test/test.d.ts
vendored
@ -1 +0,0 @@
|
|||||||
import 'typings-test';
|
|
116
test/test.js
116
test/test.js
File diff suppressed because one or more lines are too long
@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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"}
|
|
155
test/test.ts
155
test/test.ts
@ -1,134 +1,33 @@
|
|||||||
import 'typings-test'
|
import { expect, tap } from 'tapbundle'
|
||||||
|
|
||||||
|
import * as smartgulp from 'smartgulp'
|
||||||
let gulp = require('gulp')
|
let gulp = require('gulp')
|
||||||
import gulpFunction from '../dist/index'
|
import * as gulpFunction from '../ts/index'
|
||||||
|
|
||||||
import * as beautylog from 'beautylog'
|
let smartq = require('smartq')
|
||||||
let Q = require('q')
|
|
||||||
|
|
||||||
let myFunction = function () {
|
tap.test('should run through smoothly with ' + "'forEach'", async (tools) => {
|
||||||
let done = Q.defer()
|
let done = smartq.defer()
|
||||||
beautylog.log('Function executed')
|
let counter = 0
|
||||||
done.resolve()
|
gulp.src('./test/testfiles/*.md')
|
||||||
return done.promise
|
.pipe(gulpFunction.forEach(async () => {
|
||||||
}
|
counter++
|
||||||
let myFunction2 = function (file?) {
|
if (counter === 2) {
|
||||||
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 logFileFunction = function (file) {
|
|
||||||
let done = Q.defer()
|
|
||||||
console.log(file.contents)
|
|
||||||
if (typeof file.contents !== 'undefined') {
|
|
||||||
|
|
||||||
} else {
|
|
||||||
throw new Error('file.contents not present')
|
|
||||||
}
|
|
||||||
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()
|
done.resolve()
|
||||||
}, 500)
|
}
|
||||||
return done.promise
|
}))
|
||||||
}
|
await 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(logFileFunction,'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(){
|
|
||||||
let done = Q.defer()
|
|
||||||
beautylog.log('nextStep')
|
|
||||||
done.resolve()
|
|
||||||
return done.promise
|
|
||||||
}))
|
|
||||||
.pipe(gulpFunction(afterFunction,'atEnd'))
|
|
||||||
.pipe(gulpFunction(timeoutFunction,'atEnd'))
|
|
||||||
|
|
||||||
stream.on('finish',function(){
|
|
||||||
beautylog.info('stream finished')
|
|
||||||
done()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
tap.test('should run through smoothly with ' + "'forEach'", async (tools) => {
|
||||||
|
let done = smartq.defer()
|
||||||
|
let counter = 0
|
||||||
|
smartgulp.src(['./test/testfiles/*.md'])
|
||||||
|
.pipe(gulpFunction.atEnd(async () => {
|
||||||
|
console.log('atEnd')
|
||||||
|
done.resolve()
|
||||||
|
}))
|
||||||
|
await done.promise
|
||||||
|
})
|
||||||
|
|
||||||
|
tap.start()
|
||||||
|
@ -1,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
|
114
ts/index.ts
114
ts/index.ts
@ -1,89 +1,89 @@
|
|||||||
import 'typings-global'
|
import 'typings-global'
|
||||||
import * as q from 'q'
|
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 q.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 {
|
|
||||||
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 {
|
} else {
|
||||||
cb()
|
cb(null, file)
|
||||||
}
|
}
|
||||||
|
hasExecutedOnce = true
|
||||||
|
break
|
||||||
|
case 'atEnd':
|
||||||
|
cb()
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
break
|
||||||
}
|
}
|
||||||
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) => {
|
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
|
||||||
|
Reference in New Issue
Block a user