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:
|
||||
paths:
|
||||
- .yarn/
|
||||
- .npmci_cache/
|
||||
key: "$CI_BUILD_STAGE"
|
||||
|
||||
stages:
|
||||
- mirror
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- trigger
|
||||
- pages
|
||||
- metadata
|
||||
|
||||
# ====================
|
||||
# security stage
|
||||
# ====================
|
||||
mirror:
|
||||
stage: mirror
|
||||
stage: security
|
||||
script:
|
||||
- npmci git mirror
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
security:
|
||||
snyk:
|
||||
stage: security
|
||||
script:
|
||||
- npmci command yarn global add snyk
|
||||
- npmci command yarn install --ignore-scripts
|
||||
- npmci npm prepare
|
||||
- npmci command npm install -g snyk
|
||||
- npmci command npm install --ignore-scripts
|
||||
- npmci command snyk test
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
testLEGACY:
|
||||
stage: test
|
||||
script:
|
||||
- npmci node install legacy
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
allow_failure: true
|
||||
# ====================
|
||||
# test stage
|
||||
# ====================
|
||||
|
||||
testLTS:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install lts
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
testSTABLE:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
release:
|
||||
stage: release
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm publish
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
# ====================
|
||||
# metadata stage
|
||||
# ====================
|
||||
codequality:
|
||||
stage: metadata
|
||||
image: docker:stable
|
||||
allow_failure: true
|
||||
services:
|
||||
- docker:stable-dind
|
||||
script:
|
||||
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
||||
- docker run
|
||||
--env SOURCE_CODE="$PWD"
|
||||
--volume "$PWD":/code
|
||||
--volume /var/run/docker.sock:/var/run/docker.sock
|
||||
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
|
||||
artifacts:
|
||||
paths: [codeclimate.json]
|
||||
tags:
|
||||
- docker
|
||||
- priv
|
||||
|
||||
trigger:
|
||||
stage: trigger
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci trigger
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
pages:
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
stage: pages
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci command yarn global add npmpage
|
||||
- npmci command npmpage
|
||||
- npmci command npm install -g typedoc typescript
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
only:
|
||||
- tags
|
||||
artifacts:
|
||||
expire_in: 1 week
|
||||
paths:
|
||||
- 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)
|
||||
[![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)
|
||||
[![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/)
|
||||
[![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/)
|
||||
@ -25,34 +23,34 @@ accepts a function call as parameter to execute in gulp pipeline
|
||||
|
||||
```typescript
|
||||
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'
|
||||
|
||||
let myAsyncFunction = async (file, enc) => {
|
||||
// await some async stuff
|
||||
};
|
||||
|
||||
gulp.task("gulpTest", function() {
|
||||
gulp.task('gulpTest', function() {
|
||||
let stream = gulp
|
||||
.src("./mydir/*.something")
|
||||
.pipe(gulpFunction(myAsyncFunction, "forEach")) //read the notes below
|
||||
.src('./mydir/*.something')
|
||||
.pipe(gulpFunction(myAsyncFunction, 'forEach')) //read the notes below
|
||||
// .pipe(forEach(myAsyncFunction)) // if imported as >> import { forEach } from 'gulp-function' <<
|
||||
.pipe(gulp.dest("./build/"));
|
||||
.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**.
|
||||
- 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.
|
||||
- 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.
|
||||
- "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.
|
||||
|
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 =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xDQUFDO0FBQ3pDLENBQUMsQ0FBQztBQUVGLGtCQUFlLGFBQWEsQ0FBQyJ9
|
4015
package-lock.json
generated
Normal file
4015
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
20
package.json
20
package.json
@ -5,7 +5,8 @@
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"scripts": {
|
||||
"test": "(npmts)"
|
||||
"test": "(tstest test/)",
|
||||
"build": "(tsbuild)"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -24,13 +25,18 @@
|
||||
},
|
||||
"homepage": "https://gitlab.com/pushrocks/gulp-function",
|
||||
"dependencies": {
|
||||
"@pushrocks/smartpromise": "^2.0.5",
|
||||
"@types/through2": "^2.0.32",
|
||||
"smartq": "^1.1.6",
|
||||
"through2": "^2.0.3"
|
||||
"through2": "^3.0.0"
|
||||
},
|
||||
"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",
|
||||
"smartgulp": "^1.0.1",
|
||||
"tapbundle": "^1.0.10"
|
||||
}
|
||||
}
|
||||
"tslint": "^5.11.0",
|
||||
"tslint-config-prettier": "^1.17.0"
|
||||
},
|
||||
"private": true
|
||||
}
|
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'
|
||||
let gulp = require('gulp')
|
||||
import * as gulpFunction from '../ts/index'
|
||||
import * as smartgulp from '@pushrocks/smartgulp';
|
||||
let gulp = require('gulp');
|
||||
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) => {
|
||||
let done = smartq.defer()
|
||||
let counter = 0
|
||||
gulp.src('./test/testfiles/*.md')
|
||||
.pipe(gulpFunction.forEach(async () => {
|
||||
counter++
|
||||
tap.test('should run through smoothly with ' + "'forEach'", async tools => {
|
||||
let done = smartpromise.defer();
|
||||
let counter = 0;
|
||||
gulp.src('./test/testfiles/*.md').pipe(
|
||||
gulpFunction.forEach(async () => {
|
||||
counter++;
|
||||
if (counter === 2) {
|
||||
done.resolve()
|
||||
done.resolve();
|
||||
}
|
||||
}))
|
||||
await done.promise
|
||||
})
|
||||
})
|
||||
);
|
||||
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.test('should run through smoothly with ' + "'forEach'", async tools => {
|
||||
let done = smartpromise.defer();
|
||||
let counter = 0;
|
||||
smartgulp.src(['./test/testfiles/*.md']).pipe(
|
||||
gulpFunction.atEnd(async () => {
|
||||
console.log('atEnd');
|
||||
done.resolve();
|
||||
})
|
||||
);
|
||||
await done.promise;
|
||||
});
|
||||
|
||||
tap.start()
|
||||
tap.start();
|
||||
|
35
ts/index.ts
35
ts/index.ts
@ -1,8 +1,8 @@
|
||||
import * as q from "smartq";
|
||||
import * as through2 from "through2";
|
||||
import { Transform } from "stream";
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
import * as through2 from 'through2';
|
||||
import { Transform } from 'stream';
|
||||
|
||||
export type TExecutionMode = "forEach" | "forFirst" | "atEnd";
|
||||
export type TExecutionMode = 'forEach' | 'forFirst' | 'atEnd';
|
||||
|
||||
export interface IPromiseFunction {
|
||||
(file?, enc?): PromiseLike<any>;
|
||||
@ -10,30 +10,25 @@ export interface IPromiseFunction {
|
||||
|
||||
let defaultExport = (
|
||||
functionsToExecuteArg: IPromiseFunction | IPromiseFunction[],
|
||||
executionModeArg: TExecutionMode = "forEach"
|
||||
executionModeArg: TExecutionMode = 'forEach'
|
||||
): Transform => {
|
||||
let promiseArray = [];
|
||||
let runFunction = function(functionArg, file, enc) {
|
||||
let returnValue = functionArg(file, enc);
|
||||
if (
|
||||
typeof returnValue !== "undefined" &&
|
||||
typeof returnValue.then !== "undefined"
|
||||
) {
|
||||
if (typeof returnValue !== 'undefined' && typeof returnValue.then !== 'undefined') {
|
||||
promiseArray.push(returnValue);
|
||||
}
|
||||
};
|
||||
|
||||
let checkAndRunFunction = function(file, enc) {
|
||||
if (typeof functionsToExecuteArg === "function") {
|
||||
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"
|
||||
);
|
||||
throw new Error('gulp-callfunction: something is strange with the given arguments');
|
||||
}
|
||||
return Promise.all(promiseArray);
|
||||
};
|
||||
@ -42,12 +37,12 @@ let defaultExport = (
|
||||
let forEach = function(file, enc, cb) {
|
||||
// the forEach function is called for every chunk
|
||||
switch (executionModeArg) {
|
||||
case "forEach":
|
||||
case 'forEach':
|
||||
checkAndRunFunction(file, enc).then(function() {
|
||||
cb(null, file);
|
||||
});
|
||||
break;
|
||||
case "forFirst":
|
||||
case 'forFirst':
|
||||
if (hasExecutedOnce) {
|
||||
checkAndRunFunction(file, enc).then(function() {
|
||||
cb(null, file);
|
||||
@ -57,7 +52,7 @@ let defaultExport = (
|
||||
}
|
||||
hasExecutedOnce = true;
|
||||
break;
|
||||
case "atEnd":
|
||||
case 'atEnd':
|
||||
cb();
|
||||
break;
|
||||
default:
|
||||
@ -66,7 +61,7 @@ let defaultExport = (
|
||||
};
|
||||
|
||||
let atEnd = function(cb) {
|
||||
if (executionModeArg === "atEnd") {
|
||||
if (executionModeArg === 'atEnd') {
|
||||
checkAndRunFunction(null, null).then(function() {
|
||||
cb();
|
||||
});
|
||||
@ -78,15 +73,15 @@ let defaultExport = (
|
||||
};
|
||||
|
||||
export let forEach = (funcArg: IPromiseFunction) => {
|
||||
return defaultExport(funcArg, "forEach");
|
||||
return defaultExport(funcArg, 'forEach');
|
||||
};
|
||||
|
||||
export let forFirst = (funcArg: IPromiseFunction) => {
|
||||
return defaultExport(funcArg, "forFirst");
|
||||
return defaultExport(funcArg, 'forFirst');
|
||||
};
|
||||
|
||||
export let atEnd = (funcArg: IPromiseFunction) => {
|
||||
return defaultExport(funcArg, "atEnd");
|
||||
return defaultExport(funcArg, 'atEnd');
|
||||
};
|
||||
|
||||
export default defaultExport;
|
||||
|
16
tslint.json
16
tslint.json
@ -1,3 +1,17 @@
|
||||
{
|
||||
"extends": "tslint-config-standard"
|
||||
"extends": ["tslint:latest", "tslint-config-prettier"],
|
||||
"rules": {
|
||||
"semicolon": [true, "always"],
|
||||
"no-console": false,
|
||||
"ordered-imports": false,
|
||||
"object-literal-sort-keys": false,
|
||||
"member-ordering": {
|
||||
"options":{
|
||||
"order": [
|
||||
"static-method"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"defaultSeverity": "warning"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user