I'm learning how to use gulpjs. From what I've been reading/watching on youtube. Gulp is a task runner like grunt except that it uses streams built on nodes stream api http://nodejs.org/api/stream.html I have a few questions about the utility...
-- 1. I've heard from several people that gulpjs is faster than grunt because it uses streams. I don't understand what the big benefit of streams is. I know it helps when you're processing very large files (parsing csv files) but for stuff like running unit tests or compiling sass files, I don't what the benefit is.
2. I'm finding it very hard to sniff the stream for raw data and running code against it. Here is an example. I want to write a test to see if a program is up or not...
var shell = require('gulp-shell');
gulp.task('test', function() {
var task = shell.task(['boot2docker status']);
var stream = task();
stream
.setEncoding('utf8')
.on('readable', function(a){
var chunk;
console.log('---readable---');
console.log(JSON.stringify(a, null, 4));
console.log(stream.read());
while (null !== (chunk = stream.read())) {
console.log('got %d bytes of data', chunk.length);
console.log('data: ', chunk);
}
})
.on('data', function(a){
console.log('---data---');
console.log(a);
})
.on('end', function(){
console.log('---end----');
});
});
I've tried a few different ways of trying to sniff the stream and this is the closest I've been. In all my attempts, I can get the stream object. But I just want to capture the output of the command and run an if condition on it. The bash command only returns a single line so it's really easy to check once I get it. But I can't get to it easily. Am I using streams in the wrong way? From what I read, stream api is based on the eventemitter built into node so it comes with events I can tap into. I know I'm doing this wrong but I don't know why.
3. is there a way to emit errors with proper exit codes so CI processes can catch errors? From what I've seen, people just do a console.log to output data but what if I make a custom task that I want to throw propper errors i.e. gulp knows it's an error, highlights it as an error and a CI environment like drone.io could see that and know something went wrong.
4. Theres the native node stream, buffers, file stream and vinyl. What is the difference between each, how do you know which one is being used in your task and why are there different stream types? Are there any sites that give a general breakdown of them? https://medium.com/@webprolific/getting-gulpy-a2010c13d3d5 that is the closest thing I've found but it's way over my head.
-Thank you
You received this message because you are subscribed to the Google Groups "JavaScript Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to javascript-information+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.