[Build] reinstantiate compass per task execution

Reinstantiate compass wrapper for each task execution.  Allows stylesheets
task to be run multiple times by watch.  Fixes a bug that prevents watch
from working properly.
This commit is contained in:
Pete Richards 2016-02-22 12:45:41 -08:00
parent 6d036a5d67
commit 34b0b55b97

View File

@ -71,10 +71,14 @@ var gulp = require('gulp'),
} }
} }
}, },
stream = require('stream'), stream = require('stream');
compassWrapper = new stream.Transform({objectMode: true});
/* Transform stream that allows us to transform individual files */ /**
* Returns a transform stream that allows us to customize the destination
* paths for individual sass files. Wraps compass.
*/
function customCompass() {
var compassWrapper = new stream.Transform({objectMode: true});
compassWrapper._transform = function (chunk, encoding, done) { compassWrapper._transform = function (chunk, encoding, done) {
if (/\/_[^\/]*.scss$/.test(chunk.path)) { if (/\/_[^\/]*.scss$/.test(chunk.path)) {
return done(); return done();
@ -86,15 +90,22 @@ compassWrapper._transform = function (chunk, encoding, done) {
css: baseDir + 'css/', css: baseDir + 'css/',
comments: true, comments: true,
bundle_exec: true bundle_exec: true
}; },
compassObj;
compass(options).on('data', function (file) { compassObj = compass(options);
done(null, file); compassObj.on('data', function (file) {
}).on('error', function (error) { this.push(file);
done(error); }.bind(this));
}) compassObj.on('end', function () {
.end(chunk); done();
});
compassObj.end(chunk);
}; };
return compassWrapper;
}
gulp.task('scripts', function () { gulp.task('scripts', function () {
return gulp.src(paths.main) return gulp.src(paths.main)
@ -113,7 +124,7 @@ gulp.task('compass');
gulp.task('stylesheets', function () { gulp.task('stylesheets', function () {
return gulp.src(paths.scss) return gulp.src(paths.scss)
.pipe(compassWrapper); .pipe(customCompass());
}); });
gulp.task('lint', function () { gulp.task('lint', function () {