Create gulp plugin from a function or object that works with string data (e.g. a converter).
API
Exposes function that returns a gulp plugin: gulpPluginFabric(name, run, [init])
.
name
: name of the plugin (will begulp-name
)run
: function that transforms incoming data, can be both sync or asyncinit
: function that is launched beforerun
with options (optional)
The following types of functions are supported:
- Sync:
run(data, options)
returns resulting string, or throws an error - Async:
run(data, options, cb)
callscb(null, result)
upon successful completion, orcb(err)
in case of an error
Examples
Let's create a simple gulp plugin that adds a custom suffix to the input string. For example, suffix "!" would result in "str" -> "str!" transformation.
Convert function to gulp plugin:
let text + optionssuffix;let plugin = "my-plugin" run;
Convert object to gulp plugin:
let runner = _suffix: "!" { return text + this_suffix; } { this_suffix = optionssuffix | ""; }; let plugin = "my-plugin" runnerrun runnerinit;
Then you can use plugin in gulp as follows:
gulp ;