Created
December 13, 2016 22:42
-
-
Save shellscape/637c4192f1a14cd31e9aa854e92907ca to your computer and use it in GitHub Desktop.
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
'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