Useful utilities for creating Gulp plugins
npm install gulp-plugin-extrasimport {gulpPlugin, PluginError} from 'gulp-plugin-extras'; const pluginName = 'gulp-foo'; export default function gulpFoo(requiredArgument) { if (!requiredArgument) { throw new PluginError(pluginName, 'Missing argument `requiredArgument`'); } return gulpPlugin(pluginName, async file => { file.contents = await someKindOfTransformation(file.contents); return file; }); }Create a Gulp plugin.
If you throw an error with a .isPresentable = true property, it will not display the error stack.
This does not support streaming unless you enable the supportsAnyType option.
Type: string
The plugin name.
Type: (file) => file
The function called for each Vinyl file in the stream. Must return a modified or new Vinyl file. May be async.
Type: object
Type: boolean
Default: false
Whether the plugin can handle directories.
Type: boolean
Default: false
Whether the plugin can handle any Vinyl file type.
Useful for custom type filtering.
Supersedes supportsDirectories.
Type: async function * (stream: NodeJS.ReadableStream): AsyncGenerator<File, never, void>
An async generator function executed for finalization after all files have been processed.
You can yield more files from it if needed.
import {gulpPlugin} from 'gulp-plugin-extras'; export default function gulpFoo() { return gulpPlugin( 'gulp-foo', async file => { … }, { async * onFinish() { yield someVinylFile; yield someVinylFile2; } } ); }Create a Gulp plugin error. See the types for docs.