0

Trying to study https://github.com/jhades/angularjs-gulp-example/blob/master/gulpfile.js, and I have noticed that for the task build there is a dependency clean. However, for most of the other definitions clean is also specified as a dependency! So if I run build it will run clean, but then what about build-css and build-template-cache which both also have clean dependencies, etc... will it also run the clean for each of those dependencies? So basically will running the one command gulp build end up running clean more than once... wiping out the output from other dependencies.... or will running clean the first time explicitly satisfy the dependency for the other dependencies and prevent clean from running again!?

Any pointers will be appreciated.

Please Note

I am NOT asking about what the proper cleaning techniques are! I am specifically asking about the link that I posted... and how IT is handling the clean task.

Grateful
  • 9,685
  • 10
  • 45
  • 77
  • Possible duplicate of [How to clean a project correctly with gulp?](http://stackoverflow.com/questions/24396659/how-to-clean-a-project-correctly-with-gulp) – Claies Jan 23 '17 at 01:59
  • @Claies I briefly read the link... so, thank you. However, I am not asking about how to clean the project correctly. My question is specifically to do with the link I posted... and how it handles the cleaning. I just need to understand its flow.. because it apparently seems to be running fine. – Grateful Jan 23 '17 at 02:05
  • basically, the build is done in a pipeline, but the `clean` is not part of the pipeline. because `clean` is called as a dependency to each task, it must be done before the task is run, but each task then returns a promise object. The net effect is that the cleans are all run in the front end of the chain. – Claies Jan 23 '17 at 02:17
  • the only conflict really occurs if you happen to be using `watch` to trigger one of those tasks that has a dependency on `clean`, which would cause the `clean` to kick off during the watch, and potentially remove unwanted files, which is the problem that was happening in the link I referenced. – Claies Jan 23 '17 at 02:20
  • @Claies I see. Thank you. – Grateful Jan 23 '17 at 02:41
  • I've put in an edit that makes it super minimal. While it may not but accepted, if you feel as if the edit wasn't what you were looking, go ahead revert it, but please strip out some of the unneeded details. – David Archibald Feb 11 '17 at 22:21

1 Answers1

1

Dependencies

Dependencies in a gulp file just say that it has to have run before it at least once. For example this code:

var gulp = require('gulp');

gulp.task('main', ['b', 'a'], function() {
  return gulp;
});

gulp.task('a', ['b'], function() {
  return gulp;
});

gulp.task('b', ['a'], function() {
  return gulp;
});

Will run like this:

  • main
  • a
  • b

Not:

  • main
  • a
  • b
  • a
  • b

Repeating infinitely.

Dependencies execution order

However, it could just as easily be run in the order main, b, then a. This is because of synchronous tasks in gulp. The dependencies have to run before the task asynchronously, but they run together or synchronously, this answer explains the difference between synchronous and asynchronous.

To avoid this you can use this code in Gulp 4:

gulp.task('main', function() {
  gulp.series('a', 'b');
});

This will always run in the order main, a, b But below that, you need to use the run-sequence package. Here's an example:

var runSequence = require('run-sequence');
gulp.task('main', function() {
  runSequence('a', 'b');
})
David Archibald
  • 1,431
  • 14
  • 27
  • I thought the dependency order was not necessarily "in order" because they apparently run asynchronously. Isn't that true? – Grateful Jan 23 '17 at 02:43