fix(core): update to latest gitzone standards
This commit is contained in:
parent
a05253bdcd
commit
7d35f4c90b
@ -3,94 +3,123 @@ image: hosttoday/ht-docker-node:npmci
|
|||||||
|
|
||||||
cache:
|
cache:
|
||||||
paths:
|
paths:
|
||||||
- .yarn/
|
- .npmci_cache/
|
||||||
key: "$CI_BUILD_STAGE"
|
key: "$CI_BUILD_STAGE"
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- mirror
|
|
||||||
- security
|
- security
|
||||||
- test
|
- test
|
||||||
- release
|
- release
|
||||||
- trigger
|
- metadata
|
||||||
- pages
|
|
||||||
|
|
||||||
|
# ====================
|
||||||
|
# security stage
|
||||||
|
# ====================
|
||||||
mirror:
|
mirror:
|
||||||
stage: mirror
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci git mirror
|
- npmci git mirror
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
security:
|
snyk:
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci command yarn global add snyk
|
- npmci npm prepare
|
||||||
- npmci command yarn install --ignore-scripts
|
- npmci command npm install -g snyk
|
||||||
|
- npmci command npm install --ignore-scripts
|
||||||
- npmci command snyk test
|
- npmci command snyk test
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
testLEGACY:
|
# ====================
|
||||||
stage: test
|
# test stage
|
||||||
script:
|
# ====================
|
||||||
- npmci node install legacy
|
|
||||||
- npmci npm install
|
|
||||||
- npmci npm test
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
allow_failure: true
|
|
||||||
|
|
||||||
testLTS:
|
testLTS:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
- npmci node install lts
|
- npmci node install lts
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci npm test
|
- npmci npm test
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
testSTABLE:
|
testSTABLE:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
- npmci node install stable
|
- npmci node install stable
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci npm test
|
- npmci npm test
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
release:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci node install stable
|
||||||
- npmci npm publish
|
- npmci npm publish
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
|
# ====================
|
||||||
|
# metadata stage
|
||||||
|
# ====================
|
||||||
|
codequality:
|
||||||
|
stage: metadata
|
||||||
|
image: docker:stable
|
||||||
|
allow_failure: true
|
||||||
|
services:
|
||||||
|
- docker:stable-dind
|
||||||
|
script:
|
||||||
|
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
||||||
|
- docker run
|
||||||
|
--env SOURCE_CODE="$PWD"
|
||||||
|
--volume "$PWD":/code
|
||||||
|
--volume /var/run/docker.sock:/var/run/docker.sock
|
||||||
|
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
|
||||||
|
artifacts:
|
||||||
|
paths: [codeclimate.json]
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
- priv
|
||||||
|
|
||||||
trigger:
|
trigger:
|
||||||
stage: trigger
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci trigger
|
- npmci trigger
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
pages:
|
pages:
|
||||||
image: hosttoday/ht-docker-node:npmci
|
image: hosttoday/ht-docker-node:npmci
|
||||||
stage: pages
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci command yarn global add npmpage
|
- npmci command npm install -g typedoc typescript
|
||||||
- npmci command npmpage
|
- npmci npm prepare
|
||||||
|
- npmci npm install
|
||||||
|
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
- notpriv
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
artifacts:
|
artifacts:
|
||||||
expire_in: 1 week
|
expire_in: 1 week
|
||||||
paths:
|
paths:
|
||||||
- public
|
- public
|
||||||
|
allow_failure: true
|
||||||
|
24
README.md
24
README.md
@ -15,8 +15,6 @@ accepts a function call as parameter to execute in gulp pipeline
|
|||||||
[![coverage report](https://GitLab.com/pushrocks/gulp-function/badges/master/coverage.svg)](https://GitLab.com/pushrocks/gulp-function/commits/master)
|
[![coverage report](https://GitLab.com/pushrocks/gulp-function/badges/master/coverage.svg)](https://GitLab.com/pushrocks/gulp-function/commits/master)
|
||||||
[![npm downloads per month](https://img.shields.io/npm/dm/gulp-function.svg)](https://www.npmjs.com/package/gulp-function)
|
[![npm downloads per month](https://img.shields.io/npm/dm/gulp-function.svg)](https://www.npmjs.com/package/gulp-function)
|
||||||
[![Dependency Status](https://david-dm.org/pushrocks/gulp-function.svg)](https://david-dm.org/pushrocks/gulp-function)
|
[![Dependency Status](https://david-dm.org/pushrocks/gulp-function.svg)](https://david-dm.org/pushrocks/gulp-function)
|
||||||
[![bitHound Dependencies](https://www.bithound.io/github/pushrocks/gulp-function/badges/dependencies.svg)](https://www.bithound.io/github/pushrocks/gulp-function/master/dependencies/npm)
|
|
||||||
[![bitHound Code](https://www.bithound.io/github/pushrocks/gulp-function/badges/code.svg)](https://www.bithound.io/github/pushrocks/gulp-function)
|
|
||||||
[![TypeScript](https://img.shields.io/badge/TypeScript-2.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
[![TypeScript](https://img.shields.io/badge/TypeScript-2.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||||
[![node](https://img.shields.io/badge/node->=%206.x.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
[![node](https://img.shields.io/badge/node->=%206.x.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||||
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
|
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
|
||||||
@ -25,34 +23,34 @@ accepts a function call as parameter to execute in gulp pipeline
|
|||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
import gulp = require('gulp');
|
import gulp = require('gulp');
|
||||||
import gulpFunction from "gulp-function"; // default ES6 export
|
import gulpFunction from 'gulp-function'; // default ES6 export
|
||||||
// import {forFirst, forEach, atEnd} from 'gulp-function'
|
// import {forFirst, forEach, atEnd} from 'gulp-function'
|
||||||
|
|
||||||
let myAsyncFunction = async (file, enc) => {
|
let myAsyncFunction = async (file, enc) => {
|
||||||
// await some async stuff
|
// await some async stuff
|
||||||
};
|
};
|
||||||
|
|
||||||
gulp.task("gulpTest", function() {
|
gulp.task('gulpTest', function() {
|
||||||
let stream = gulp
|
let stream = gulp
|
||||||
.src("./mydir/*.something")
|
.src('./mydir/*.something')
|
||||||
.pipe(gulpFunction(myAsyncFunction, "forEach")) //read the notes below
|
.pipe(gulpFunction(myAsyncFunction, 'forEach')) //read the notes below
|
||||||
// .pipe(forEach(myAsyncFunction)) // if imported as >> import { forEach } from 'gulp-function' <<
|
// .pipe(forEach(myAsyncFunction)) // if imported as >> import { forEach } from 'gulp-function' <<
|
||||||
.pipe(gulp.dest("./build/"));
|
.pipe(gulp.dest('./build/'));
|
||||||
return stream; // by returning the stream gulp knows when our task has finished.
|
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**.
|
- 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.
|
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
|
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 second argument can be empty, it defaults to "forEach"
|
||||||
* The following options are available:
|
- The following options are available:
|
||||||
* "forFirst" - executes when first chunk/vinylfile of the stream reaches the pipestop.
|
- "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.
|
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;
|
- "forEach" - executes like "forFirst" but with every chunk/vinylfile in the stream;
|
||||||
* "atEnd" - executes after all chunks have passed and are processed in full.
|
- "atEnd" - executes after all chunks have passed and are processed in full.
|
||||||
That means the stream's "finish" event fires **before "atLast" is executed**!!!
|
That means the stream's "finish" event fires **before "atLast" is executed**!!!
|
||||||
|
|
||||||
For further information read the linked docs at the top of this README.
|
For further information read the linked docs at the top of this README.
|
||||||
|
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUNBLHFDQUFxQztBQVNyQyxJQUFJLGFBQWEsR0FBRyxDQUNsQixxQkFBNEQsRUFDNUQsbUJBQW1DLFNBQVMsRUFDakMsRUFBRTtJQUNiLElBQUksWUFBWSxHQUFHLEVBQUUsQ0FBQztJQUN0QixJQUFJLFdBQVcsR0FBRyxVQUFTLFdBQVcsRUFBRSxJQUFJLEVBQUUsR0FBRztRQUMvQyxJQUFJLFdBQVcsR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EVBQUUsQ0FBQztZQUNQLENBQUMsQ0FBQyxDQUFDO1FBQ0wsQ0FBQztRQUFDLElBQUksQ0FBQyxDQUFDO1lBQ04sRUFBRSxFQUFFLENBQUM7UUFDUCxDQUFDO0lBQ0gsQ0FBQyxDQUFDO0lBQ0YsTUFBTSxDQUFDLFFBQVEsQ0FBQyxHQUFHLENBQUMsT0FBTyxFQUFFLEtBQUssQ0FBQyxDQUFDO0FBQ3RDLENBQUMsQ0FBQztBQUVTLFFBQUEsT0FBTyxHQUFHLENBQUMsT0FBeUIsRUFBRSxFQUFFO0lBQ2pELE1BQU0sQ0FBQyxhQUFhLENBQUMsT0FBTyxFQUFFLFNBQVMsQ0FBQyxDQUFDO0FBQzNDLENBQUMsQ0FBQztBQUVTLFFBQUEsUUFBUSxHQUFHLENBQUMsT0FBeUIsRUFBRSxFQUFFO0lBQ2xELE1BQU0sQ0FBQyxhQUFhLENBQUMsT0FBTyxFQUFFLFVBQVUsQ0FBQyxDQUFDO0FBQzVDLENBQUMsQ0FBQztBQUVTLFFBQUEsS0FBSyxHQUFHLENBQUMsT0FBeUIsRUFBRSxFQUFFO0lBQy9DLE1BQU0sQ0FBQyxhQUFhLENBQUMsT0FBTyxFQUFFLE9BQU8sQ0FBQyxDQUFDO0FBQ3pDLENBQUMsQ0FBQztBQUVGLGtCQUFlLGFBQWEsQ0FBQyJ9
|
|
4015
package-lock.json
generated
Normal file
4015
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
18
package.json
18
package.json
@ -5,7 +5,8 @@
|
|||||||
"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 +25,18 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/gulp-function",
|
"homepage": "https://gitlab.com/pushrocks/gulp-function",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@pushrocks/smartpromise": "^2.0.5",
|
||||||
"@types/through2": "^2.0.32",
|
"@types/through2": "^2.0.32",
|
||||||
"smartq": "^1.1.6",
|
"through2": "^3.0.0"
|
||||||
"through2": "^2.0.3"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@gitzone/tsbuild": "^2.1.3",
|
||||||
|
"@gitzone/tstest": "^1.0.18",
|
||||||
|
"@pushrocks/smartgulp": "^2.0.1",
|
||||||
|
"@pushrocks/tapbundle": "^3.0.7",
|
||||||
"gulp": "^3.9.1",
|
"gulp": "^3.9.1",
|
||||||
"smartgulp": "^1.0.1",
|
"tslint": "^5.11.0",
|
||||||
"tapbundle": "^1.0.10"
|
"tslint-config-prettier": "^1.17.0"
|
||||||
}
|
},
|
||||||
|
"private": true
|
||||||
}
|
}
|
50
test/test.ts
50
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"
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user