franleplant / require-less

Browserify transform to require('file.less')
MIT License
1 stars 0 forks source link

Improve the stream interface #3

Open franleplant opened 10 years ago

franleplant commented 10 years ago

The stream interface right now is an array attribute called pipe. I foresee an opportunity for improvements, giving the user more freedom in terms of handling the stream.

This may implicate an overall change of the current API.

This is a tentative solution:

var fs = require('fs');

var require_less_factory = require('require-less');
var less_opts = {...};

function css_stream_processor( css_stream ) { 
   // This function will be called when the less parser finishes
   // it's work and returns the css stream
  css_stream.pipe(stream_transform1)
            .pipe(stream_transform2)
            ...
            .pipe(stream_transformn)
            .pipe(fs.createWriteStream('path/compiled.css'));
};

var require_less_transform = require_less_factory(
                                less_opts, 
                                css_stream_processor 
                            );

var browserify = require('browserify');
browserify_opts = {...}
browserify(browserify_opts).transform(require_less);

This illustrates that with this type of API the library is not just giving access to the pipeline, but its giving access to the css_stream itself, potentially providing more flexibility and composability, and also providing a more standard way of handling the stream.

franleplant commented 10 years ago

@uipoet, glad to hear your feedback.