Feng
Feng

Reputation: 78

Gulp not executing the zip task

I'm a newcomer to the gulp world, and hence I'm still baby-stepping how to troubleshoot this thing.

The issue: the zip task is being skipped, even being defined in the 'default' task.

Where/what am I missing?

More details

The gulp zip runs fine when specified in the command line (there is no eg; syntax error, and the output is being produced as expected):

$ gulp zip
[16:49:41] Using gulpfile ~/Work/........../gulpfile.js
[16:49:41] Starting 'zip'...
[16:49:41] Finished 'zip' after 11 ms
$

However, when running gulp (without any additional arguments, which means the default is chosen):

$ gulp
[16:49:34] Using gulpfile ~/Work/........../gulpfile.js
[16:49:34] Starting 'clean'...
[16:49:34] Finished 'clean' after 35 ms
...
...
[16:49:36] Finished 'minify-css' after 750 ms
[16:49:36] Starting 'build'...
[16:49:36] Finished 'build' after 2.1 μs
$

The zip task is being skipped (!?)

Checking the 'default' task definition:

gulp.task('default', ['clean'], function () {
  gulp.start('build');
});

And the `build' task is defined as:

gulp.task('build', ['html', 'images', 'fonts', 'misc', 'i18n', 'swagger', 'minify-js', 'minify-css', 'zip']);

Look the zip task listed in the end of the array. Finally, the zip task is defined as:

gulp.task('zip', function () {
  var packageName = 'whatever';
  var dateString = now.getFullYear()+('0'+(parseInt(now.getMonth())+1)).substr(-2)+('0'+now.getDate()).substr(-2);
  var timeString = ('0'+now.getHours()).substr(-2)+('0'+now.getMinutes()).substr(-2)+('0'+now.getSeconds()).substr(-2);
  gulp.src('target/dist/**')
    .pipe(zip(packageName+'-'+dateString+'.'+timeString+'.zip'))
    .pipe(gulp.dest('target'));
  return;
});

Any help [pointing the direction] will be greatly appreciated.

Upvotes: 0

Views: 614

Answers (1)

Feng
Feng

Reputation: 78

One more lesson learned!

Gulp, by default, runs as much as possible the tasks in asynchronous fashion - unless you've taken the appropriate measures to force it to run the tasks in a sequential manner.

Having this said, the zip task was indeed executed - but it was executed way earlier than I was expecting - hence I was [incorrectly] assuming it didn't ran at all.

Therefore, instead of adding the 'zip' task as one more task that the 'build' task depends on, I made the 'zip' task to depend on the 'build' task, and have the 'default' task run the 'zip' task:

gulp.task('zip', function () {
  var packageName = 'whatever';
  var dateString = now.getFullYear()+...
  var timeString = ('0'+now.getHours()).substr(-2)+...
  gulp.src('target/dist/**')
    .pipe(zip(packageName+'-'+dateString+'.'+timeString+'.zip'))
    .pipe(gulp.dest('target'));
  return;
});

gulp.task('build', ['html', 'images', 'fonts', 'misc', 'i18n', 'swagger', 'minify-js', 'minify-css']);

gulp.task('default', ['clean'], function () {
  //gulp.start('build');
  gulp.start('zip');
});

After these changes, the build started to work as expected:

$ gulp
[17:04:59] Using gulpfile ~/Work/ij-wksp/smiles-password-form-Q1_2017/gulpfile.js
[17:04:59] Starting 'clean'...
[17:04:59] Finished 'clean' after 45 ms
[17:04:59] Starting 'default'...
[17:04:59] Starting 'wiredep'...
[17:04:59] Starting 'injector:css'...
[17:04:59] Starting 'scripts'...
[17:05:00] Starting 'version'...
[17:05:00] Starting 'consolidate:jade:app'...
[17:05:00] Starting 'consolidate:jade:scripts'...
...
[17:05:01] Finished 'html' after 233 ms
[17:05:01] Starting 'build'...
[17:05:01] Finished 'build' after 3.71 μs
[17:05:01] Starting 'zip'...
[17:05:01] Finished 'zip' after 1.95 ms
$

Upvotes: 1

Related Questions