I want to put my spellcheck results out to the console instead of to a file and I think this should work since as I understand it gulp returns a stream.
Instead I get an error:
TypeError: Object #<Stream> has no method 'read'
Here is my code
gulp.task('spellcheck', function() {
var patterns = [{
// Strip tags from HTML
pattern: /(<([^>]+)>)/ig,
replacement: ''
}];
var spellSuggestions = [{
pattern: / [^ ]+? \(suggestions:[A-z, ']+\)/g,
replacement: function(match) {
return '<<<' + match + '>>>';
}
}];
var nonSuggestions = [{
pattern: /<<<.+>>>|([^\s]+[^<]+)/g,
replacement: function(match) {
if (match.indexOf('<') == 0) {
return '\n' + match + '\n';
}
return '';
}
}];
var toConsole = gulp.src('./_site/**/*.html')
.pipe(frep(patterns))
.pipe(spellcheck())
.pipe(frep((spellSuggestions)))
.pipe(frep((nonSuggestions)));
var b = toConsole.read();
console.log(b);
});
Gulp plugins are Node Transform Streams that encapsulate common behavior to transform files in a pipeline - often placed between src() and dest() using the . pipe() method. They can change the filename, metadata, or contents of every file that passes through the stream.
There is no read method on a stream. You have have two choices:
Implemented in code:
gulp.task('spellcheck', function () {
var patterns = [
{
// Strip tags from HTML
pattern: /(<([^>]+)>)/ig,
replacement: ''
}];
var nonSuggestions = [
{
pattern: /<<<.+>>>|([^\s]+[^<]+)/g,
replacement: function(match) {
if (match.indexOf('<')==0) {
return '\n' + match +'\n';
}
return '';
}
}];
var a = gulp.src('./_site/**/*.html')
.pipe(frep(patterns))
.pipe(spellcheck(({replacement: '<<<%s (suggestions: %s)>>>'})))
.pipe(frep(nonSuggestions))
;
a.on('data', function(chunk) {
var contents = chunk.contents.toString().trim();
var bufLength = process.stdout.columns;
var hr = '\n\n' + Array(bufLength).join("_") + '\n\n'
if (contents.length > 1) {
process.stdout.write(chunk.path + '\n' + contents + '\n');
process.stdout.write(chunk.path + hr);
}
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With