Compare commits
79 Commits
Author | SHA1 | Date | |
---|---|---|---|
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 | |||
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 | |||
ac9305c480 | |||
a51419f2b0 | |||
4b02d17d6d | |||
57350d6fee | |||
dcdf0059cc | |||
9cc9e15b04 |
10
.gitignore
vendored
10
.gitignore
vendored
@ -1,9 +1,5 @@
|
|||||||
node_modules/
|
node_modules/
|
||||||
.settings/
|
coverage/
|
||||||
.idea/
|
public/
|
||||||
|
pages/
|
||||||
ts/*.js
|
|
||||||
ts/*.js.map
|
|
||||||
ts/typings/
|
|
||||||
test/result/
|
|
||||||
|
|
||||||
|
96
.gitlab-ci.yml
Normal file
96
.gitlab-ci.yml
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
# gitzone standard
|
||||||
|
image: hosttoday/ht-docker-node:npmci
|
||||||
|
|
||||||
|
cache:
|
||||||
|
paths:
|
||||||
|
- .yarn/
|
||||||
|
key: "$CI_BUILD_STAGE"
|
||||||
|
|
||||||
|
stages:
|
||||||
|
- mirror
|
||||||
|
- security
|
||||||
|
- test
|
||||||
|
- release
|
||||||
|
- trigger
|
||||||
|
- pages
|
||||||
|
|
||||||
|
mirror:
|
||||||
|
stage: mirror
|
||||||
|
script:
|
||||||
|
- npmci git mirror
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
|
||||||
|
security:
|
||||||
|
stage: security
|
||||||
|
script:
|
||||||
|
- npmci command yarn global add snyk
|
||||||
|
- npmci command yarn install --ignore-scripts
|
||||||
|
- npmci command snyk test
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
|
||||||
|
testLEGACY:
|
||||||
|
stage: test
|
||||||
|
script:
|
||||||
|
- npmci node install legacy
|
||||||
|
- npmci npm install
|
||||||
|
- npmci npm test
|
||||||
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
allow_failure: true
|
||||||
|
|
||||||
|
testLTS:
|
||||||
|
stage: test
|
||||||
|
script:
|
||||||
|
- npmci node install lts
|
||||||
|
- npmci npm install
|
||||||
|
- npmci npm test
|
||||||
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
|
||||||
|
testSTABLE:
|
||||||
|
stage: test
|
||||||
|
script:
|
||||||
|
- npmci node install stable
|
||||||
|
- npmci npm install
|
||||||
|
- npmci npm test
|
||||||
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
|
||||||
|
release:
|
||||||
|
stage: release
|
||||||
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci npm 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/
|
ts/
|
||||||
test/
|
test/
|
||||||
|
docs/
|
||||||
|
coverage/
|
||||||
node_modules/
|
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=
|
|
69
README.md
69
README.md
@ -1,26 +1,63 @@
|
|||||||
# gulp-function
|
# gulp-function
|
||||||
accepts call to execute in gulp pipeline.
|
|
||||||
|
|
||||||
### build status/Dependencies
|
accepts a function call as parameter to execute in gulp pipeline
|
||||||
[](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://www.npmjs.com/package/gulp-function)
|
||||||
[](https://david-dm.org/pushrocks/gulp-function)
|
[](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://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||||
|
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||||
|
[](http://standardjs.com/)
|
||||||
|
|
||||||
### Usage
|
### Usage
|
||||||
```javascript
|
|
||||||
var gulp = require("gulp");
|
|
||||||
var gulpFunction = require("gulp-function");
|
|
||||||
|
|
||||||
var myFunction = function () {
|
```typescript
|
||||||
console.log("Hello World!")
|
import gulp = require('gulp');
|
||||||
}
|
import gulpFunction from "gulp-function"; // default ES6 export
|
||||||
|
// import {forFirst, forEach, atEnd} from 'gulp-function'
|
||||||
|
|
||||||
gulp.task('gulpTest',function() {
|
let myAsyncFunction = async (file, enc) => {
|
||||||
gulp.src('./mydir/*.something')
|
// await some async stuff
|
||||||
.pipe(gulpFunction(myFunction,'forEach'))
|
};
|
||||||
.pipe(gulp.dest("./build/"))
|
|
||||||
|
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.
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
>Note: The first argument of gulpFunction can also be an array of multiple functionnames.
|
### Notes
|
||||||
>Note: the second argument can be empty (defaults to 'forEach') or 'atEnd'
|
|
||||||
|
* 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.
|
||||||
|
|
||||||
|
> 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)
|
||||||
|
11
dist/index.d.ts
vendored
Normal file
11
dist/index.d.ts
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
/// <reference types="node" />
|
||||||
|
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 });
|
||||||
|
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) {
|
||||||
|
// 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();
|
||||||
|
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUNBLHFDQUFxQztBQVNyQyxJQUFJLGFBQWEsR0FBRyxDQUNsQixxQkFBNEQsRUFDNUQsbUJBQW1DLFNBQVMsRUFDakMsRUFBRTtJQUNiLElBQUksWUFBWSxHQUFHLEVBQUUsQ0FBQztJQUN0QixJQUFJLFdBQVcsR0FBRyxVQUFTL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EVBQUUsSUFBSSxDQUFDLENBQUMsSUFBSSxDQUFDO2dCQUNuQyxFQUFFLEVBQUUsQ0FBQztZQUNQLENBQUMsQ0FBQyxDQUFDO1FBQ0wsQ0FBQztRQUFDLElBQUksQ0FBQyxDQUFDO1lBQ04sRUFBRSxFQUFFLENBQUM7UUFDUCxDQUFDO0lBQ0gsQ0FBQyxDQUFDO0lBQ0YsTUFBTSxDQUFDLFFBQVEsQ0FBQyxHQUFHLENBQUMsT0FBTyxFQUFFLEtBQUssQ0FBQyxDQUFDO0FBQ3RDLENBQUMsQ0FBQztBQUVTLFFBQUEsT0FBTyxHQUFHLENBQUMsT0FBeUIsRUFBRSxFQUFFO0lBQ2pELE1BQU0sQ0FBQyxhQUFhLENBQUMsT0FBTyxFQUFFLFNBQVMsQ0FBQyxDQUFDO0FBQzNDLENBQUMsQ0FBQztBQUVTLFFBQUEsUUFBUSxHQUFHLENBQUMsT0FBeUIsRUFBRSxFQUFFO0lBQ2xELE1BQU0sQ0FBQyxhQUFhLENBQUMsT0FBTyxFQUFFLFVBQVUsQ0FBQyxDQUFDO0FBQzVDLENBQUMsQ0FBQztBQUVTLFFBQUEsS0FBSyxHQUFHLENBQUMsT0FBeUIsRUFBRSxFQUFFO0lBQy9DLE1BQU0sQ0FBQyxhQUFhLENBQUMsT0FBTyxFQUFFLE9BQU8sQ0FBQyxDQUFDO0FBQ3pDLENBQUMsQ0FBQztBQUVGLGtCQUFlLGFBQWEsQ0FBQyJ9
|
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;
|
|
47
index.js
47
index.js
@ -1,47 +0,0 @@
|
|||||||
#!/usr/bin/env node
|
|
||||||
|
|
||||||
/// <reference path="typings/main.d.ts" />
|
|
||||||
var through = require("through2");
|
|
||||||
var path = require("path");
|
|
||||||
var beautylog = require("beautylog");
|
|
||||||
module.exports = function (functionsToExecuteArg, executionModeArg, logBoolArg) {
|
|
||||||
if (executionModeArg === void 0) { executionModeArg = 'forEach'; }
|
|
||||||
if (logBoolArg === void 0) { logBoolArg = false; }
|
|
||||||
//important vars
|
|
||||||
var gulpFunction = {
|
|
||||||
executionMode: executionModeArg,
|
|
||||||
functionsToExecute: functionsToExecuteArg,
|
|
||||||
logBool: logBoolArg
|
|
||||||
};
|
|
||||||
var runFunctionNames = function () {
|
|
||||||
if (typeof gulpFunction.functionsToExecute == "function") {
|
|
||||||
gulpFunction.functionsToExecute();
|
|
||||||
}
|
|
||||||
else if (Array.isArray(gulpFunction.functionsToExecute)) {
|
|
||||||
for (var anyFunction in gulpFunction.functionsToExecute) {
|
|
||||||
anyFunction();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
beautylog.error('gulp-callfunction: something is strange with the given arguments');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
var forEach = function (file, enc, cb) {
|
|
||||||
if (gulpFunction.logBool)
|
|
||||||
beautylog.log(gulpFunction.executionMode);
|
|
||||||
if (gulpFunction.executionMode === 'forEach') {
|
|
||||||
if (gulpFunction.logBool)
|
|
||||||
beautylog.log('is forEach');
|
|
||||||
runFunctionNames();
|
|
||||||
}
|
|
||||||
//tell gulp that we are complete
|
|
||||||
return cb(null, file);
|
|
||||||
};
|
|
||||||
var atEnd = function (cb) {
|
|
||||||
if (gulpFunction.executionMode == "atEnd") {
|
|
||||||
runFunctionNames();
|
|
||||||
}
|
|
||||||
cb();
|
|
||||||
};
|
|
||||||
return through.obj(forEach, atEnd);
|
|
||||||
};
|
|
10
npmextra.json
Normal file
10
npmextra.json
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"npmts": {
|
||||||
|
"mode": "default"
|
||||||
|
},
|
||||||
|
"npmci": {
|
||||||
|
"npmGlobalTools": [
|
||||||
|
"npmts"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
31
package.json
31
package.json
@ -1,35 +1,36 @@
|
|||||||
{
|
{
|
||||||
"name": "gulp-function",
|
"name": "gulp-function",
|
||||||
"version": "1.0.1",
|
"version": "2.2.14",
|
||||||
"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": "index.js",
|
"main": "dist/index.js",
|
||||||
|
"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",
|
||||||
"url": "https://github.com/pushrocks/gulp-function.git"
|
"url": "https://gitlab.com/pushrocks/gulp-function.git"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"gulpplugin",
|
"gulpplugin",
|
||||||
"gulp",
|
"gulp",
|
||||||
"function"
|
"function",
|
||||||
|
"pushrocks"
|
||||||
],
|
],
|
||||||
"author": "Smart Coordination GmbH <office@push.rocks> (https://push.rocks)",
|
"author": "Lossless GmbH <office@lossless.com> (https://lossless.com)",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"bugs": {
|
"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": {
|
"dependencies": {
|
||||||
"beautylog": "2.0.4",
|
"@types/through2": "^2.0.32",
|
||||||
"through2": "2.0.0"
|
"smartq": "^1.1.6",
|
||||||
|
"through2": "^2.0.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"gulp": "^3.9.0",
|
"gulp": "^3.9.1",
|
||||||
"npmts": "^2.0.2"
|
"smartgulp": "^1.0.1",
|
||||||
|
"tapbundle": "^1.0.10"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
17
test/test.js
17
test/test.js
@ -1,17 +0,0 @@
|
|||||||
/// <reference path="typings/main.d.ts" />
|
|
||||||
var gulp = require("gulp");
|
|
||||||
var gulpFunction = require("../index.js");
|
|
||||||
var beautylog = require("beautylog");
|
|
||||||
var myFunction = function () {
|
|
||||||
beautylog.log("Mocha Test successfull!");
|
|
||||||
};
|
|
||||||
describe("gulpFunction", function () {
|
|
||||||
it("should run through smoothly", function () {
|
|
||||||
gulp.task('default', function () {
|
|
||||||
gulp.src('./test/test.md')
|
|
||||||
.pipe(gulpFunction(myFunction, 'forEach'))
|
|
||||||
.pipe(gulp.dest("./test/result/"));
|
|
||||||
});
|
|
||||||
gulp.start.apply(gulp, ['default']);
|
|
||||||
});
|
|
||||||
});
|
|
@ -1,2 +0,0 @@
|
|||||||
# Test.md
|
|
||||||
This is a test file for the test.js gulp pipeline
|
|
33
test/test.ts
Normal file
33
test/test.ts
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import { expect, tap } from 'tapbundle'
|
||||||
|
|
||||||
|
import * as smartgulp from 'smartgulp'
|
||||||
|
let gulp = require('gulp')
|
||||||
|
import * as gulpFunction from '../ts/index'
|
||||||
|
|
||||||
|
let smartq = require('smartq')
|
||||||
|
|
||||||
|
tap.test('should run through smoothly with ' + "'forEach'", async (tools) => {
|
||||||
|
let done = smartq.defer()
|
||||||
|
let counter = 0
|
||||||
|
gulp.src('./test/testfiles/*.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
|
||||||
|
smartgulp.src(['./test/testfiles/*.md'])
|
||||||
|
.pipe(gulpFunction.atEnd(async () => {
|
||||||
|
console.log('atEnd')
|
||||||
|
done.resolve()
|
||||||
|
}))
|
||||||
|
await done.promise
|
||||||
|
})
|
||||||
|
|
||||||
|
tap.start()
|
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
|
123
ts/index.ts
123
ts/index.ts
@ -1,45 +1,92 @@
|
|||||||
/// <reference path="typings/main.d.ts" />
|
import * as q from "smartq";
|
||||||
var through = require("through2");
|
import * as through2 from "through2";
|
||||||
var path = require("path");
|
import { Transform } from "stream";
|
||||||
var beautylog = require("beautylog");
|
|
||||||
|
|
||||||
|
export type TExecutionMode = "forEach" | "forFirst" | "atEnd";
|
||||||
|
|
||||||
module.exports = function (functionsToExecuteArg:any|any[],executionModeArg:string = 'forEach', logBoolArg = false) {
|
export interface IPromiseFunction {
|
||||||
//important vars
|
(file?, enc?): PromiseLike<any>;
|
||||||
var gulpFunction = {
|
}
|
||||||
executionMode: executionModeArg, //can be forEach or atEnd
|
|
||||||
functionsToExecute: functionsToExecuteArg,
|
|
||||||
logBool: logBoolArg
|
|
||||||
};
|
|
||||||
|
|
||||||
var runFunctionNames = function () {
|
let defaultExport = (
|
||||||
if (typeof gulpFunction.functionsToExecute == "function" ) {
|
functionsToExecuteArg: IPromiseFunction | IPromiseFunction[],
|
||||||
gulpFunction.functionsToExecute();
|
executionModeArg: TExecutionMode = "forEach"
|
||||||
} else if (Array.isArray(gulpFunction.functionsToExecute)) {
|
): Transform => {
|
||||||
for (var anyFunction in gulpFunction.functionsToExecute) {
|
let promiseArray = [];
|
||||||
anyFunction();
|
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 {
|
} else {
|
||||||
beautylog.error('gulp-callfunction: something is strange with the given arguments');
|
cb(null, file);
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
var forEach = function (file, enc, cb) {
|
|
||||||
if (gulpFunction.logBool) beautylog.log(gulpFunction.executionMode);
|
|
||||||
if (gulpFunction.executionMode === 'forEach') {
|
|
||||||
if(gulpFunction.logBool) beautylog.log('is forEach');
|
|
||||||
runFunctionNames();
|
|
||||||
}
|
|
||||||
//tell gulp that we are complete
|
|
||||||
return cb(null, file);
|
|
||||||
};
|
|
||||||
|
|
||||||
var atEnd = function(cb) {
|
|
||||||
if (gulpFunction.executionMode == "atEnd") {
|
|
||||||
runFunctionNames();
|
|
||||||
}
|
}
|
||||||
|
hasExecutedOnce = true;
|
||||||
|
break;
|
||||||
|
case "atEnd":
|
||||||
cb();
|
cb();
|
||||||
};
|
break;
|
||||||
return through.obj(forEach,atEnd);
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
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 let forFirst = (funcArg: IPromiseFunction) => {
|
||||||
|
return defaultExport(funcArg, "forFirst");
|
||||||
|
};
|
||||||
|
|
||||||
|
export let atEnd = (funcArg: IPromiseFunction) => {
|
||||||
|
return defaultExport(funcArg, "atEnd");
|
||||||
|
};
|
||||||
|
|
||||||
|
export default defaultExport;
|
||||||
|
20
ts/test.ts
20
ts/test.ts
@ -1,20 +0,0 @@
|
|||||||
/// <reference path="typings/main.d.ts" />
|
|
||||||
var gulp = require("gulp");
|
|
||||||
var gulpFunction = require("../index.js");
|
|
||||||
var beautylog = require("beautylog");
|
|
||||||
|
|
||||||
var myFunction = function () {
|
|
||||||
beautylog.log("Mocha Test successfull!");
|
|
||||||
};
|
|
||||||
|
|
||||||
describe("gulpFunction",function(){
|
|
||||||
it("should run through smoothly",function(){
|
|
||||||
gulp.task('default',function() {
|
|
||||||
gulp.src('./test/test.md')
|
|
||||||
.pipe(gulpFunction(myFunction,'forEach'))
|
|
||||||
.pipe(gulp.dest("./test/result/"))
|
|
||||||
});
|
|
||||||
gulp.start.apply(gulp, ['default']);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
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