gulp-bower
gulp-bower copied to clipboard
Can't action at end of bower task unless adding unnecessary .pipe command
gulp_bower is performing the task I want, which is for any of my 'self contained' modules to be able to locally install their bower components during the build process if they are not present.
My problem is, that this is one step in the chain, and it must complete before the RequireJS optimization step starts.
So, what I want to have is:
gulp.task("installBower",function(cb){
var progPath = path.join(opts.appRoot,opts.currentProgram);
fs.exists(path.join(progPath,"bower.json"),function(exists){
if(exists){
bower({directory:"./bower_components",cwd:progPath})
.on("end",function(res){
cb();
})
}
else{
console.log("installBower: no bower.json found");
cb();
}
});
});
Problem is, I have to add in a line:
gulp.task("installBower",function(cb){
var progPath = path.join(opts.appRoot,opts.currentProgram);
fs.exists(path.join(progPath,"bower.json"),function(exists){
if(exists){
bower({directory:"./bower_components",cwd:progPath})
.pipe(gulp.dest(path.join(progPath,"bower_components")))//<----UNNECESSARY STEP
.on("end",function(res){
cb();
})
}
else{
console.log("installBower: no bower.json found");
cb();
}
});
});
To make the *.on("end" * event trigger.
Without that pipe, and with no following tasks, this runs fine and installs the bower components as I want them, but the rest of the gulp chain doesn't fire because the "end" event is never called.
Am I not understanding something about gulp and pipes... I just want to be able to run the bower task and have the next task only run once the bower step is finished.
I faced the same issue as described above. It feels counter intuitive compared to other gulp-x packages and the documentation doesn't really specify this as its behaviour.
I'm also having a problem with gulp-bower not emitting an end event (but only sometimes!). Adding the superfluous gulp.dest
doesn't work for me, though.
same problem here
IMHO I believe all you need is a return. Simple test, try removing the return on some of the gulp tasks and you'll notice it never says finish (even thought it had been running for 5 minutes :) )