Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for processing single files for interop with gulp-watch #111

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,23 @@ gulp.task('compass', function() {
});
```

### Usage with gulp-watch

```javascript
var compass = require('gulp-compass'),
watch = require('gulp-watch');

gulp.task('compass', function() {
return watch('./src/*.scss')
.pipe(compass.singleFile({
css: 'app/assets/css',
sass: 'app/assets/sass',
image: 'app/assets/images'
}))
.pipe(gulp.dest('app/assets/temp'));
});
```

## Configuration

### Configuration Options
Expand Down
31 changes: 31 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ var callCounter = require('./callCounter');
var through = require('through2');
var gutil = require('gulp-util');
var path = require('path');
var source = require('vinyl-source-stream');
var eventStream = require('event-stream');

// Consts
var PLUGIN_NAME = 'gulp-compass';
Expand Down Expand Up @@ -77,3 +79,32 @@ module.exports = function(opt) {

return through.obj(collectNames, compile);
};

/**
* Run compass on single sass files as they come down the stream.
*
* The gulp-compass plugin collects all files and runs compass on them when the
* stream is over, but the stream is never over when watching.
*/
module.exports.singleFile = function(opt) {

return eventStream.map(function(file, callback) {

var result;

var stream = source(file.relative)
.pipe(module.exports(opt))
.on('data', function(data) {
result = data;
})
.on('end', function() {
callback(null, result);
});

stream.write(file);

stream.end();

});

};
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
},
"homepage": "https://github.com/appleboy/gulp-compass",
"dependencies": {
"event-stream": "^3.3.2",
"gulp-util": "^3.0.4",
"through2": "^0.6.5",
"vinyl-source-stream": "^1.1.0",
"which": "^1.1.1"
},
"devDependencies": {
Expand Down