Compare commits
No commits in common. "master" and "v0.0.4" 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
|
22
.gitignore
vendored
22
.gitignore
vendored
@ -1,20 +1,6 @@
|
||||
.nogit/
|
||||
|
||||
# artifacts
|
||||
coverage/
|
||||
public/
|
||||
pages/
|
||||
|
||||
# installs
|
||||
node_modules/
|
||||
.settings/
|
||||
.idea/
|
||||
|
||||
# caches
|
||||
.yarn/
|
||||
.cache/
|
||||
.rpt2_cache
|
||||
|
||||
# builds
|
||||
dist/
|
||||
dist_*/
|
||||
|
||||
# custom
|
||||
ts/*.js
|
||||
ts/*.js.map
|
||||
|
@ -1,5 +0,0 @@
|
||||
ts/
|
||||
test/
|
||||
docs/
|
||||
coverage/
|
||||
node_modules/
|
19
.travis.yml
Normal file
19
.travis.yml
Normal file
@ -0,0 +1,19 @@
|
||||
language: node_js
|
||||
before_install:
|
||||
- nvm install stable
|
||||
- node -v
|
||||
- npm -v
|
||||
- npm install -g gulp
|
||||
- npm install gulp
|
||||
- npm install gulp-typescript
|
||||
deploy:
|
||||
provider: npm
|
||||
email: npm@smart-coordination.com
|
||||
api_key:
|
||||
secure: AcM6ooFjEIaWOC84QMxxugV3GtkMEoMI6zxy4oB9u9xihLopVZnm6c8FxIr+Wl2Ykjwj2deOuC7Q7QLtfH8/n4cVj1x7c32DJ21XJsE6uGm2opT7bSMm/NgcIvbkzWdPSyG8OpJEu8l///+YTceLdLV2Tn4lPobZRgu0KIF3Pg0Fo2V/0kSH/gSjlbLBgMBx1QrO2y52VHMdqWs3VwMIv1lEEicUsbnBg1z03I/Ka+JZQPCDYGgHu7y62zgB36mdkNVg8pyvGrrTSWeMVyHc8SSvBoqszVUeXfs4d4tcw0+vPsIJD5hDzAGOtH+3KO2Bgi87UB/Dgd5xw92+zQxhKnKewFiyTvANFXoag5UooPupWKhu5DljZ27CkgLX/N/AF6eTuQR0ffW92Bvz2YWis5JC75+HGFV2tBI7hRinScc00J0vOAqqVpp81PD6BXQDX2y5y77arArJVQTC5irOYL20x3UMBB7fOpTkYV9T2NxzR6OBv4P6MLWPbnmFr+zpjkzBxHeJMOosb+9W6TAbVmouM5SfnFU5bBYh2gF52Yz2FnfpDzclVZW/OI0YcAtIdozbHRcJ1s6pVkPqZIqKcCM+jVhzvt8NTnehSOqjFyIV9rcbsYQplLs8b9ntmcuRLCPatXMGFQM/y9Sjw4is0gHhRMjxQo32bfIiX1CTqVo=
|
||||
on:
|
||||
tags: true
|
||||
repo: pushrocks/gulp-callfunction
|
||||
notifications:
|
||||
slack:
|
||||
secure: Bb8P3fboL52CugSsp0RhOkGCeWVbgjb+QDpnMHdSOa0Nequj8V4kvrzBLZOBOjaSB0/gMvdoB4Slv2bls1dAxXW1IX1DdRb3RLMKj/Owje7eTd4IoUuSs49y6/yEkVK+E1wicdwjlMmvsk8fQE/owDRMRXYoXxhN2ZOVSQvAQ3iBO0eokFvWO7yj/VSxKoITymCXA3LfyzXXUuhvxuQd3BPZCe25xa6GWuHtaa5fbJg17pp8jJX6VZYLSRcSYyJxMU8SLdkrOsQZKj0+/Yfpu7XTmPbqxjNapuE7Zm70mi+aB26IQCnmwkdcEQNJVxQOKoP2+/ZnDfcTLQROwH1PJVzol0hneH6DdOlWt9bvBJcUvFRwaDgIb5xXQV8bGsRe5ayE/4MgCgfvdBTvevu6n12fmPx74prIv4pOPMwlALjjP8XavGL4A6amOuV7fJiSyGAku8aUe1rlUXyfoHJswMyOfkIsvnGDE3eEfq1WUIjn8tW1ZozJyoCTAIh6IHPI3Nsg3LkTRvDHPYq25/xCKWxGb2OaJc3JeqVREqm0auDqj6HoVAi/mW/uyvwX9jEVX8fNoQ69ac5VUMFfn2Mx3sU6aHKgZe/tdrtql6NYtIA+g5/ZDnHE1mnbl6MfrYiKwRbrICH5v/u1xK+4+yh09BUqazi3PzOhyTRfba/gRUg=
|
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)
|
||||
|
||||
Copyright (c) 2015 Lossless GmbH
|
||||
Copyright (c) 2015 Push.Rocks
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
25
README.md
Normal file
25
README.md
Normal file
@ -0,0 +1,25 @@
|
||||
# gulp-callfunction
|
||||
accepts call to execute in gulp pipeline.
|
||||
|
||||
### build status/Dependencies
|
||||
[](https://travis-ci.org/pushrocks/gulp-callfunction)
|
||||
[](https://david-dm.org/pushrocks/gulp-callfunction)
|
||||
|
||||
### Usage
|
||||
```javascript
|
||||
var gulp = require("gulp");
|
||||
var gulpCallFunction = require("gulp-callfunction");
|
||||
|
||||
var myFunction = function () {
|
||||
console.log("Hello World!")
|
||||
}
|
||||
|
||||
gulp.task('gulpTest',function() {
|
||||
gulp.src('./mydir/*.something')
|
||||
.pipe(gulpCallFunction(myFunction,'forEach'))
|
||||
.pipe(gulp.dest("./build/"))
|
||||
});
|
||||
```
|
||||
|
||||
>Note: The first argument of gulpCallFunction can also be an array of multiple functionnames.
|
||||
>Note: the second argument can be empty (defaults to 'forEach') or 'atEnd'
|
47
index.js
Normal file
47
index.js
Normal file
@ -0,0 +1,47 @@
|
||||
/// <reference path="typings/tsd.d.ts" />
|
||||
var through = require("through2");
|
||||
var path = require("path");
|
||||
var beautylog = require("beautylog");
|
||||
//important vars
|
||||
var gulpCallFunction = {
|
||||
executionMode: 'forEach',
|
||||
functionsToExecute: undefined,
|
||||
logBool: false
|
||||
};
|
||||
var runFunctionNames = function () {
|
||||
if (typeof gulpCallFunction.functionsToExecute == "function") {
|
||||
gulpCallFunction.functionsToExecute();
|
||||
}
|
||||
else if (Array.isArray(gulpCallFunction.functionsToExecute)) {
|
||||
for (var anyFunction in gulpCallFunction.functionsToExecute) {
|
||||
anyFunction();
|
||||
}
|
||||
}
|
||||
else {
|
||||
beautylog.error('gulp-callfunction: something is strange with the given arguments');
|
||||
}
|
||||
};
|
||||
var forEach = function (file, enc, cb) {
|
||||
if (gulpCallFunction.logBool)
|
||||
beautylog.log(gulpCallFunction.executionMode);
|
||||
if (gulpCallFunction.executionMode === 'forEach') {
|
||||
if (gulpCallFunction.logBool)
|
||||
beautylog.log('is forEach');
|
||||
runFunctionNames();
|
||||
}
|
||||
//tell gulp that we are complete
|
||||
return cb(null, file);
|
||||
};
|
||||
var atEnd = function () {
|
||||
if (gulpCallFunction.executionMode == "atEnd") {
|
||||
runFunctionNames();
|
||||
}
|
||||
};
|
||||
module.exports = function (functionsToExecute, executionMode, logBool) {
|
||||
if (executionMode === void 0) { executionMode = 'forEach'; }
|
||||
if (logBool === void 0) { logBool = false; }
|
||||
gulpCallFunction.functionsToExecute = functionsToExecute;
|
||||
gulpCallFunction.executionMode = executionMode;
|
||||
gulpCallFunction.logBool = logBool;
|
||||
return through.obj(forEach, atEnd);
|
||||
};
|
@ -1,34 +0,0 @@
|
||||
{
|
||||
"npmts": {
|
||||
"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"
|
||||
}
|
||||
}
|
70
package.json
70
package.json
@ -1,63 +1,35 @@
|
||||
{
|
||||
"name": "@push.rocks/gulp-function",
|
||||
"private": false,
|
||||
"version": "3.0.7",
|
||||
"description": "A Gulp plugin to execute functions within a Gulp task pipeline.",
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"name": "gulp-callfunction",
|
||||
"version": "0.0.4",
|
||||
"description": "accepts a function call as parameter to execute in gulp pipeline",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "(tstest test/)",
|
||||
"build": "(tsbuild --allowimplicitany)",
|
||||
"buildDocs": "tsdoc"
|
||||
"test": "(cd ts/compile && node compile.js) && (node test.js)",
|
||||
"reinstall": "(rm -r node_modules && npm install)",
|
||||
"release": "(git pull origin master && npm version patch && git push origin master && git checkout release && git merge master && git push origin release && git checkout master)",
|
||||
"startdev": "(git checkout master && git pull origin master)"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://code.foss.global/push.rocks/gulp-function.git"
|
||||
"url": "https://github.com/pushrocks/gulp-callfunction.git"
|
||||
},
|
||||
"keywords": [
|
||||
"gulp",
|
||||
"plugin",
|
||||
"task automation",
|
||||
"stream manipulation",
|
||||
"async function execution",
|
||||
"pipeline",
|
||||
"build tool",
|
||||
"JavaScript",
|
||||
"TypeScript"
|
||||
"json",
|
||||
"jade",
|
||||
"template"
|
||||
],
|
||||
"author": "Lossless GmbH <office@lossless.com> (https://lossless.com)",
|
||||
"author": "Smart Coordination GmbH <office@push.rocks> (https://push.rocks)",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://gitlab.com/push.rocks/gulp-function/issues"
|
||||
},
|
||||
"homepage": "https://code.foss.global/push.rocks/gulp-function",
|
||||
"dependencies": {
|
||||
"@push.rocks/smartpromise": "^4.0.3",
|
||||
"@types/through2": "^2.0.32",
|
||||
"through2": "^3.0.1"
|
||||
"url": "https://github.com/pushrocks/gulp-callfunction/issues"
|
||||
},
|
||||
"homepage": "https://github.com/pushrocks/gulp-callfunction",
|
||||
"devDependencies": {
|
||||
"@git.zone/tsbuild": "^2.1.17",
|
||||
"@git.zone/tsrun": "^1.2.46",
|
||||
"@git.zone/tstest": "^1.0.28",
|
||||
"@push.rocks/smartgulp": "^3.0.3",
|
||||
"@push.rocks/tapbundle": "^5.0.15",
|
||||
"gulp": "^4.0.2"
|
||||
"gulp": "^3.9.0",
|
||||
"gulp-typescript": "^2.9.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"
|
||||
]
|
||||
"dependencies": {
|
||||
"beautylog": "0.0.15",
|
||||
"through2": "^2.0.0"
|
||||
}
|
||||
}
|
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.
|
12
test.js
Normal file
12
test.js
Normal file
@ -0,0 +1,12 @@
|
||||
/// <reference path="typings/tsd.d.ts" />
|
||||
var gulp = require("gulp");
|
||||
var gulpCallFunction = require("./index.js");
|
||||
var myFunction = function () {
|
||||
console.log("Hello World!");
|
||||
};
|
||||
gulp.task('default', function () {
|
||||
gulp.src('./test/test.md')
|
||||
.pipe(gulpCallFunction(myFunction, 'forEach'))
|
||||
.pipe(gulp.dest("./test/result/"));
|
||||
});
|
||||
gulp.start.apply(gulp, ['default']);
|
2
test/result/test.md
Normal file
2
test/result/test.md
Normal file
@ -0,0 +1,2 @@
|
||||
# Test.md
|
||||
This is a test file for the test.js gulp pipeline
|
2
test/test.md
Normal file
2
test/test.md
Normal file
@ -0,0 +1,2 @@
|
||||
# Test.md
|
||||
This is a test file for the test.js gulp pipeline
|
35
test/test.ts
35
test/test.ts
@ -1,35 +0,0 @@
|
||||
import { expect, tap } from '@push.rocks/tapbundle';
|
||||
|
||||
import * as smartgulp from '@push.rocks/smartgulp';
|
||||
import gulp from 'gulp';
|
||||
import * as gulpFunction from '../ts/index.js';
|
||||
|
||||
import * as smartpromise from '@push.rocks/smartpromise';
|
||||
|
||||
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();
|
||||
}
|
||||
})
|
||||
);
|
||||
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();
|
@ -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'
|
||||
}
|
26
ts/compile/compile.js
Normal file
26
ts/compile/compile.js
Normal file
@ -0,0 +1,26 @@
|
||||
// import gulp
|
||||
var gulp = require("gulp"),
|
||||
gulpTypescript = require("gulp-typescript");
|
||||
|
||||
gulp.task('compileTS', function() {
|
||||
var stream = gulp.src('../index.ts')
|
||||
.pipe(gulpTypescript({
|
||||
out: "index.js"
|
||||
}))
|
||||
.pipe(gulp.dest("../../"));
|
||||
return stream;
|
||||
});
|
||||
|
||||
gulp.task('compileTestTS', function() {
|
||||
var stream = gulp.src('../test.ts')
|
||||
.pipe(gulpTypescript({
|
||||
out: "test.js"
|
||||
}))
|
||||
.pipe(gulp.dest("../../"));
|
||||
return stream;
|
||||
});
|
||||
|
||||
gulp.task('default',['compileTS','compileTestTS'], function() {
|
||||
console.log('Typescript compiled');
|
||||
});
|
||||
gulp.start.apply(gulp, ['default']);
|
2
ts/compile/compile.sh
Normal file
2
ts/compile/compile.sh
Normal file
@ -0,0 +1,2 @@
|
||||
nvm use v0.12.7
|
||||
gulp
|
2
ts/compile/readme.md
Normal file
2
ts/compile/readme.md
Normal file
@ -0,0 +1,2 @@
|
||||
# How to compile.
|
||||
Make sure gulp and gulp-taypescript from npm are available. Then run the gulpfile in this directory.
|
111
ts/index.ts
111
ts/index.ts
@ -1,87 +1,46 @@
|
||||
import * as smartpromise from '@push.rocks/smartpromise';
|
||||
import * as through2 from 'through2';
|
||||
import { Transform } from 'stream';
|
||||
/// <reference path="typings/tsd.d.ts" />
|
||||
var through = require("through2");
|
||||
var path = require("path");
|
||||
var beautylog = require("beautylog");
|
||||
|
||||
export type TExecutionMode = 'forEach' | 'forFirst' | 'atEnd';
|
||||
//important vars
|
||||
var gulpCallFunction = {
|
||||
executionMode: 'forEach', //can be forEach or atEnd
|
||||
functionsToExecute: undefined,
|
||||
logBool: false
|
||||
};
|
||||
|
||||
export interface IPromiseFunction {
|
||||
(file?, enc?): PromiseLike<any>;
|
||||
}
|
||||
|
||||
let defaultExport = (
|
||||
functionsToExecuteArg: IPromiseFunction | IPromiseFunction[],
|
||||
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') {
|
||||
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);
|
||||
var runFunctionNames = function () {
|
||||
if (typeof gulpCallFunction.functionsToExecute == "function" ) {
|
||||
gulpCallFunction.functionsToExecute();
|
||||
} else if (Array.isArray(gulpCallFunction.functionsToExecute)) {
|
||||
for (var anyFunction in gulpCallFunction.functionsToExecute) {
|
||||
anyFunction();
|
||||
}
|
||||
hasExecutedOnce = true;
|
||||
break;
|
||||
case 'atEnd':
|
||||
cb();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
let atEnd = function(cb) {
|
||||
if (executionModeArg === 'atEnd') {
|
||||
checkAndRunFunction(null, null).then(function() {
|
||||
cb();
|
||||
});
|
||||
} else {
|
||||
cb();
|
||||
beautylog.error('gulp-callfunction: something is strange with the given arguments');
|
||||
}
|
||||
};
|
||||
return through2.obj(forEach, atEnd);
|
||||
};
|
||||
|
||||
export let forEach = (funcArg: IPromiseFunction) => {
|
||||
return defaultExport(funcArg, 'forEach');
|
||||
|
||||
var forEach = function (file, enc, cb) {
|
||||
if (gulpCallFunction.logBool) beautylog.log(gulpCallFunction.executionMode);
|
||||
if (gulpCallFunction.executionMode === 'forEach') {
|
||||
if(gulpCallFunction.logBool) beautylog.log('is forEach');
|
||||
runFunctionNames();
|
||||
}
|
||||
//tell gulp that we are complete
|
||||
return cb(null, file);
|
||||
};
|
||||
|
||||
export let forFirst = (funcArg: IPromiseFunction) => {
|
||||
return defaultExport(funcArg, 'forFirst');
|
||||
var atEnd = function() {
|
||||
if (gulpCallFunction.executionMode == "atEnd") {
|
||||
runFunctionNames();
|
||||
}
|
||||
};
|
||||
|
||||
export let atEnd = (funcArg: IPromiseFunction) => {
|
||||
return defaultExport(funcArg, 'atEnd');
|
||||
module.exports = function (functionsToExecute:any|any[],executionMode:string = 'forEach', logBool = false) {
|
||||
gulpCallFunction.functionsToExecute = functionsToExecute;
|
||||
gulpCallFunction.executionMode = executionMode;
|
||||
gulpCallFunction.logBool = logBool;
|
||||
return through.obj(forEach,atEnd);
|
||||
};
|
||||
|
||||
export default defaultExport;
|
||||
|
14
ts/test.ts
Normal file
14
ts/test.ts
Normal file
@ -0,0 +1,14 @@
|
||||
/// <reference path="typings/tsd.d.ts" />
|
||||
var gulp = require("gulp");
|
||||
var gulpCallFunction = require("./index.js");
|
||||
|
||||
var myFunction = function () {
|
||||
console.log("Hello World!");
|
||||
}
|
||||
|
||||
gulp.task('default',function() {
|
||||
gulp.src('./test/test.md')
|
||||
.pipe(gulpCallFunction(myFunction,'forEach'))
|
||||
.pipe(gulp.dest("./test/result/"))
|
||||
});
|
||||
gulp.start.apply(gulp, ['default']);
|
15
ts/tsd.json
Normal file
15
ts/tsd.json
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
"version": "v4",
|
||||
"repo": "borisyankov/DefinitelyTyped",
|
||||
"ref": "master",
|
||||
"path": "typings",
|
||||
"bundle": "typings/tsd.d.ts",
|
||||
"installed": {
|
||||
"node/node.d.ts": {
|
||||
"commit": "efa0c1196d7280640e624ac1e7fa604502e7bd63"
|
||||
},
|
||||
"colors/colors.d.ts": {
|
||||
"commit": "3191f6e0088eee07c4d8fd24e4d27a40a60d9eb9"
|
||||
}
|
||||
}
|
||||
}
|
123
ts/typings/colors/colors.d.ts
vendored
Normal file
123
ts/typings/colors/colors.d.ts
vendored
Normal file
@ -0,0 +1,123 @@
|
||||
// Type definitions for Colors.js 0.6.0-1
|
||||
// Project: https://github.com/Marak/colors.js
|
||||
// Definitions by: Bart van der Schoor <https://github.com/Bartvds>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
declare module "colors" {
|
||||
interface Color {
|
||||
(text: string): string;
|
||||
|
||||
black: Color;
|
||||
red: Color;
|
||||
green: Color;
|
||||
yellow: Color;
|
||||
blue: Color;
|
||||
magenta: Color;
|
||||
cyan: Color;
|
||||
white: Color;
|
||||
gray: Color;
|
||||
grey: Color;
|
||||
|
||||
bgBlack: Color;
|
||||
bgRed: Color;
|
||||
bgGreen: Color;
|
||||
bgYellow: Color;
|
||||
bgBlue: Color;
|
||||
bgMagenta: Color;
|
||||
bgCyan: Color;
|
||||
bgWhite: Color;
|
||||
|
||||
reset: Color;
|
||||
bold: Color;
|
||||
dim: Color;
|
||||
italic: Color;
|
||||
underline: Color;
|
||||
inverse: Color;
|
||||
hidden: Color;
|
||||
strikethrough: Color;
|
||||
|
||||
rainbow: Color;
|
||||
zebra: Color;
|
||||
america: Color;
|
||||
trap: Color;
|
||||
random: Color;
|
||||
}
|
||||
|
||||
module e {
|
||||
export function setTheme(theme:any): void;
|
||||
|
||||
export var black: Color;
|
||||
export var red: Color;
|
||||
export var green: Color;
|
||||
export var yellow: Color;
|
||||
export var blue: Color;
|
||||
export var magenta: Color;
|
||||
export var cyan: Color;
|
||||
export var white: Color;
|
||||
export var gray: Color;
|
||||
export var grey: Color;
|
||||
|
||||
export var bgBlack: Color;
|
||||
export var bgRed: Color;
|
||||
export var bgGreen: Color;
|
||||
export var bgYellow: Color;
|
||||
export var bgBlue: Color;
|
||||
export var bgMagenta: Color;
|
||||
export var bgCyan: Color;
|
||||
export var bgWhite: Color;
|
||||
|
||||
export var reset: Color;
|
||||
export var bold: Color;
|
||||
export var dim: Color;
|
||||
export var italic: Color;
|
||||
export var underline: Color;
|
||||
export var inverse: Color;
|
||||
export var hidden: Color;
|
||||
export var strikethrough: Color;
|
||||
|
||||
export var rainbow: Color;
|
||||
export var zebra: Color;
|
||||
export var america: Color;
|
||||
export var trap: Color;
|
||||
export var random: Color;
|
||||
}
|
||||
|
||||
export = e;
|
||||
}
|
||||
|
||||
interface String {
|
||||
black: string;
|
||||
red: string;
|
||||
green: string;
|
||||
yellow: string;
|
||||
blue: string;
|
||||
magenta: string;
|
||||
cyan: string;
|
||||
white: string;
|
||||
gray: string;
|
||||
grey: string;
|
||||
|
||||
bgBlack: string;
|
||||
bgRed: string;
|
||||
bgGreen: string;
|
||||
bgYellow: string;
|
||||
bgBlue: string;
|
||||
bgMagenta: string;
|
||||
bgCyan: string;
|
||||
bgWhite: string;
|
||||
|
||||
reset: string;
|
||||
bold: string;
|
||||
dim: string;
|
||||
italic: string;
|
||||
underline: string;
|
||||
inverse: string;
|
||||
hidden: string;
|
||||
strikethrough: string;
|
||||
|
||||
rainbow: string;
|
||||
zebra: string;
|
||||
america: string;
|
||||
trap: string;
|
||||
random: string;
|
||||
}
|
2079
ts/typings/node/node.d.ts
vendored
Normal file
2079
ts/typings/node/node.d.ts
vendored
Normal file
File diff suppressed because it is too large
Load Diff
2
ts/typings/tsd.d.ts
vendored
Normal file
2
ts/typings/tsd.d.ts
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/// <reference path="node/node.d.ts" />
|
||||
/// <reference path="colors/colors.d.ts" />
|
@ -1,14 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"experimentalDecorators": true,
|
||||
"useDefineForClassFields": false,
|
||||
"target": "ES2022",
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"esModuleInterop": true,
|
||||
"verbatimModuleSyntax": true
|
||||
},
|
||||
"exclude": [
|
||||
"dist_*/**/*.d.ts"
|
||||
]
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user