A usage scenario of the extended version of grunt.file.expandFiles
that has the added feature of providing lists of:
- all - set of all files matching the
src
definition of the task (default option) - changed - set of files matching the
src
definition of the task that have been changed since the last iteration of thewatch
task - deleted - set of files matching the
src
definition of the task that have been deleted since the last iteration of thewatch
task
The task execution would go something like this:
- check for changed files:
files = grunt.file.expandFiles(this.file.src, {filter: "changed"})
- if there are any changed files (including new files) compile them:
if (files.lenght > 0) { compile_changed_files }
-
if there are no changed files continue to the next step
-
check for deleted files
files = grunt.file.expandFiles(this.file.src, {filter: "deleted"})
- if there are any deleted files delete their compiled counterparts:
if (files.lenght > 0) { delete_compiled_files }
A possible variation would be best explained with adding a concatenation step. If we need to do this, no additional check is needed, we just run the concat
task using all the current files matching the src
definition of the task:
files = grunt.file.expandFiles(this.file.src)
or
files = grunt.file.expandFiles(this.file.src, {filter: "all"})
and then run the concat
task:
result = grunt.helper('concat', files, {separator: this.data.separator});
If we want to make the task a more general purpose and handle calls that are not coming from the watch task only.
Using the lint
task as an example:
- if we have a changed file we just
lint
that file - if we have a deleted file we don't do anything
- but if we don't have neither changed nor deleted file we lint all the files defined for the task