Andre Medeiros
Andre Medeiros

Reputation: 234

grunt watch batch tasks doesn't working

Here's my Grunfile watch task:

watch: {
  jsFiles: {
    files: ['www/js/*.js','!www/js/*.min.js'],
    tasks: ['jshint','<%= pkg.jsTask %>'],
    options: {
        event: ['added', 'changed'],
        spawn: false
    }
  },
  cssFiles : {
    files : ['<%= pkg.cssTask === "less" ? "www/less/*.less" : "www/css/*.css" %>'],
    tasks : ['<%= pkg.cssTask %>'],
    options: {
        event: ['added', 'changed'],
        spawn: false
    }
  },
  pageFiles : {
    files: ['www/**.php','www/**.html'],
    tasks: ['<%= "uglify:some" === pkg.jsTask ? "dom_munger:whenSomeJs" : "dom_munger:whenAllInOneJs" %>','undoDomMungerQuoteShit'],
    options: {
        event: ['added', 'changed'],
        spawn: false
    }
  },
  otherFiles : {
    files: ['www/**','!www/**.php','!www/**.html','!www/js/*.js','!www/css/*.less','!www/css/*.css'],
    tasks: ['copy:regularFiles'],
    options: {
        event: ['added', 'changed'],
        spawn: false
    }
  },
  allFiles : {
    files: ['www/**'],
    options: {
        event: ['deleted'],
        spawn: false
    } 
  },
  ftpFiles : {
    files: ['build/**'],
    tasks: ['copy:ftp'],
    options: {
        event: ['added', 'changed'],
        spawn: false
    }
  },
  ftpDelete : {
    files: ['build/**'],
    options: {
        event: ['deleted'],
        spawn: false
    }
  }
}

All sub tasks place de processed file in the 'build' folder. All sub tasks, but one are working as expected: "ftpFiles"

This sub task look for changes in the 'build' folder. When I update some 'build' folder file manually, "ftpFiles" works. But when the changed file is updated by some other sub task, "ftpFiles" does not trigger.

How can I fix that?

Upvotes: 1

Views: 378

Answers (1)

Leonardo Zanivan
Leonardo Zanivan

Reputation: 790

It looks like you need concurrent watchers to run. You could either use grunt-concurrent or grunt-focus to achieve that.

Follow below a grunt-concurrent example:

concurrent: {
  options: {
    logConcurrentOutput: true
  },
  dev: {
    tasks: ["watch:js", "watch:ftp"]
  }
}

grunt.registerTask("watch-dev", ["concurrent:dev"]);

Upvotes: 2

Related Questions