Compare commits
No commits in common. "master" and "v2.0.2" have entirely different histories.
@ -1,66 +0,0 @@
|
|||||||
name: Default (not tags)
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
tags-ignore:
|
|
||||||
- '**'
|
|
||||||
|
|
||||||
env:
|
|
||||||
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
|
||||||
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
|
|
||||||
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
|
||||||
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
|
||||||
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
|
||||||
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
security:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
continue-on-error: true
|
|
||||||
container:
|
|
||||||
image: ${{ env.IMAGE }}
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Install pnpm and npmci
|
|
||||||
run: |
|
|
||||||
pnpm install -g pnpm
|
|
||||||
pnpm install -g @shipzone/npmci
|
|
||||||
|
|
||||||
- name: Run npm prepare
|
|
||||||
run: npmci npm prepare
|
|
||||||
|
|
||||||
- name: Audit production dependencies
|
|
||||||
run: |
|
|
||||||
npmci command npm config set registry https://registry.npmjs.org
|
|
||||||
npmci command pnpm audit --audit-level=high --prod
|
|
||||||
continue-on-error: true
|
|
||||||
|
|
||||||
- name: Audit development dependencies
|
|
||||||
run: |
|
|
||||||
npmci command npm config set registry https://registry.npmjs.org
|
|
||||||
npmci command pnpm audit --audit-level=high --dev
|
|
||||||
continue-on-error: true
|
|
||||||
|
|
||||||
test:
|
|
||||||
if: ${{ always() }}
|
|
||||||
needs: security
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
container:
|
|
||||||
image: ${{ env.IMAGE }}
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Test stable
|
|
||||||
run: |
|
|
||||||
npmci node install stable
|
|
||||||
npmci npm install
|
|
||||||
npmci npm test
|
|
||||||
|
|
||||||
- name: Test build
|
|
||||||
run: |
|
|
||||||
npmci node install stable
|
|
||||||
npmci npm install
|
|
||||||
npmci npm build
|
|
@ -1,124 +0,0 @@
|
|||||||
name: Default (tags)
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
tags:
|
|
||||||
- '*'
|
|
||||||
|
|
||||||
env:
|
|
||||||
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
|
||||||
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
|
|
||||||
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
|
||||||
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
|
||||||
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
|
||||||
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
security:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
continue-on-error: true
|
|
||||||
container:
|
|
||||||
image: ${{ env.IMAGE }}
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Prepare
|
|
||||||
run: |
|
|
||||||
pnpm install -g pnpm
|
|
||||||
pnpm install -g @shipzone/npmci
|
|
||||||
npmci npm prepare
|
|
||||||
|
|
||||||
- name: Audit production dependencies
|
|
||||||
run: |
|
|
||||||
npmci command npm config set registry https://registry.npmjs.org
|
|
||||||
npmci command pnpm audit --audit-level=high --prod
|
|
||||||
continue-on-error: true
|
|
||||||
|
|
||||||
- name: Audit development dependencies
|
|
||||||
run: |
|
|
||||||
npmci command npm config set registry https://registry.npmjs.org
|
|
||||||
npmci command pnpm audit --audit-level=high --dev
|
|
||||||
continue-on-error: true
|
|
||||||
|
|
||||||
test:
|
|
||||||
if: ${{ always() }}
|
|
||||||
needs: security
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
container:
|
|
||||||
image: ${{ env.IMAGE }}
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Prepare
|
|
||||||
run: |
|
|
||||||
pnpm install -g pnpm
|
|
||||||
pnpm install -g @shipzone/npmci
|
|
||||||
npmci npm prepare
|
|
||||||
|
|
||||||
- name: Test stable
|
|
||||||
run: |
|
|
||||||
npmci node install stable
|
|
||||||
npmci npm install
|
|
||||||
npmci npm test
|
|
||||||
|
|
||||||
- name: Test build
|
|
||||||
run: |
|
|
||||||
npmci node install stable
|
|
||||||
npmci npm install
|
|
||||||
npmci npm build
|
|
||||||
|
|
||||||
release:
|
|
||||||
needs: test
|
|
||||||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
container:
|
|
||||||
image: ${{ env.IMAGE }}
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Prepare
|
|
||||||
run: |
|
|
||||||
pnpm install -g pnpm
|
|
||||||
pnpm install -g @shipzone/npmci
|
|
||||||
npmci npm prepare
|
|
||||||
|
|
||||||
- name: Release
|
|
||||||
run: |
|
|
||||||
npmci node install stable
|
|
||||||
npmci npm publish
|
|
||||||
|
|
||||||
metadata:
|
|
||||||
needs: test
|
|
||||||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
container:
|
|
||||||
image: ${{ env.IMAGE }}
|
|
||||||
continue-on-error: true
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Prepare
|
|
||||||
run: |
|
|
||||||
pnpm install -g pnpm
|
|
||||||
pnpm install -g @shipzone/npmci
|
|
||||||
npmci npm prepare
|
|
||||||
|
|
||||||
- name: Code quality
|
|
||||||
run: |
|
|
||||||
npmci command npm install -g typescript
|
|
||||||
npmci npm install
|
|
||||||
|
|
||||||
- name: Trigger
|
|
||||||
run: npmci trigger
|
|
||||||
|
|
||||||
- name: Build docs and upload artifacts
|
|
||||||
run: |
|
|
||||||
npmci node install stable
|
|
||||||
npmci npm install
|
|
||||||
pnpm install -g @git.zone/tsdoc
|
|
||||||
npmci command tsdoc
|
|
||||||
continue-on-error: true
|
|
23
.gitignore
vendored
23
.gitignore
vendored
@ -1,20 +1,13 @@
|
|||||||
.nogit/
|
node_modules/
|
||||||
|
.settings/
|
||||||
# artifacts
|
.idea/
|
||||||
coverage/
|
coverage/
|
||||||
|
docs/
|
||||||
public/
|
public/
|
||||||
pages/
|
pages/
|
||||||
|
|
||||||
# installs
|
ts/*.js
|
||||||
node_modules/
|
ts/*.js.map
|
||||||
|
ts/typings/
|
||||||
|
test/result/
|
||||||
|
|
||||||
# caches
|
|
||||||
.yarn/
|
|
||||||
.cache/
|
|
||||||
.rpt2_cache
|
|
||||||
|
|
||||||
# builds
|
|
||||||
dist/
|
|
||||||
dist_*/
|
|
||||||
|
|
||||||
# custom
|
|
53
.gitlab-ci.yml
Normal file
53
.gitlab-ci.yml
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
image: hosttoday/ht-docker-node:npmts
|
||||||
|
stages:
|
||||||
|
- test
|
||||||
|
- release
|
||||||
|
- trigger
|
||||||
|
- pages
|
||||||
|
testLEGACY:
|
||||||
|
stage: test
|
||||||
|
script:
|
||||||
|
- npmci test legacy
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
allow_failure: true
|
||||||
|
testLTS:
|
||||||
|
stage: test
|
||||||
|
script:
|
||||||
|
- npmci test lts
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
|
||||||
|
testSTABLE:
|
||||||
|
stage: test
|
||||||
|
script:
|
||||||
|
- npmci test stable
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
release:
|
||||||
|
stage: release
|
||||||
|
script:
|
||||||
|
- npmci publish
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
trigger:
|
||||||
|
stage: trigger
|
||||||
|
script:
|
||||||
|
- npmci trigger
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
pages:
|
||||||
|
image: hosttoday/ht-docker-node:npmpage
|
||||||
|
stage: pages
|
||||||
|
script:
|
||||||
|
- npmci command npmpage --host gitlab
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
|
artifacts:
|
||||||
|
expire_in: 1 week
|
||||||
|
paths:
|
||||||
|
- public
|
11
.vscode/launch.json
vendored
11
.vscode/launch.json
vendored
@ -1,11 +0,0 @@
|
|||||||
{
|
|
||||||
"version": "0.2.0",
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"command": "npm test",
|
|
||||||
"name": "Run npm test",
|
|
||||||
"request": "launch",
|
|
||||||
"type": "node-terminal"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
26
.vscode/settings.json
vendored
26
.vscode/settings.json
vendored
@ -1,26 +0,0 @@
|
|||||||
{
|
|
||||||
"json.schemas": [
|
|
||||||
{
|
|
||||||
"fileMatch": ["/npmextra.json"],
|
|
||||||
"schema": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"npmci": {
|
|
||||||
"type": "object",
|
|
||||||
"description": "settings for npmci"
|
|
||||||
},
|
|
||||||
"gitzone": {
|
|
||||||
"type": "object",
|
|
||||||
"description": "settings for gitzone",
|
|
||||||
"properties": {
|
|
||||||
"projectType": {
|
|
||||||
"type": "string",
|
|
||||||
"enum": ["website", "element", "service", "npm", "wcc"]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
@ -1,6 +1,6 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2015 Lossless GmbH
|
Copyright (c) 2015 Push.Rocks
|
||||||
|
|
||||||
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
|
||||||
|
59
README.md
Normal file
59
README.md
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
# gulp-function
|
||||||
|
accepts call 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://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
|
||||||
|
```javascript
|
||||||
|
let gulp = require("gulp");
|
||||||
|
let gulpFunction = require("gulp-function");
|
||||||
|
let Q = require("q");
|
||||||
|
|
||||||
|
let myFunction = function (file, enc) { // file and enc are optional in case you want to modify the file object
|
||||||
|
let done = Q.defer();
|
||||||
|
console.log("Hello World!")
|
||||||
|
|
||||||
|
// NOTE:
|
||||||
|
// you can use done.resolve as callback function
|
||||||
|
// of any async tasks within this function
|
||||||
|
done.resolve();
|
||||||
|
|
||||||
|
return done.promise;
|
||||||
|
}
|
||||||
|
|
||||||
|
gulp.task('gulpTest',function() {
|
||||||
|
let stream = gulp.src('./mydir/*.something')
|
||||||
|
.pipe(gulpFunction(myFunction,'forEach')) //read the notes below
|
||||||
|
.pipe(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**!!!
|
||||||
|
|
||||||
|
[](https://push.rocks)
|
5
dist/index.d.ts
vendored
Normal file
5
dist/index.d.ts
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import 'typings-global';
|
||||||
|
export declare type TExecutionMode = 'forEach' | 'forFirst' | 'atEnd';
|
||||||
|
export interface IPromiseFunction {
|
||||||
|
(file?: any, enc?: any): PromiseLike<any>;
|
||||||
|
}
|
66
dist/index.js
vendored
Normal file
66
dist/index.js
vendored
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
"use strict";
|
||||||
|
require("typings-global");
|
||||||
|
const q = require("q");
|
||||||
|
const through2 = require("through2");
|
||||||
|
module.exports = (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 q.all(promiseArray);
|
||||||
|
};
|
||||||
|
let hasExecutedOnce = false;
|
||||||
|
let forEach = function (file, enc, cb) {
|
||||||
|
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(null, file);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let atEnd = function (cb) {
|
||||||
|
if (executionModeArg === 'atEnd') {
|
||||||
|
checkAndRunFunction(null, null).then(function () {
|
||||||
|
cb();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
cb();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return through2.obj(forEach, atEnd);
|
||||||
|
};
|
||||||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBQ3ZCLHVCQUFzQjtBQUN0QixxQ0FBb0M7QUFTcEMsTUFBTSxDQUFDLE9BQU8sR0FBRyxDQUNiLHFCQUE0RCxFQUM1RCxnQkFBZ0IsR0FBbUIsU0FBUztJQUc1QyxJQUFJLFlBQVksR0FBRyxFQUFFLENBQUE7SUFDckIsSUFBSSxXQUFXLEdBQUcsVUFBVSxXQUFXLEVBQUUsSUFBSSxFQUFFLEdBQUc7UUFDOUMsSUFBSSxXQUFXLEdBQUcsV0FBVyxDQUFDLElBQUksRUFBRSxHQUFHLENBQUMsQ0FBQTtRQUN4QyxFQUFFLENBQUMsQ0FBQyxPQUFPLFdBQVcsS0FBSyxXQUFXLElBQUksT0FBTyxXQUFXLENBQUMsSUFBSSxLQUFLLFdBQVcsQ0FBQyxDQUFDLENBQUM7WUFDaEYsWUFBWSxDQUFDLElBQUksQ0FBQyxXQUFXLENBQUMsQ0FBQTtRQUNsQyxDQUFDO0lBQ0wsQ0FBQyxDQUFBO0lBRUQsSUFBSSxtQkFBbUIsR0FBRyxVQUFVLElBQUksRUFBRSxHQUFHO1FBQ3pDLEVBQUUsQ0FBQyxDQUFDLE9BQU8scUJBQXFCLEtBQUssVUFBVSxDQUFDLENBQUMsQ0FBQztZQUM5QyxXQUFXLENBQUMscUJBQXFCLEVBQUUsSUFBSSxFQUFFLEdBQUcsQ0FBQyxDQUFBO1FBQ2pELENBQUM7UUFBQyxJQUFJLENB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FBO29CQUNsQixDQUFDLENBQUMsQ0FBQTtnQkFDVixDQUFDO2dCQUFDLElBQUksQ0FBQyxDQUFDO29CQUNKLEVBQUUsQ0FBQyxJQUFJLEVBQUUsSUFBSSxDQUFDLENBQUE7Z0JBQ2xCLENBQUM7Z0JBQ0QsZUFBZSxHQUFHLElBQUksQ0FBQTtnQkFDdEIsS0FBSyxDQUFBO1lBQ1QsS0FBSyxPQUFPO2dCQUNSLEVBQUUsQ0FBQyxJQUFJLEVBQUUsSUFBSSxDQUFDLENBQUE7Z0JBQ2QsS0FBSyxDQUFBO1lBQ1Q7Z0JBQ0ksS0FBSyxDQUFBO1FBQ2IsQ0FBQztJQUNMLENBQUMsQ0FBQTtJQUVELElBQUksS0FBSyxHQUFHLFVBQVUsRUFBRTtRQUNwQixFQUFFLENBQUMsQ0FBQyxnQkFBZ0IsS0FBSyxPQUFPLENBQUMsQ0FBQyxDQUFDO1lBQy9CLG1CQUFtQixDQUFDLElBQUksRUFBRSxJQUFJLENBQUMsQ0FBQyxJQUFJLENBQUM7Z0JBQ2pDLEVBQUUsRUFBRSxDQUFBO1lBQ1IsQ0FBQyxDQUFDLENBQUE7UUFDTixDQUFDO1FBQUMsSUFBSSxDQUFDLENBQUM7WUFDSixFQUFFLEVBQUUsQ0FBQTtRQUNSLENBQUM7SUFDTCxDQUFDLENBQUE7SUFDRCxNQUFNLENBQUMsUUFBUSxDQUFDLEdBQUcsQ0FBQyxPQUFPLEVBQUUsS0FBSyxDQUFDLENBQUE7QUFDdkMsQ0FBQyxDQUFBIn0=
|
@ -1,34 +1,5 @@
|
|||||||
{
|
{
|
||||||
"npmts": {
|
"npmts": {
|
||||||
"mode": "default"
|
"mode": "default"
|
||||||
},
|
|
||||||
"npmci": {
|
|
||||||
"npmGlobalTools": [],
|
|
||||||
"npmAccessLevel": "public"
|
|
||||||
},
|
|
||||||
"gitzone": {
|
|
||||||
"projectType": "npm",
|
|
||||||
"module": {
|
|
||||||
"githost": "code.foss.global",
|
|
||||||
"gitscope": "push.rocks",
|
|
||||||
"gitrepo": "gulp-function",
|
|
||||||
"description": "A Gulp plugin to execute functions within a Gulp task pipeline.",
|
|
||||||
"npmPackagename": "@push.rocks/gulp-function",
|
|
||||||
"license": "MIT",
|
|
||||||
"keywords": [
|
|
||||||
"gulp",
|
|
||||||
"plugin",
|
|
||||||
"task automation",
|
|
||||||
"stream manipulation",
|
|
||||||
"async function execution",
|
|
||||||
"pipeline",
|
|
||||||
"build tool",
|
|
||||||
"JavaScript",
|
|
||||||
"TypeScript"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"tsdoc": {
|
|
||||||
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
72
package.json
72
package.json
@ -1,63 +1,41 @@
|
|||||||
{
|
{
|
||||||
"name": "@push.rocks/gulp-function",
|
"name": "gulp-function",
|
||||||
"private": false,
|
"version": "2.0.2",
|
||||||
"version": "3.0.7",
|
"description": "accepts a function call as parameter to execute in gulp pipeline",
|
||||||
"description": "A Gulp plugin to execute functions within a Gulp task pipeline.",
|
"main": "dist/index.js",
|
||||||
"main": "dist_ts/index.js",
|
"typings": "dist/index.d.ts",
|
||||||
"typings": "dist_ts/index.d.ts",
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/)",
|
"test": "(npmts)",
|
||||||
"build": "(tsbuild --allowimplicitany)",
|
"reinstall": "(rm -r node_modules && npm install)",
|
||||||
"buildDocs": "tsdoc"
|
"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://code.foss.global/push.rocks/gulp-function.git"
|
"url": "https://gitlab.com/pushrocks/gulp-function.git"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
|
"gulpplugin",
|
||||||
"gulp",
|
"gulp",
|
||||||
"plugin",
|
"function"
|
||||||
"task automation",
|
|
||||||
"stream manipulation",
|
|
||||||
"async function execution",
|
|
||||||
"pipeline",
|
|
||||||
"build tool",
|
|
||||||
"JavaScript",
|
|
||||||
"TypeScript"
|
|
||||||
],
|
],
|
||||||
"author": "Lossless GmbH <office@lossless.com> (https://lossless.com)",
|
"author": "Lossless GmbH <office@lossless.com> (https://lossless.com)",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://gitlab.com/push.rocks/gulp-function/issues"
|
"url": "https://gitlab.com/pushrocks/gulp-function/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://code.foss.global/push.rocks/gulp-function",
|
"homepage": "https://gitlab.com/pushrocks/gulp-function",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@push.rocks/smartpromise": "^4.0.3",
|
"@types/q": "0.0.32",
|
||||||
"@types/through2": "^2.0.32",
|
"@types/through2": "^2.0.31",
|
||||||
"through2": "^3.0.1"
|
"q": "^1.4.1",
|
||||||
|
"through2": "^2.0.1",
|
||||||
|
"typings-global": "^1.0.14"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@git.zone/tsbuild": "^2.1.17",
|
"beautylog": "^6.0.0",
|
||||||
"@git.zone/tsrun": "^1.2.46",
|
"gulp": "^3.9.1",
|
||||||
"@git.zone/tstest": "^1.0.28",
|
"npmts-g": "^5.2.8",
|
||||||
"@push.rocks/smartgulp": "^3.0.3",
|
"typings-test": "^1.0.3"
|
||||||
"@push.rocks/tapbundle": "^5.0.15",
|
}
|
||||||
"gulp": "^4.0.2"
|
}
|
||||||
},
|
|
||||||
"files": [
|
|
||||||
"ts/**/*",
|
|
||||||
"ts_web/**/*",
|
|
||||||
"dist/**/*",
|
|
||||||
"dist_*/**/*",
|
|
||||||
"dist_ts/**/*",
|
|
||||||
"dist_ts_web/**/*",
|
|
||||||
"assets/**/*",
|
|
||||||
"cli.js",
|
|
||||||
"npmextra.json",
|
|
||||||
"readme.md"
|
|
||||||
],
|
|
||||||
"type": "module",
|
|
||||||
"browserslist": [
|
|
||||||
"last 1 chrome versions"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
7617
pnpm-lock.yaml
generated
7617
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -1 +0,0 @@
|
|||||||
|
|
106
readme.md
106
readme.md
@ -1,106 +0,0 @@
|
|||||||
# @push.rocks/gulp-function
|
|
||||||
|
|
||||||
[@push.rocks/gulp-function](https://www.npmjs.com/package/@push.rocks/gulp-function) is a Gulp plugin designed to execute custom functions within a Gulp pipeline. It accepts a function call as a parameter and allows for flexible task executions, including asynchronous tasks, with easy integration into the Gulp workflow.
|
|
||||||
|
|
||||||
## Install
|
|
||||||
|
|
||||||
To use @push.rocks/gulp-function in your project, you'll first need to install it via npm. You can do this by running the following command in your project's root directory:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
npm install @push.rocks/gulp-function --save-dev
|
|
||||||
```
|
|
||||||
|
|
||||||
This command will add `@push.rocks/gulp-function` as a development dependency to your project, making it available for use in your Gulp tasks.
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
The primary use case for `@push.rocks/gulp-function` is to incorporate custom function executions into your Gulp pipelines. This can be particularly useful for tasks that require conditional processing, external API calls, or any other logic that extends beyond the capabilities of existing Gulp plugins.
|
|
||||||
|
|
||||||
Here's how you can use `@push.rocks/gulp-function` within your Gulp setup:
|
|
||||||
|
|
||||||
### Basic Example
|
|
||||||
|
|
||||||
Let's start with a simple scenario where you want to log the path of files processed by Gulp.
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
import gulp from 'gulp';
|
|
||||||
import gulpFunction, { forEach } from '@push.rocks/gulp-function';
|
|
||||||
|
|
||||||
const logFilePath = async (file: Buffer, enc: string) => {
|
|
||||||
console.log(`Processing file: ${file.path}`);
|
|
||||||
};
|
|
||||||
|
|
||||||
gulp.task('log', () => {
|
|
||||||
return gulp.src('./src/**/*.ts')
|
|
||||||
.pipe(forEach(logFilePath))
|
|
||||||
.pipe(gulp.dest('./dist'));
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
In this example, we're using the `forEach` method exported by `@push.rocks/gulp-function` to execute `logFilePath` for each file matched by `gulp.src`. The file's path is logged to the console during the build process.
|
|
||||||
|
|
||||||
### Advanced Use Case: Asynchronous Function Execution
|
|
||||||
|
|
||||||
`@push.rocks/gulp-function` truly shines when you need to perform asynchronous operations within your Gulp tasks. Here's an example that demonstrates making an asynchronous API call for each file:
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
import gulp from 'gulp';
|
|
||||||
import gulpFunction, { forEach } from '@push.rocks/gulp-function';
|
|
||||||
import axios from 'axios';
|
|
||||||
|
|
||||||
const uploadFileToServer = async (file: Buffer, enc: string) => {
|
|
||||||
const formData = new FormData();
|
|
||||||
formData.append('file', file.contents, file.relative);
|
|
||||||
|
|
||||||
await axios.post('https://example.com/upload', formData, {
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'multipart/form-data'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log(`Uploaded file: ${file.path}`);
|
|
||||||
};
|
|
||||||
|
|
||||||
gulp.task('uploadFiles', () => {
|
|
||||||
return gulp.src('./uploads/**/*')
|
|
||||||
.pipe(forEach(uploadFileToServer))
|
|
||||||
.pipe(gulp.dest('./dist/uploads'));
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
In this more advanced example, we use the `forEach` method to upload each file to a remote server using `axios`. The function `uploadFileToServer` is executed for each file, where an HTTP POST request is made to upload the file. This shows how you can integrate asynchronous operations seamlessly into your Gulp pipeline.
|
|
||||||
|
|
||||||
### Execution Modes
|
|
||||||
|
|
||||||
`@push.rocks/gulp-function` supports three execution modes for your functions: `forEach`, `forFirst`, and `atEnd`.
|
|
||||||
|
|
||||||
- **forEach**: Executes the provided function for each file in the stream.
|
|
||||||
- **forFirst**: Executes the provided function only for the first file that passes through the stream.
|
|
||||||
- **atEnd**: Executes the provided function once after all files have passed through the stream.
|
|
||||||
|
|
||||||
These modes provide flexibility in determining when your custom functions should be triggered during the build process.
|
|
||||||
|
|
||||||
### Conclusion
|
|
||||||
|
|
||||||
`@push.rocks/gulp-function` is a powerful tool for integrating custom processing logic into Gulp workflows. Whether you need to execute simple synchronous tasks or complex asynchronous operations, `@push.rocks/gulp-function` offers the flexibility and ease of use to enhance your Gulp builds significantly.
|
|
||||||
|
|
||||||
Remember, the examples provided are starting points. The real power of `@push.rocks/gulp-function` lies in its ability to adapt to your specific use cases, enabling you to automate and streamline your build processes as never before.
|
|
||||||
|
|
||||||
## License and Legal Information
|
|
||||||
|
|
||||||
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
|
|
||||||
|
|
||||||
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
|
|
||||||
|
|
||||||
### Trademarks
|
|
||||||
|
|
||||||
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
|
|
||||||
|
|
||||||
### Company Information
|
|
||||||
|
|
||||||
Task Venture Capital GmbH
|
|
||||||
Registered at District court Bremen HRB 35230 HB, Germany
|
|
||||||
|
|
||||||
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
|
|
||||||
|
|
||||||
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
|
|
1
test/test.d.ts
vendored
Normal file
1
test/test.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
import "typings-test";
|
102
test/test.js
Normal file
102
test/test.js
Normal file
File diff suppressed because one or more lines are too long
1
test/test.js.map
Normal file
1
test/test.js.map
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"test.js","sourceRoot":"","sources":["test.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,IAAI,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAC3B,IAAI,YAAY,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;AAC/C,IAAI,SAAS,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;AACrC,IAAI,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;AAErB,IAAI,UAAU,GAAG;IACb,IAAI,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,CAAA;IACpB,SAAS,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IACnC,IAAI,CAAC,OAAO,EAAE,CAAC;IACf,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC;AACxB,CAAC,CAAC;AACF,IAAI,WAAW,GAAG;IACd,IAAI,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC;IACr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AC,IAAI,CAAC,iBAAiB,CAAC,CAAC;YAClC,IAAI,EAAE,CAAC;QACX,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
141
test/test.ts
141
test/test.ts
@ -1,35 +1,118 @@
|
|||||||
import { expect, tap } from '@push.rocks/tapbundle';
|
import "typings-test"
|
||||||
|
var gulp = require("gulp");
|
||||||
|
var gulpFunction = require("../dist/index.js");
|
||||||
|
var beautylog = require("beautylog");
|
||||||
|
var Q = require("q");
|
||||||
|
|
||||||
import * as smartgulp from '@push.rocks/smartgulp';
|
var myFunction = function () {
|
||||||
import gulp from 'gulp';
|
var done = Q.defer()
|
||||||
import * as gulpFunction from '../ts/index.js';
|
beautylog.log("Function executed");
|
||||||
|
done.resolve();
|
||||||
|
return done.promise;
|
||||||
|
};
|
||||||
|
var myFunction2 = function () {
|
||||||
|
var done = Q.defer();
|
||||||
|
beautylog.ok("Function2 executed");
|
||||||
|
done.resolve();
|
||||||
|
return done.promise;
|
||||||
|
};
|
||||||
|
var myFunction3 = function () {
|
||||||
|
var done = Q.defer();
|
||||||
|
beautylog.success("Function3 executed");
|
||||||
|
done.resolve();
|
||||||
|
return done.promise;
|
||||||
|
};
|
||||||
|
|
||||||
import * as smartpromise from '@push.rocks/smartpromise';
|
var beforeFunction = function () {
|
||||||
|
var done = Q.defer();
|
||||||
|
beautylog.success("beforeFunction executed");
|
||||||
|
done.resolve();
|
||||||
|
return done.promise;
|
||||||
|
};
|
||||||
|
|
||||||
tap.test('should run through smoothly with ' + "'forEach'", async tools => {
|
var middleFunctionRun = false;
|
||||||
let done = smartpromise.defer();
|
|
||||||
let counter = 0;
|
var middleFunction = function () {
|
||||||
gulp.src('./test/testfiles/*.md').pipe(
|
var done = Q.defer();
|
||||||
gulpFunction.forEach(async () => {
|
beautylog.success("middleFunction executed");
|
||||||
counter++;
|
setTimeout(function(){
|
||||||
if (counter === 2) {
|
beautylog.log("timeout fired");
|
||||||
|
middleFunctionRun = true;
|
||||||
done.resolve();
|
done.resolve();
|
||||||
}
|
}, 500);
|
||||||
})
|
return done.promise;
|
||||||
);
|
};
|
||||||
await done.promise;
|
|
||||||
|
var afterFunction = function () {
|
||||||
|
var done = Q.defer();
|
||||||
|
beautylog.success("afterFunction executed");
|
||||||
|
done.resolve();
|
||||||
|
return done.promise;
|
||||||
|
};
|
||||||
|
|
||||||
|
let timeoutFunction = function(){
|
||||||
|
var done = Q.defer();
|
||||||
|
setTimeout(function(){
|
||||||
|
beautylog.log("largeTimeout fired");
|
||||||
|
done.resolve();
|
||||||
|
},2000);
|
||||||
|
return done.promise;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
describe("gulpFunction",function(){
|
||||||
|
it("should run through smoothly with " + "'forEach'".blue,function(done){
|
||||||
|
gulp.src('./test/*.md')
|
||||||
|
.pipe(gulpFunction(myFunction,'forEach'))
|
||||||
|
.pipe(gulp.dest("./test/result/"));
|
||||||
|
|
||||||
|
gulp.src('./test/*.md')
|
||||||
|
.pipe(gulpFunction([myFunction2,myFunction3],'forEach'))
|
||||||
|
.pipe(gulp.dest("./test/result/"))
|
||||||
|
.pipe(gulpFunction(done,"atEnd"));
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should run through smoothly with " + "'atEnd'".blue,function(done){
|
||||||
|
gulp.src('./test/*.md')
|
||||||
|
.pipe(gulpFunction(myFunction,'atEnd'))
|
||||||
|
.pipe(gulp.dest("./test/result/"));
|
||||||
|
|
||||||
|
gulp.src('./test/*.md')
|
||||||
|
.pipe(gulpFunction([myFunction2,myFunction3],'atEnd'))
|
||||||
|
.pipe(gulp.dest("./test/result/"))
|
||||||
|
.pipe(gulpFunction(done,"atEnd"));
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should run through smoothly once with " + "'atFirst'".blue,function(done){
|
||||||
|
|
||||||
|
gulp.src('./test/*.md')
|
||||||
|
.pipe(gulpFunction([myFunction2,myFunction3],'forFirst'))
|
||||||
|
.pipe(gulp.dest("./test/result/"))
|
||||||
|
.pipe(gulpFunction(done,"atEnd"));
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should run in order",function(done){
|
||||||
|
this.timeout(5000);
|
||||||
|
let stream = gulp.src('./test/*.md')
|
||||||
|
.pipe(gulpFunction([beforeFunction,middleFunction,middleFunction],'atEnd'))
|
||||||
|
.pipe(gulpFunction(function(){
|
||||||
|
beautylog.log("stream progressed");
|
||||||
|
var done2 = Q.defer();
|
||||||
|
done2.resolve();
|
||||||
|
return done2.promise;
|
||||||
|
},"forEach"))
|
||||||
|
.pipe(gulpFunction(function(){
|
||||||
|
beautylog.log("nextStep");
|
||||||
|
}))
|
||||||
|
.pipe(gulpFunction(afterFunction,"atEnd"))
|
||||||
|
.pipe(gulpFunction(timeoutFunction,"atEnd"));
|
||||||
|
|
||||||
|
stream.on("finish",function(){
|
||||||
|
beautylog.info("stream finished");
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should run through smoothly with ' + "'forEach'", async tools => {
|
|
||||||
let done = smartpromise.defer();
|
|
||||||
let counter = 0;
|
|
||||||
smartgulp.src(['./test/testfiles/*.md']).pipe(
|
|
||||||
gulpFunction.atEnd(async () => {
|
|
||||||
console.log('atEnd');
|
|
||||||
done.resolve();
|
|
||||||
})
|
|
||||||
);
|
|
||||||
await done.promise;
|
|
||||||
});
|
|
||||||
|
|
||||||
tap.start();
|
|
||||||
|
2
test/test01.md
Normal file
2
test/test01.md
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
# Test.md
|
||||||
|
This is a test file for the test.js gulp pipeline
|
2
test/test02.md
Normal file
2
test/test02.md
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
# Test.md
|
||||||
|
This is another test file for the test.js gulp pipeline
|
@ -1 +0,0 @@
|
|||||||
# the 1st testfile
|
|
@ -1 +0,0 @@
|
|||||||
# the second testfile
|
|
@ -1 +0,0 @@
|
|||||||
# the third testfile
|
|
@ -1 +0,0 @@
|
|||||||
# the fourth testfile
|
|
@ -1 +0,0 @@
|
|||||||
# the fifth testfile
|
|
@ -1 +0,0 @@
|
|||||||
# the sixth testfile
|
|
@ -1 +0,0 @@
|
|||||||
# the seventh testfile
|
|
@ -1 +0,0 @@
|
|||||||
# the eighth testfile
|
|
@ -1 +0,0 @@
|
|||||||
# the nineth testfile
|
|
@ -1 +0,0 @@
|
|||||||
# the tenth testfile
|
|
@ -1 +0,0 @@
|
|||||||
# the eleventh testfile
|
|
@ -1 +0,0 @@
|
|||||||
# the twelveth testfile
|
|
@ -1 +0,0 @@
|
|||||||
# the second testfile
|
|
@ -1 +0,0 @@
|
|||||||
# the second testfile
|
|
@ -1 +0,0 @@
|
|||||||
# the second testfile
|
|
@ -1 +0,0 @@
|
|||||||
# the second testfile
|
|
@ -1 +0,0 @@
|
|||||||
# the second testfile
|
|
@ -1 +0,0 @@
|
|||||||
# the 18th testfile
|
|
@ -1,8 +0,0 @@
|
|||||||
/**
|
|
||||||
* autocreated commitinfo by @pushrocks/commitinfo
|
|
||||||
*/
|
|
||||||
export const commitinfo = {
|
|
||||||
name: '@push.rocks/gulp-function',
|
|
||||||
version: '3.0.7',
|
|
||||||
description: 'accepts a function call as parameter to execute in gulp pipeline'
|
|
||||||
}
|
|
136
ts/index.ts
136
ts/index.ts
@ -1,87 +1,75 @@
|
|||||||
import * as smartpromise from '@push.rocks/smartpromise';
|
import 'typings-global'
|
||||||
import * as through2 from 'through2';
|
import * as q from 'q'
|
||||||
import { Transform } from 'stream';
|
import * as through2 from 'through2'
|
||||||
|
import { Transform } from 'stream'
|
||||||
|
|
||||||
export type TExecutionMode = 'forEach' | 'forFirst' | 'atEnd';
|
export type TExecutionMode = 'forEach' | 'forFirst' | 'atEnd'
|
||||||
|
|
||||||
export interface IPromiseFunction {
|
export interface IPromiseFunction {
|
||||||
(file?, enc?): PromiseLike<any>;
|
(file?, enc?): PromiseLike<any>
|
||||||
}
|
}
|
||||||
|
|
||||||
let defaultExport = (
|
module.exports = (
|
||||||
functionsToExecuteArg: IPromiseFunction | IPromiseFunction[],
|
functionsToExecuteArg: IPromiseFunction | IPromiseFunction[],
|
||||||
executionModeArg: TExecutionMode = 'forEach'
|
executionModeArg: TExecutionMode = 'forEach'
|
||||||
): Transform => {
|
): Transform => {
|
||||||
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) {
|
let promiseArray = []
|
||||||
if (typeof functionsToExecuteArg === 'function') {
|
let runFunction = function (functionArg, file, enc) {
|
||||||
runFunction(functionsToExecuteArg, file, enc);
|
let returnValue = functionArg(file, enc)
|
||||||
} else if (Array.isArray(functionsToExecuteArg)) {
|
if (typeof returnValue !== 'undefined' && typeof returnValue.then !== 'undefined') {
|
||||||
for (let anyFunction in functionsToExecuteArg) {
|
promiseArray.push(returnValue)
|
||||||
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) {
|
let checkAndRunFunction = function (file, enc) {
|
||||||
if (executionModeArg === 'atEnd') {
|
if (typeof functionsToExecuteArg === 'function') {
|
||||||
checkAndRunFunction(null, null).then(function() {
|
runFunction(functionsToExecuteArg, file, enc)
|
||||||
cb();
|
} else if (Array.isArray(functionsToExecuteArg)) {
|
||||||
});
|
for (let anyFunction in functionsToExecuteArg) {
|
||||||
} else {
|
runFunction(functionsToExecuteArg[anyFunction], file, enc)
|
||||||
cb();
|
}
|
||||||
|
} else {
|
||||||
|
throw new Error('gulp-callfunction: something is strange with the given arguments')
|
||||||
|
}
|
||||||
|
return q.all(promiseArray)
|
||||||
}
|
}
|
||||||
};
|
|
||||||
return through2.obj(forEach, atEnd);
|
|
||||||
};
|
|
||||||
|
|
||||||
export let forEach = (funcArg: IPromiseFunction) => {
|
let hasExecutedOnce = false
|
||||||
return defaultExport(funcArg, 'forEach');
|
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(null, file)
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export let forFirst = (funcArg: IPromiseFunction) => {
|
let atEnd = function (cb) {
|
||||||
return defaultExport(funcArg, 'forFirst');
|
if (executionModeArg === 'atEnd') {
|
||||||
};
|
checkAndRunFunction(null, null).then(function () {
|
||||||
|
cb()
|
||||||
export let atEnd = (funcArg: IPromiseFunction) => {
|
})
|
||||||
return defaultExport(funcArg, 'atEnd');
|
} else {
|
||||||
};
|
cb()
|
||||||
|
}
|
||||||
export default defaultExport;
|
}
|
||||||
|
return through2.obj(forEach, atEnd)
|
||||||
|
}
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"experimentalDecorators": true,
|
|
||||||
"useDefineForClassFields": false,
|
|
||||||
"target": "ES2022",
|
|
||||||
"module": "NodeNext",
|
|
||||||
"moduleResolution": "NodeNext",
|
|
||||||
"esModuleInterop": true,
|
|
||||||
"verbatimModuleSyntax": true
|
|
||||||
},
|
|
||||||
"exclude": [
|
|
||||||
"dist_*/**/*.d.ts"
|
|
||||||
]
|
|
||||||
}
|
|
3
tslint.json
Normal file
3
tslint.json
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"extends": "tslint-config-standard"
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user