Skip to content

Instantly share code, notes, and snippets.

@kadamwhite
Created March 14, 2014 19:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kadamwhite/9555032 to your computer and use it in GitHub Desktop.
Save kadamwhite/9555032 to your computer and use it in GitHub Desktop.
Grunt task to error out if files are missing
var _ = require('lodash');
module.exports = function(grunt) {
grunt.registerMultiTask('check', 'Check for the existence of files', function() {
var filesMissing = false;
// Flatten the nested source arrays -- I used _.flatten, there are other methods
_.flatten( this.data ).forEach(function( filepath ) {
if ( ! grunt.file.exists(filepath) ) {
filesMissing = true;
grunt.log.error( 'Missing File: ' + filepath );
}
});
// Return false to error out:
// remove this if you want to continue even if files are missing
if ( filesMissing ) {
return false;
}
});
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
check: {
source: [
'<%= pkg.gruntConfig.js.dist.default %>',
'<%= pkg.gruntConfig.js.dev.default %>'
]
},
// OR
check: [
'<%= pkg.gruntConfig.js.dist.default %>',
'<%= pkg.gruntConfig.js.dev.default %>'
],
// ....
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment