Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@shellscape
Created December 13, 2016 22:42
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 shellscape/637c4192f1a14cd31e9aa854e92907ca to your computer and use it in GitHub Desktop.
Save shellscape/637c4192f1a14cd31e9aa854e92907ca to your computer and use it in GitHub Desktop.
'use strict';
const chalk = require('chalk');
const stringLength = require('string-length');
const table = require('text-table');
const tableOptions = { stringLength: stringLength };
class Reporter {
log (file) {
if (!('david' in file)) {
throw new Error(`[${ pkg.name }] Dependencies not found.`);
}
console.log('\n', chalk.underline(file.path), '\n');
let types = Object.keys(file.david)
.filter(type => Object.keys(file.david[type]).length > 0);
if (!types.length) {
console.log(chalk.green('\n All dependencies up to date.\n'));
}
else {
types.forEach(type => {
let deps = file.david[type],
rows = [
[ ` ${type}`, 'package.json', 'stable', 'latest' ]
.map(cell => chalk.grey(cell))
];
for (let name in deps) {
let dependency = deps[name],
requiredVersion = chalk.red(dependency.required || '*'),
stableVersion = chalk.green(dependency.stable || '*'),
latestVersion = chalk.yellow(dependency.latest || '*'),
pkgName = chalk.blue(name);
rows.push([ ` ${pkgName}`, requiredVersion, stableVersion, latestVersion ]);
}
console.log(table(rows, tableOptions));
});
}
}
}
module.exports = { Reporter: Reporter };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment