gulp-plugin-extras
Advanced tools
Comparing version 0.1.0 to 0.2.0
import File = require('vinyl'); | ||
export type Options = { | ||
/** | ||
Whether the plugin can handle directories. | ||
@default false | ||
*/ | ||
readonly supportsDirectories: boolean; | ||
/** | ||
An async generator function executed for finalization after all files have been processed. | ||
You can yield more files from it if needed. | ||
@example | ||
``` | ||
import {gulpPlugin} from 'gulp-plugin-extras'; | ||
export default function gulpFoo() { | ||
return gulpPlugin( | ||
'gulp-foo', | ||
async file => { … }, | ||
{ | ||
onFinish: async function * () { | ||
yield someVinylFile; | ||
yield someVinylFile2; | ||
} | ||
} | ||
); | ||
} | ||
``` | ||
*/ | ||
readonly onFinish?: () => AsyncGenerator<File.BufferFile>; | ||
}; | ||
/** | ||
@@ -8,3 +42,2 @@ Create a Gulp plugin. | ||
@param onFile - The async function called for each vinyl file in the stream. Must return a modified or new vinyl file. | ||
@param onFinish - An async generator function executed for finalization after all files have been processed. You can yield more files from it if needed. | ||
@@ -16,13 +49,6 @@ @example | ||
export default function gulpFoo() { | ||
return gulpPlugin( | ||
'gulp-foo', | ||
async file => { | ||
file.contents = await someKindOfTransformation(file.contents); | ||
return file; | ||
}, | ||
async function* () { | ||
yield someVinylFile; | ||
yield someVinylFile2; | ||
} | ||
); | ||
return gulpPlugin('gulp-foo', async file => { | ||
file.contents = await someKindOfTransformation(file.contents); | ||
return file; | ||
}); | ||
} | ||
@@ -34,3 +60,3 @@ ``` | ||
onFile: (file: File.BufferFile) => Promise<File.BufferFile>, | ||
onFinish?: () => AsyncGenerator<File.BufferFile> | ||
options?: Options | ||
): NodeJS.ReadableStream; |
import transformStream from 'easy-transform-stream'; | ||
import PluginError from './plugin-error.js'; | ||
export function gulpPlugin(name, onFile, onFinish) { | ||
export function gulpPlugin(name, onFile, {onFinish, supportsDirectories} = {}) { | ||
return transformStream( | ||
@@ -10,3 +10,3 @@ { | ||
async file => { | ||
if (file.isNull()) { | ||
if (file.isNull() && !(supportsDirectories && file.isDirectory())) { | ||
return file; | ||
@@ -13,0 +13,0 @@ } |
{ | ||
"name": "gulp-plugin-extras", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Useful utilities for creating Gulp plugins", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -26,3 +26,3 @@ # gulp-plugin-extras | ||
### `gulpPlugin(name, onFile, onFinish?)` | ||
### `gulpPlugin(name, onFile, options?)` | ||
@@ -45,4 +45,15 @@ Create a Gulp plugin. | ||
#### onFinish | ||
#### options | ||
Type: `object` | ||
##### supportsDirectories | ||
Type: `boolean`\ | ||
Default: `false` | ||
Whether the plugin can handle directories. | ||
##### onFinish | ||
Type: `async function * (): void` | ||
@@ -61,5 +72,7 @@ | ||
async file => { … }, | ||
async function * () { | ||
yield someVinylFile; | ||
yield someVinylFile2; | ||
{ | ||
onFinish: async function * () { | ||
yield someVinylFile; | ||
yield someVinylFile2; | ||
} | ||
} | ||
@@ -66,0 +79,0 @@ ); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9043
190
79