-
Notifications
You must be signed in to change notification settings - Fork 237
/
Copy pathstatic-output.js
107 lines (90 loc) · 4.51 KB
/
static-output.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
'use strict';
const chalk = require('chalk');
const _ = require('lodash');
const table = require('text-table');
const emoji = require('./emoji');
function uppercaseFirstLetter(str) {
return str[0].toUpperCase() + str.substr(1);
}
function render(pkg, currentState) {
const packageName = pkg.moduleName;
const rows = [];
const indent = ' ' + emoji(' ');
const flags = currentState.get('global') ? '--global' : `--save${pkg.devDependency ? '-dev' : ''}`;
const upgradeCommand = `npm install ${flags} ${packageName}@${pkg.latest}`;
const upgradeMessage = `${chalk.green(upgradeCommand)} to go from ${pkg.installed} to ${pkg.latest}`;
// DYLAN: clean this up
const status = _([
pkg.notInstalled && !pkg.removed ? chalk.bgRed.white.bold(emoji(' :worried: ') + ' MISSING! ') + ' Not installed.' : '',
pkg.notInPackageJson ? chalk.bgRed.white.bold(emoji(' :worried: ') + ' PKG ERR! ') + ' Not in the package.json. ' + pkg.notInPackageJson : '',
pkg.pkgError && !pkg.notInstalled ? chalk.bgGreen.white.bold(emoji(' :worried: ') + ' PKG ERR! ') + ' ' + chalk.red(pkg.pkgError.message) : '',
pkg.bump && pkg.easyUpgrade ? [
chalk.bgGreen.white.bold(emoji(' :heart_eyes: ') + ' UPDATE! ') + ' Your local install is out of date. ' + chalk.blue.underline(pkg.homepage || ''),
indent + upgradeMessage
] : '',
pkg.bump && !pkg.easyUpgrade ? [
chalk.white.bold.bgGreen((pkg.bump === 'nonSemver' ? emoji(' :sunglasses: ') + ' new ver! '.toUpperCase() : emoji(' :sunglasses: ') + ' ' + pkg.bump.toUpperCase() + ' UP ')) + ' ' + uppercaseFirstLetter(pkg.bump) + ' update available. ' + chalk.blue.underline(pkg.homepage || ''),
indent + upgradeMessage
] : '',
pkg.unused && !pkg.removed ? [
chalk.black.bold.bgWhite(emoji(' :confused: ') + ' NOTUSED? ') + ` ${chalk.yellow(`Still using ${packageName}?`)}`,
indent + `Depcheck did not find code similar to ${chalk.green(`require('${packageName}')`)} or ${chalk.green(`import from '${packageName}'`)}.`,
indent + `Check your code before removing as depcheck isn't able to foresee all ways dependencies can be used.`,
indent + `Use ${chalk.green('--skip-unused')} to skip this check.`,
indent + `To remove this package: ${chalk.green(`npm uninstall --save${pkg.devDependency ? '-dev' : ''} ${packageName}`)} or add ${chalk.green(`--remove-unused`)} option for auto removing unused dependencies.`
] : '',
pkg.removed ? [
chalk.bgGreen.white.bold(emoji(' :thumbsup: ') + ' RM UNUSED ') + `The package was removed as unused.`,
indent + `Don't use ${chalk.green('--remove-unused')} or add ${chalk.green('--skip-unused')} option to skip this check.`
] : '',
pkg.mismatch && !pkg.bump ? chalk.bgRed.yellow.bold(emoji(' :interrobang: ') + ' MISMATCH ') + ' Installed version does not match package.json. ' + pkg.installed + ' ≠ ' + pkg.packageJson : '',
pkg.regError ? chalk.bgRed.white.bold(emoji(' :no_entry: ') + ' NPM ERR! ') + ' ' + chalk.red(pkg.regError) : ''
])
.flatten()
.compact()
.valueOf();
if (!status.length) {
return false;
}
rows.push(
[
chalk.yellow(packageName),
status.shift()
]);
while (status.length) {
rows.push([
' ',
status.shift()
]);
}
rows.push(
[
' '
]);
return rows;
}
function outputConsole(currentState) {
const packages = currentState.get('packages');
const rows = packages.reduce((acc, pkg) => {
return acc.concat(render(pkg, currentState));
}, [])
.filter(Boolean);
if (rows.length) {
const renderedTable = table(rows, {
stringLength: s => chalk.stripColor(s).length
});
console.log('');
console.log(renderedTable);
console.log(`Use ${chalk.green(`npm-check -${currentState.get('global') ? 'g' : ''}u`)} for interactive update.`);
const removeError = currentState.get('removeUnusedError');
if (removeError) {
console.log("Auto removing dependencies have crashed with following error: ",
chalk.red(removeError));
}
process.exitCode = 1;
} else {
console.log(`${emoji(':heart: ')}Your modules look ${chalk.bold('amazing')}. Keep up the great work.${emoji(' :heart:')}`);
process.exitCode = 0;
}
}
module.exports = outputConsole;