gulp-consolidate
gulp-consolidate copied to clipboard
added ability to accept its data from file.data
I've created a de-coupled (generic) data source plugin that sets a data attribute to the file object. Through the new gulp-data
plugin the data attribute can be set from a variety of sources such a JSON file, front-matter, a database, anything really. See https://www.npmjs.org/package/gulp-data for more detail and the rationale behind it. For this to be effective, I'm asking plugin devs that receive data through the options parameter to also accept this data via the file.data property. I've made the change and have added a test. Thanks!
This is possible already doing something like the following.
consolidate('swig', function (file) {
return file.data;
});
I saw that but that's not what I'm proposing. I've created a new plugin for setting the data object, for other plugins to consume. The passing in the options.data as a function rather than an object is not an abstract enough method IMO. This is because you've had to modify your code to check if options.data is a function. This is code smell. We need a standard by which plugin authors (gulp-jade, gulp-swig, gulp-consolodate, etc) can just consume a data object and not have to check whether or not it's a function. It's just an object. The new 'gulp-data
plugin allows this. For instance, if my data comes from an asynchronous source, I need a way to pass the result data through a callback function. Just passing a function to options.data isn't going to work. Having a standard that encapsulates these variations, allows your plugin to remain agnostic and have cleaner code as a result.
Having gulp-consolidate
allow a per-file callback is actually more flexible than just assuming a file.data
property was set by an earlier plugin.
I'm hesitant to tie data loading so closely to another plugin, especially when its already possible to load data supplied by gulp-data
via gulp-consolidate
's per-file callback.
Maybe adding an example to the gulp-consolidate
readme of how to use data from gulp-data
would suffice?
That's fine and makes sense in the short term. I guess what I'm trying to accomplish is to convince gulp plugin authors to use a single api provided through gulp-data. This new plugin manages all manner of passing data. There would be no need to pass a function; it already provides the per-file callback
For what it's worth, both gulp-jade and gulp-swig have been updated to follow this new standard