bower - Gulp tasks not running synchronously -


i trying install packages through bower, , once installation finished, want files moved dist folder parent, , delete dist folder. somehow, not working properly.

var gulp = require('gulp'),     bower = require('gulp-bower'),     del = require('del'),     fs = require('fs'),     path = require('path'),     merge = require('merge-stream');     vinylpaths = require('vinyl-paths');     runsequence = require('run-sequence');  var apppath="./www"; var folders = getfolders(apppath);  /* function folders present in www */ function getfolders(dir) {     return fs.readdirsync(dir)       .filter(function(file) {         return fs.statsync(path.join(dir, file)).isdirectory();       }); }  gulp.task('clean', function (){     var tasks = folders.map(function(folder) {        return gulp.src(path.join(apppath, folder))             .pipe(vinylpaths(del))     }); });  /* gulp task run bower install */ gulp.task('bower', ['clean'], function() {     return bower({cmd: "install"});  });  /* gulp task copy files dist folder parent folders */ gulp.task('movefiles', ['bower'], function (){     var tasks = folders.map(function(folder) {         console.log("folder", folder);         return gulp.src(path.join(apppath, folder, '/dist/**/*'))             .pipe(gulp.dest(path.join(apppath, folder )));      });     return tasks; });  /* gulp task clean dist folder after files have been copied  */ gulp.task('delete-dist-folder', ['movefiles'], function () {     var tasks = folders.map(function(folder) {            return gulp.src(path.join(apppath, folder, '/dist'))                 .pipe(vinylpaths(del))     });     return tasks; });  gulp.task('default', ['delete-dist-folder']); 

this wrote till now. after bower, rest 2 tasks don't run. if run them individually, work fine.

i unable figure out going wrong here. appreciated.

the problem return arrays of event streams. @ delete-dist-folder task. return tasks , tasks created calling .map on array. tasks array (of event streams).

gulp not know arrays , assumes tasks synchronous. there 3 ways mark task asynchronous: 1) return stream; gulp wait stream end, 2) return promise; gulp wait promise resolved or rejected, or 3) declare task callback take single parameter you'll call when task done; gulp wait callback called. array of event streams not correspond of these options.

the gulp wiki suggest using merge-stream return more 1 stream task. judging code of merge-stream, , supposing imported merge-stream merge, return merge.apply(undefined, tasks).

side node: in clean task forgot return value.


Comments