Skip to content
This repository has been archived by the owner on Jun 24, 2024. It is now read-only.

Commit

Permalink
Merge pull request #35 from asset-pipe/update_css_writer
Browse files Browse the repository at this point in the history
Update css writer
  • Loading branch information
digitalsadhu authored Nov 23, 2017
2 parents a523182 + 9a8d15e commit c32ca69
Show file tree
Hide file tree
Showing 4 changed files with 534 additions and 922 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# asset-pipe-dev-middleware
# @asset-pipe/dev-middleware

[![Greenkeeper badge](https://badges.greenkeeper.io/asset-pipe/asset-pipe-dev-middleware.svg)](https://greenkeeper.io/)
30 changes: 4 additions & 26 deletions lib/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ const EventEmitter = require('events');
const watchify = require('watchify');
const devnull = require('dev-null');
const express = require('express');
const JsWriter = require('asset-pipe-js-writer');
const CssWriter = require('asset-pipe-css-writer');
const JsWriter = require('@asset-pipe/js-writer');
const CssWriter = require('@asset-pipe/css-writer');
const emits = require('emits');
const { Transform } = require('stream');

module.exports = class Middleware extends EventEmitter {
constructor(jsFiles = [], cssFiles = [], options = {}) {
Expand All @@ -27,7 +26,7 @@ module.exports = class Middleware extends EventEmitter {
this.emits = emits;
this.writers = {
js: new JsWriter(jsFiles, this.options, true),
css: new CssWriter(cssFiles, this.options),
css: new CssWriter(cssFiles, true),
};

this.writers.js.plugin(watchify);
Expand All @@ -43,16 +42,6 @@ module.exports = class Middleware extends EventEmitter {
bundler.pipe(devnull());
});

this.writers.css.on('update', () => {
const bundler = this.writers.css;

bundler.on('error', e => {
this.emit('error', e);
});

bundler.pipe(devnull());
});

// Proxy underlaying events
this.writers.js.on('error', this.emits('error'));
this.writers.js.on('update', this.emits('update'));
Expand All @@ -61,10 +50,6 @@ module.exports = class Middleware extends EventEmitter {
this.writers.js.on('log', this.emits('log'));

this.writers.css.on('error', this.emits('error'));
this.writers.css.on('update', this.emits('update'));
this.writers.css.on('bytes', this.emits('bytes'));
this.writers.css.on('time', this.emits('time'));
this.writers.css.on('log', this.emits('log'));

// eslint-disable-next-line new-cap
this.app = express.Router({
Expand Down Expand Up @@ -117,14 +102,7 @@ module.exports = class Middleware extends EventEmitter {
css() {
return (req, res, next) => {
res.type('css');
const bundler = this.writers.css.pipe(
new Transform({
objectMode: true,
transform(chunk, enc, cb) {
cb(null, chunk.content);
},
})
);
const bundler = this.writers.css.bundle();

bundler.on('error', cleanup);

Expand Down
Loading

0 comments on commit c32ca69

Please sign in to comment.