Created
March 1, 2013 19:52
-
-
Save cowboy/5067251 to your computer and use it in GitHub Desktop.
Grunt: Test that package.json dependencies were installed correctly.
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
grunt.registerTask('deps', 'Test that package.json dependencies were installed correctly.', function() { | |
var pkg = grunt.file.readJSON('package.json'); | |
var total = 0; | |
['dependencies', 'devDependencies'].forEach(function(key) { | |
var deps = pkg[key]; | |
if (!deps) { return; } | |
grunt.verbose.subhead(key); | |
Object.keys(deps).forEach(function(name) { | |
total++; | |
var msg = 'Checking "' + name + '" dependency...'; | |
grunt.verbose.write(msg); | |
try { | |
require(name); | |
grunt.verbose.ok(); | |
} catch(err) { | |
grunt.verbose.or.write(msg); | |
grunt.log.error().error(err.message); | |
} | |
}); | |
}); | |
if (this.errorCount > 0) { | |
grunt.fail.fatal('Errors were encountered. Did you "npm install" first?'); | |
} else { | |
grunt.verbose.writeln(); | |
grunt.log.ok(total + ' dependencies installed correctly.'); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My grunt-check-modules task just delegates to
npm ls
and checks for an error exit code. Though this is an interesting idea, sincenpm ls
has some bugs.