Skip to content

Commit

Permalink
colorize
Browse files Browse the repository at this point in the history
  • Loading branch information
couchand committed Jul 30, 2014
1 parent c14ef79 commit 40ca4da
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
5 changes: 5 additions & 0 deletions lib/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ http://yuilibrary.com/license/
*/

var nopt = require('nopt'),
chalk = require('chalk'),
known = {
json: require('path'),
csv: require('path'),
unknown: Boolean,
version: Boolean,
color: Boolean,
start: String,
help: Boolean
},
Expand Down Expand Up @@ -45,6 +47,9 @@ var setDefaults = function(parsed) {
if (parsed === undefined) {
parsed = clean();
}
if (parsed.color === undefined) {
parsed.color = chalk.supportsColor;
}
parsed.start = parsed.start || process.cwd();

return parsed;
Expand Down
20 changes: 14 additions & 6 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,22 @@ var data = {};
var fs = require('fs');
var path = require('path');
var read = require('read-installed');
var chalk = require('chalk');
var treeify = require('treeify');
var license = require('./license');

var flatten = function(json) {
var moduleInfo = {licenses: UNKNOWN},
licenseData, files;
var flatten = function(json, colorize) {
var moduleInfo, licenseData, files, key;

data[json.name + '@' + json.version] = moduleInfo;
if (colorize) {
moduleInfo = {licenses: chalk.bold.red(UNKNOWN)};
key = chalk.bold.blue(json.name) + chalk.dim('@') + chalk.green(json.version);
} else {
moduleInfo = {licenses: UNKNOWN};
key = json.name + '@' + json.version;
}

data[key] = moduleInfo;

if (json.repository) {
if (typeof json.repository === 'object' && typeof json.repository.url === 'string') {
Expand Down Expand Up @@ -72,7 +80,7 @@ var flatten = function(json) {
if (data[dependencyId]) { // already exists
return;
}
flatten(childDependency);
flatten(childDependency, colorize);
});
}
};
Expand All @@ -82,7 +90,7 @@ exports.init = function(options, callback) {
console.log('scanning' , options.start);

read(options.start, function(err, json) {
flatten(json);
flatten(json, options.color);
var sorted = {};
Object.keys(data).sort().forEach(function(item) {
if (options.unknown) {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"mkdirp": "^0.3.5",
"treeify": "^1.0.1",
"nopt": "^2.2.0",
"read-installed": "^1.0.0"
"read-installed": "^1.0.0",
"chalk": "~0.5.1"
},
"devDependencies": {
"yui-lint": "~0.1.1",
Expand Down

0 comments on commit 40ca4da

Please sign in to comment.