Created
March 14, 2014 19:31
-
-
Save kadamwhite/9555032 to your computer and use it in GitHub Desktop.
Grunt task to error out if files are missing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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