Skip to content

gulp.trigger(taskName) should be a through stream #32

Closed

Description

@yocontra

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.

Activity

  1. robrich commented on Dec 2, 2013

    @robrich
    Contributor

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

  2. yocontra commented on Dec 4, 2013

    @yocontra
    MemberAuthor

    @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

  3. yocontra commented on Dec 4, 2013

    @yocontra
    MemberAuthor

    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?

  4. robrich commented on Dec 4, 2013

    @robrich
    Contributor

    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.

  5. yocontra commented on Dec 20, 2013

    @yocontra
    MemberAuthor

    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

  6. dashed commented on Dec 27, 2013

    @dashed
    Contributor

    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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions