title: Using Gulp 4 with Promises to Clean/Copy Files
body: <p>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).</p>
  
  <pre><code>gulp.task('make-app', function makeApp(done) {
      function make() {
          return gulp.src(getPatterns('src-app'))
              .pipe(gulp.dest('./build/app/'));
      }
  
      return (args.noclean &amp;&amp; !args.deploy)
          ? make()
          : del(getPatterns('dest-app')
              .then(make);
              // .then(done);
  });
  </code></pre>
  
  <p>Some things to note:</p>
  
  <p><code>getPatterns()</code> is a function which simply returns a glob pattern from my config.
  The <code>src-app</code> glob is: <code>[ './source/app/**/*' ]</code>. The <code>(args.noclean &amp;&amp; !args.deploy)</code> evaluate to <code>false</code>, which starts the <code>del</code> module (which is v2, so it returns a <code>Promise</code>). To my limited understanding of Promises, we <code>.then()</code> it to the <code>make()</code> function, which I'd love to return a Promise and just chain a <code>.then(done)</code>, but that's where I'm lost. Currently, I'm just returning a <code>stream</code>, which is resulting in not all the files copying over.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I've taken about 70 more random stabs (the absolute, most miserable way to gain experience!) and have come up with this:</p>
  
  <pre><code>return del(getPatterns('dest-app'))
      .then(function() {
          return gulp.src(getPatterns('src-app'))
              .pipe(gulp.dest(dest + app));
      });
  </code></pre>
  
  <p>And the build process completes, the files always get deleted first, but Gulp only copies over the first 16 files/folders from the stream.</p>
  
  <p><strong>UPDATE 2</strong> - 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).</p>
  
  <pre><code>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]);
  </code></pre>