Reputation: 25
There's simple gulpfile but it doesn't executes as expected:
var gulp = require('gulp');
var rename = require('gulp-rename');
var mapStream = require('map-stream');
var fs = require('fs');
gulp.task('default', function () {
gulp.src('123.js')
.pipe(log('before'))
.pipe(rename({prefix: '_'}))
.pipe(gulp.dest('.'))
.pipe(log('after'))
;
});
function log (txt) {
return mapStream(function (file, cb) {
console.log(txt, fs.statSync(file.path).size, !!file.contents.toString());
cb();
});
}
logs only "before", but no "after". why?
Upvotes: 0
Views: 998
Reputation: 4777
In addition to returning the stream as Sindre suggested, you need to pass 'file' to the callback function of 'map-stream' in order to pass the data through the stream.
function log (txt) {
return mapStream(function (file, cb) {
console.log(txt, fs.statSync(file.path).size, !!file.contents.toString());
cb(null, file);
});
}
Upvotes: 1
Reputation: 63487
You need to return the stream:
gulp.task('default', function () {
return gulp.src('123.js')
.pipe(log('before'))
.pipe(rename({prefix: '_'}))
.pipe(gulp.dest('.'))
.pipe(log('after'));
});
Upvotes: 1