I am pretty new to Gulp and I kind of love it but also kind of don't really understand it at all so I might be going about this the wrong way entirely.
I have a file structure like this:
main
|-build
|-big_file1.txt
|-big_file2.txt
|-small_file3.txt
|-med_file4.txt
I want to copy the contents of build
to a new dir and then delete some files so I set up two tasks like this:
var gulp = require("gulp");
var foreach = require("gulp-foreach");
var del =require("del");
gulp.task("taskA", function(cb){
var err = undefined;
gulp.src("./build/*file*")
.pipe(foreach(function(stream, file){
stream.pipe(gulp.dest("./test"));
return stream;
}));
cb(err);
});
gulp.task("taskB", ["taskA"], function(cb){
var err = undefined;
del(["./test/*big*"]);
cb(err);
});
When I manually run gulp taskA
the duplicate files appear in ./test
as expected and if I then run gulp taskB
the ones prefixed with big
are deleted. All groovy and as expected.
I then try to run the tasks in sequence like this:
gulp.task("both", ["taskA", "taskB"]);
gulp.task("taskA", function(cb){
var err = undefined;
gulp.src("./build/*file*")
.pipe(foreach(function(stream, file){
stream.pipe(gulp.dest("./test"));
return stream;
}));
cb(err);
});
gulp.task("taskB", ["taskA"], function(cb){
var err = undefined;
del(["./test/*big*"]);
cb(err);
});
And it doesn't work the same way. The log says that taskA
is started then finished THEN taskB
THEN both
and the duplicate files are created in ./test
but the deletion never occurs. Can anyone explain what is happening here and suggest a way to fix it?
Thank you in advance :)