gulpjs/gulp

gulp.trigger(taskName) should be a through stream

Closed this issue · 6 comments

This makes this use case possible

gulp = require 'gulp'

coffee = require 'gulp-coffee'
minify = require 'gulp-minify'

gulp.task 'reload', ->
  # do some live reload stuff here

gulp.task 'coffee', ->
  # compile, minify, and copy all coffee-script
  gulp.files("./client/js/**", {ignore:["vendor"]})
    .pipe(coffee)
    .pipe(minify)
    .pipe(gulp.folder("./public/js"))
    .pipe(gulp.trigger('reload'))

gulp.task 'js', ->
  # minify and copy all vendor files
  gulp.files("./client/js/vendor/**")
    .pipe(minify)
    .pipe(gulp.folder("./public/js/vendor"))
    .pipe(gulp.trigger('reload'))

gulp.task 'default', ->
  gulp.run 'js', 'coffee'

  gulp.watch "./client/js/**", ->
    gulp.run 'js', 'coffee'

So really just an es.map stream that does nothing but trigger a task and passes the same file through when its done.

If plugins could get a reference to the gulp engine, this would make a cool plugin.

@robrich that can be dangerous though. Plugins should be relatively stateless. If plugins were able to get into the task system I feel like that would lead to grunt where plugins are responsible for creating their own tasks in the system and you're supposed to just assume the names

The only question in my mind about this is the behavior. Should it fire for every file that passes through or should it wait until the entire upstream is done before firing then pass everything through? Flag to toggle each behavior?

I see the point. If plugins can reach into the main system, things could quickly get out of hand.

I think it should trigger on stream end as you can't pass the filename into the other task, and if you wanted to you should pipe into a plugin in the current task instead.

Closing this - I don't think it is a good idea (otherwise I would have implemented it by now)

If anyone has arguments for/against it I'm still open to discussion

An alternative is to execute the reload task within the run callback, since it is executed once all tasks are finished:

gulp.run 'js', 'coffee', (err)->
  gulp.run('reload') if !err