Munter / tolk

A file reader that promises to translate non-web assets to web assets given the available transpilers. Autoprefixing, sourcemaps and all!
27 stars 0 forks source link

Add stream input to the API #14

Open gustavnikolaj opened 9 years ago

gustavnikolaj commented 9 years ago

As we talked about, this would allow us to more easily integrate it into an express middleware.

I was considering something like this.

it('should accept a stream as input', function () {
    var scssFileAsStream = fs.createReadStream('path/to/stylesheet.scss');

    return expect(tolk.readStream(scssFileAsStream), 'to be fulfilled').then(function (compiled) {
        return expect(compiled, 'to be valid css');
    });
});

I also thought about making tolk into a writable stream. That would allow you to pipe to it, but it may be too invasive. I don't know..

Munter commented 9 years ago

I think we would need to pass in the file name, file extension or explicitly desired transpiler for it to know which one to apply.

A tolk readStream method should probably also return a steam wrapped promise for pipes to continue working

gustavnikolaj commented 9 years ago

Of course, you'd need at least the file name in order for this to work in the same way as .read. Hmm...

I assume that you also use the path to the file to resolve fx. includes in a sass file?

Munter commented 9 years ago

Right. Forgot about that. Sass the includePaths. It's very tied to the file system, which is also the reason why my sass compiling express middleware does not use hijackresponse

gustavnikolaj commented 9 years ago

The main reason I needed stream support was to build a middleware that relied on the static middleware to get the files for me. I guess we could just skip that idea and handle file loading in the middleware itself. If it's needed for sass anyway, I guess it would be hard to get them to blend any way.

Munter commented 9 years ago

It would be nice to get the benefits of express-static behind it though. Then you wouldn't have to reimplement your own caching as well. I just don't really know how