grunt-contrib-watch icon indicating copy to clipboard operation
grunt-contrib-watch copied to clipboard

watch-Event should be fired at start-up for each file, when atBegin is true

Open 0815fox opened this issue 7 years ago • 0 comments

I have a task configured as follows:

...
watch: {
            'convert-model': {
                files: [
                    'src/ch.actifsource.cloud.model/**/*.asr'
                ],
                tasks: [],
                options: {
                    spawn: true,
                    interrupt: false,
                    atBegin: true
                },
            }
...
grunt.event.on('watch', function(Action, FilePath, Target) {
        if (Target === 'convert-model') {
            switch (Action) {
                case 'added':
                case 'changed':
                    var TargetPath = convertModelTargetPath(FilePath);
                    grunt.log.writeln('Converting model file ' + FilePath + ' to: ' + TargetPath);
                    myOwnFileConverterFunction(FilePath,TargetPath);
                    break;
                case 'deleted':
                var TargetPath = convertModelTargetPath(FilePath);
                    grunt.log.writeln('Deleting model file from: ' + TargetPath);
                    break;
                default:
                    grunt.log.writeln('Unknown action on ' + FilePath + ': ' + Action);
            }

        }
    });

I want my watch:convert-model task to convert each target file using my own converter function at startup and then each as it changes. However, the event is only emitted on changes after the watch task started. Request: When atBegin is set, the event should also be called for each file which exists at the beginning. However, I am not sure, whether that should be seen as added or modified-action. It may even make sense to define a new action string, e.g. atBegin, then one could easily filter those out when atBegin is set, but the custom code shall not be executed for atBegin-Modifications.

0815fox avatar Oct 06 '16 13:10 0815fox