I'm using grunt-contrib's concat
and uglify
modules to process some javascript. Currently if src/js/
is empty, they will still create an (empty) concat'd file, along with the minified version and a source map.
I want to task to detect if the src/js/
folder is empty before proceeding, and if it is, then the task should skip (not fail). Any ideas how to do this?
With this plugin:
https://www.npmjs.org/package/grunt-file-exists
You can check file existence. (I didn't try, but the source looks like supporting grunt expands. (*, ** ...)
For example like this::
But maybe if the file doesn't exist it will fail with error instead of simple skip. (I didn't test it.)
If this is a problem you can modify a bit the source of this plugin to run the related task if the file exists:
The config:
And you should add this:
In this file:
https://github.com/alexeiskachykhin/grunt-file-exists/blob/master/tasks/fileExists.js
after this line:
The solution may not be the prettiest, but could give you an idea. You'll need to run something like
npm install --save-dev glob
first. This is based on part of theMilkshake
project you mentioned.A gist for comparison: https://gist.github.com/kosmotaur/61bff2bc807b28a9fcfa
Maybe this is just a more up-to-date answer as the others are more than a year old, but you don't need a plugin for this; you can use
grunt.file.expand
to test if files matching a certain globbing pattern exist.Update of @Kosmotaur's answer (path is just hard-code here though for simplicity):