Compare commits
14 Commits
Author | SHA1 | Date | |
---|---|---|---|
a1fa6b751e | |||
5792a13b01 | |||
1008c3f103 | |||
c366bde211 | |||
e22c6764b7 | |||
50836eab06 | |||
077834f7a4 | |||
ca348b5475 | |||
2c9ab52cee | |||
7d35f4c90b | |||
a05253bdcd | |||
54b80098d2 | |||
c39a4a6cb0 | |||
f325479a11 |
19
.gitignore
vendored
19
.gitignore
vendored
@ -1,5 +1,22 @@
|
|||||||
node_modules/
|
.nogit/
|
||||||
|
|
||||||
|
# artifacts
|
||||||
coverage/
|
coverage/
|
||||||
public/
|
public/
|
||||||
pages/
|
pages/
|
||||||
|
|
||||||
|
# installs
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# caches
|
||||||
|
.yarn/
|
||||||
|
.cache/
|
||||||
|
.rpt2_cache
|
||||||
|
|
||||||
|
# builds
|
||||||
|
dist/
|
||||||
|
dist_web/
|
||||||
|
dist_serve/
|
||||||
|
dist_ts_web/
|
||||||
|
|
||||||
|
# custom
|
132
.gitlab-ci.yml
132
.gitlab-ci.yml
@ -1,86 +1,126 @@
|
|||||||
# gitzone standard
|
# gitzone ci_default
|
||||||
image: hosttoday/ht-docker-node:npmci
|
image: registry.gitlab.com/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
|
- lossless
|
||||||
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
testLEGACY:
|
snyk:
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-node:snyk
|
||||||
|
stage: security
|
||||||
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci command npm install --ignore-scripts
|
||||||
|
- npmci command snyk test
|
||||||
|
tags:
|
||||||
|
- lossless
|
||||||
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
|
# ====================
|
||||||
|
# test stage
|
||||||
|
# ====================
|
||||||
|
|
||||||
|
testStable:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci node install legacy
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci node install stable
|
||||||
- npmci npm test
|
- npmci npm install
|
||||||
|
- npmci npm test
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
allow_failure: true
|
- docker
|
||||||
|
- priv
|
||||||
|
|
||||||
testLTS:
|
testBuild:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci node install lts
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci node install stable
|
||||||
- npmci npm test
|
- npmci npm install
|
||||||
|
- npmci command npm run build
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
|
- docker
|
||||||
testSTABLE:
|
- notpriv
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci node install stable
|
|
||||||
- npmci npm install
|
|
||||||
- npmci npm test
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
|
|
||||||
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
|
- lossless
|
||||||
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
|
# ====================
|
||||||
|
# metadata stage
|
||||||
|
# ====================
|
||||||
|
codequality:
|
||||||
|
stage: metadata
|
||||||
|
allow_failure: true
|
||||||
|
script:
|
||||||
|
- npmci command npm install -g tslint typescript
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci npm install
|
||||||
|
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||||
|
tags:
|
||||||
|
- lossless
|
||||||
|
- docker
|
||||||
|
- priv
|
||||||
|
|
||||||
trigger:
|
trigger:
|
||||||
stage: trigger
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci trigger
|
- npmci trigger
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
pages:
|
pages:
|
||||||
image: hosttoday/ht-docker-node:npmci
|
stage: metadata
|
||||||
stage: pages
|
|
||||||
script:
|
script:
|
||||||
- npmci command yarn global add npmpage
|
- npmci node install lts
|
||||||
- npmci command npmpage
|
- npmci command npm install -g @gitzone/tsdoc
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci npm install
|
||||||
|
- npmci command tsdoc
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- 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
|
||||||
|
63
README.md
63
README.md
@ -1,63 +0,0 @@
|
|||||||
# gulp-function
|
|
||||||
|
|
||||||
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/)
|
|
||||||
|
|
||||||
## 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://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
|
|
||||||
|
|
||||||
```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(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**!!!
|
|
||||||
|
|
||||||
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
11
dist/index.d.ts
vendored
@ -1,11 +0,0 @@
|
|||||||
/// <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
76
dist/index.js
vendored
@ -1,76 +0,0 @@
|
|||||||
"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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUNBLHFDQUFxQztBQVNyQyxJQUFJLGFBQWEsR0FBRyxDQUNsQixxQkFBNEQsRUFDNUQsbUJBQW1DLFNBQVMsRUFDakMsRUFBRTtJQUNiLElBQUksWUFBWSxHQUFHLEVBQUUsQ0FBQztJQUN0QixJQUFJLFdBQVcsR0FBRyxVQUFTLFdBQVcsRUFBRSxJQUFJLEVBQUUsR0FBRztRQUMvQyxJQUFJLFdBQVcsR0FBRyxXQUFXLENBQUMsSUFBSSxFQUFFLEdBQUcsQ0FBQyxDQUFDO1FBQ3pDLEVBQUUsQ0FBQyxDQUNELE9BQU8sV0FBVyxLQUFLLFdBQVc7WUFDbEMsT0FBTyxXQUFXLENBQUMsSUFBSSxLQUFLLFdBQzlCLENBQUMsQ0FBQyxDQUFDO1lBQ0QsWUFBWSxDQUFDLElBQUksQ0FBQyxXQUFXLENBQUMsQ0FBQztRQUNqQyx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Q0FBQztBQUVTLFFBQUEsT0FBTyxHQUFHLENBQUMsT0FBeUIsRUFBRSxFQUFFO0lBQ2pELE1BQU0sQ0FBQyxhQUFhLENBQUMsT0FBTyxFQUFFLFNBQVMsQ0FBQyxDQUFDO0FBQzNDLENBQUMsQ0FBQztBQUVTLFFBQUEsUUFBUSxHQUFHLENBQUMsT0FBeUIsRUFBRSxFQUFFO0lBQ2xELE1BQU0sQ0FBQyxhQUFhLENBQUMsT0FBTyxFQUFFLFVBQVUsQ0FBQyxDQUFDO0FBQzVDLENBQUMsQ0FBQztBQUVTLFFBQUEsS0FBSyxHQUFHLENBQUMsT0FBeUIsRUFBRSxFQUFFO0lBQy9DLE1BQU0sQ0FBQyxhQUFhLENBQUMsT0FBTyxFQUFFLE9BQU8sQ0FBQyxDQUFDO0FBQ3pDLENBQUMsQ0FBQztBQUVGLGtCQUFlLGFBQWEsQ0FBQyJ9
|
|
@ -3,8 +3,17 @@
|
|||||||
"mode": "default"
|
"mode": "default"
|
||||||
},
|
},
|
||||||
"npmci": {
|
"npmci": {
|
||||||
"globalNpmTools": [
|
"npmGlobalTools": [],
|
||||||
"npmts"
|
"npmAccessLevel": "public"
|
||||||
]
|
},
|
||||||
|
"gitzone": {
|
||||||
|
"module": {
|
||||||
|
"githost": "gitlab.com",
|
||||||
|
"gitscope": "pushrocks",
|
||||||
|
"gitrepo": "gulp-function",
|
||||||
|
"shortDescription": "accepts a function call as parameter to execute in gulp pipeline",
|
||||||
|
"npmPackagename": "@pushrocks/gulp-function",
|
||||||
|
"license": "MIT"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
5454
package-lock.json
generated
Normal file
5454
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
35
package.json
35
package.json
@ -1,11 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "gulp-function",
|
"name": "@pushrocks/gulp-function",
|
||||||
"version": "2.2.13",
|
"private": false,
|
||||||
|
"version": "3.0.2",
|
||||||
"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",
|
||||||
@ -24,13 +26,28 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/gulp-function",
|
"homepage": "https://gitlab.com/pushrocks/gulp-function",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@pushrocks/smartpromise": "^3.0.6",
|
||||||
"@types/through2": "^2.0.32",
|
"@types/through2": "^2.0.32",
|
||||||
"smartq": "^1.1.6",
|
"through2": "^3.0.1"
|
||||||
"through2": "^2.0.3"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"gulp": "^3.9.1",
|
"@gitzone/tsbuild": "^2.1.17",
|
||||||
"smartgulp": "^1.0.1",
|
"@gitzone/tstest": "^1.0.28",
|
||||||
"tapbundle": "^1.0.10"
|
"@pushrocks/smartgulp": "^2.0.2",
|
||||||
}
|
"@pushrocks/tapbundle": "^3.2.0",
|
||||||
|
"gulp": "^4.0.2",
|
||||||
|
"tslint": "^5.20.1",
|
||||||
|
"tslint-config-prettier": "^1.18.0"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"ts/**/*",
|
||||||
|
"ts_web/**/*",
|
||||||
|
"dist/**/*",
|
||||||
|
"dist_web/**/*",
|
||||||
|
"dist_ts_web/**/*",
|
||||||
|
"assets/**/*",
|
||||||
|
"cli.js",
|
||||||
|
"npmextra.json",
|
||||||
|
"readme.md"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
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();
|
||||||
|
35
ts/index.ts
35
ts/index.ts
@ -1,8 +1,8 @@
|
|||||||
import * as q from "smartq";
|
import * as smartpromise from '@pushrocks/smartpromise';
|
||||||
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>;
|
||||||
@ -10,30 +10,25 @@ export interface IPromiseFunction {
|
|||||||
|
|
||||||
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 (
|
if (typeof returnValue !== 'undefined' && typeof returnValue.then !== 'undefined') {
|
||||||
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(
|
throw new Error('gulp-callfunction: something is strange with the given arguments');
|
||||||
"gulp-callfunction: something is strange with the given arguments"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return Promise.all(promiseArray);
|
return Promise.all(promiseArray);
|
||||||
};
|
};
|
||||||
@ -42,12 +37,12 @@ let defaultExport = (
|
|||||||
let forEach = function(file, enc, cb) {
|
let forEach = function(file, enc, cb) {
|
||||||
// the forEach function is called for every chunk
|
// 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).then(function() {
|
checkAndRunFunction(file, enc).then(function() {
|
||||||
cb(null, file);
|
cb(null, file);
|
||||||
@ -57,7 +52,7 @@ let defaultExport = (
|
|||||||
}
|
}
|
||||||
hasExecutedOnce = true;
|
hasExecutedOnce = true;
|
||||||
break;
|
break;
|
||||||
case "atEnd":
|
case 'atEnd':
|
||||||
cb();
|
cb();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -66,7 +61,7 @@ let defaultExport = (
|
|||||||
};
|
};
|
||||||
|
|
||||||
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();
|
||||||
});
|
});
|
||||||
@ -78,15 +73,15 @@ let defaultExport = (
|
|||||||
};
|
};
|
||||||
|
|
||||||
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