I am very new to Promises, but would like to use them to sequentially fire off a clean (deleting files) and then a make (copying files from source to build).
gulp.task('make-app', function makeApp(done) {
function make() {
return gulp.src(getPatterns('src-app'))
.pipe(gulp.dest('./build/app/'));
}
return (args.noclean && !args.deploy)
? make()
: del(getPatterns('dest-app')
.then(make);
// .then(done);
});
Some things to note:
getPatterns()
is a function which simply returns a glob pattern from my config.
The src-app
glob is: [ './source/app/**/*' ]
. The (args.noclean && !args.deploy)
evaluate to false
, which starts the del
module (which is v2, so it returns a Promise
). To my limited understanding of Promises, we .then()
it to the make()
function, which I'd love to return a Promise and just chain a .then(done)
, but that's where I'm lost. Currently, I'm just returning a stream
, which is resulting in not all the files copying over.
UPDATE
I've taken about 70 more random stabs (the absolute, most miserable way to gain experience!) and have come up with this:
return del(getPatterns('dest-app'))
.then(function() {
return gulp.src(getPatterns('src-app'))
.pipe(gulp.dest(dest + app));
});
And the build process completes, the files always get deleted first, but Gulp only copies over the first 16 files/folders from the stream.
UPDATE 2 - The below code LOOKS as if it'd work, but Gulp reports that it is not completing (so a Stream, Promise or Callback is not being returned).
var make = new Promise(function(resolve, reject) {});
var clean = del(getPatterns('dest-app'))
.then(function() {
var makeStream = gulp.src(getPatterns('src-app'))
.pipe(gulp.dest(dest + app));
makeStream.on('end', function() {
make.resolve();
});
});
return Promise.all([clean, make]);