gruntjs / grunt-contrib-watch

Run tasks whenever watched files change.
http://gruntjs.com/
MIT License
1.98k stars 356 forks source link

grunt-run with grunt-watch #506

Open mmumshad opened 8 years ago

mmumshad commented 8 years ago

I am trying to use osprey-mock-service to mock RAML service in my project. When I serve my application with grunt, I use grunt-run to execute the mock service before the application is shared like this:

//Run
    run: {
      options: {
        wait: false
      },
      commands: {
        exec: 'osprey-mock-service -f RAML\\api.raml -p 8000'
      }
    },
...
...
grunt.task.run([
      'clean:server',
      'wiredep',
      'concurrent:server',
      'autoprefixer:server',
      'run',
      'connect:livereload',
      'watch'
    ]);

I am trying to watch my api.raml file so if it is changed, the osprey-mock-service is re-run automatically like this:

watch: {
      raml:{
          files: ['RAML\\api.raml'],
          tasks: ['run']
      }
}

When I change the file, I get the following error. What am I doing wrong? Is this a bad way to do this?

>> File "RAML\api.raml" changed.
Running "run:commands" (run) task
>> Skipping run:commands since it not itterable. Call it directly or from another task.
adanieljsinclair commented 7 years ago

I have the same issue - did you work it out?

kanthoney commented 7 years ago

The problem is with grunt-run. If you've got the gruntfile

module.exports = function(grunt)
{
  grunt.initConfig({
    run: {
      ls: {
        cmd: 'ls'
      }
    }
  });
  grunt.loadNpmTasks('grunt-run');
};

and run grunt run you get the error message. If you run grunt run:ls it works fine.

Looking at grunt-run's source code, it looks as if tasks are skipped if the keyword run appears on the command line, unless the task is explicitly specified or the itterable (note spelling) option is set to true. I'm sure there's a really good reason for this, but I don't know what it might be.

So you would have to add itterable: true to your options for the run config, or change run to run:commands.