1

I'm trying to run shell command when file changes. Getting last changed file to use as argument for shell command. Here is the code:

grunt.initConfig({
    changedFile: 'test',

    watch: {
        all: {
            files: ['js/*.js'],
            tasks: ['shell']
        }
    },

    shell: {
        run: {
            // it outputs 'test', not changed file
            command: 'touch <%= changedFile %>'
        }
    }

});

grunt.event.on('watch', function(action, filepath) {
    grunt.config('changedFile', filepath);
});

'watch' eventListener actually works, but it does after shell command runs. How can I run task before event has been triggered?

nikoloza
  • 968
  • 2
  • 12
  • 30

1 Answers1

1

options: { nospawn: true } for the watch task helped me on this.

Thanks guys from this thread: How to modify grunt watch tasks based on the file changed?

Community
  • 1
  • 1
nikoloza
  • 968
  • 2
  • 12
  • 30