Skip to content

Instantly share code, notes, and snippets.

@ducin
Created April 21, 2016 17:50
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 ducin/eb1c99dd3c70ecb39479710a08932dea to your computer and use it in GitHub Desktop.
Save ducin/eb1c99dd3c70ecb39479710a08932dea to your computer and use it in GitHub Desktop.
use `david` to check available dependency updates
var pkgPath = '<path to package.json file>';
var david = require('david'),
chalk = require('chalk'),
fs = require('fs');
var manifest = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
david.getDependencies(manifest, function (er, deps) {
console.log('\n', chalk.cyan('latest dependencies information for', manifest.name));
listDependencies(deps, 'cyan');
});
david.getDependencies(manifest, { dev: true }, function (er, deps) {
console.log('\n', chalk.cyan('latest devDependencies information for', manifest.name));
listDependencies(deps, 'cyan');
});
david.getUpdatedDependencies(manifest, function (er, deps) {
console.log('\n', chalk.magenta('dependencies with newer versions for', manifest.name));
listDependencies(deps, 'magenta');
});
david.getUpdatedDependencies(manifest, { dev: true }, function (er, deps) {
console.log('\n', chalk.magenta('devDependencies with newer versions for', manifest.name));
listDependencies(deps, 'magenta');
});
david.getUpdatedDependencies(manifest, { stable: true }, function (er, deps) {
console.log('\n', chalk.red('dependencies with newer STABLE versions for', manifest.name));
listDependencies(deps, 'red');
});
david.getUpdatedDependencies(manifest, { dev: true, stable: true }, function (er, deps) {
console.log('\n', chalk.red('devDependencies with newer STABLE versions for', manifest.name));
listDependencies(deps, 'red');
});
function listDependencies(deps, color) {
Object.keys(deps).forEach(function(depName) {
var required = deps[depName].required || '*';
var stable = deps[depName].stable || 'None';
var latest = deps[depName].latest;
var colorF = chalk[color];
console.log(colorF(depName), 'Required:', required, 'Stable:', stable, 'Latest:', latest);
});
}
{
"scripts": {
"start": "node index"
},
"dependencies": {
"chalk": "^1.1.3",
"david": "^7.0.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment