[英]How do I output gulp results to console?
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. 我想把我的拼写检查结果输出到控制台而不是文件,我认为这应该有效,因为据我了解它gulp返回一个流。
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);
});
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);
}
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.