Skip to content

Commit

Permalink
Fix codestyle and whitespaces
Browse files Browse the repository at this point in the history
Also took care of failing tests
  • Loading branch information
Philipp Tusch committed Jul 28, 2015
1 parent dd173ba commit 38a2bd2
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 91 deletions.
2 changes: 1 addition & 1 deletion bin/license-checker
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ args.customFormat = checker.parseJson(args.customPath);

checker.init(args, function(json) {

console.log(args.customFormat);
console.log(args.customFormat);

var formattedOutput = '';
if (args.json) {
Expand Down
38 changes: 19 additions & 19 deletions lib/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,32 @@ http://yuilibrary.com/license/
*/

var nopt = require('nopt'),
chalk = require('chalk'),
known = {
json: Boolean,
csv: Boolean,
markdown: Boolean,
out: require('path'),
unknown: Boolean,
version: Boolean,
color: Boolean,
start: String,
help: Boolean,
customPath: require('path'),
customFormat: { }
},
shorts = {
"v" : ["--version"],
"h" : ["--help"]
};
chalk = require('chalk'),
known = {
json: Boolean,
csv: Boolean,
markdown: Boolean,
out: require('path'),
unknown: Boolean,
version: Boolean,
color: Boolean,
start: String,
help: Boolean,
customPath: require('path'),
customFormat: { }
},
shorts = {
"v" : ["--version"],
"h" : ["--help"]
};

var raw = function (args) {
return nopt(known, shorts, (args || process.argv));
};

var has = function (a) {
var cooked = raw().argv.cooked,
ret = false;
ret = false;

cooked.forEach(function (o) {
if ((o === '--' + a) || (o === '--no-' + a)) {
Expand Down
143 changes: 72 additions & 71 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ var license = require('./license');

var flatten = function(options) {
var moduleInfo = { licenses: UNKNOWN },
json = options.deps,
data = options.data,
key = json.name + '@' + json.version,
colorize = options.color,
licenseData, files = [], licenseFile,
customFormat = options.customFormat;
json = options.deps,
data = options.data,
key = json.name + '@' + json.version,
colorize = options.color,
licenseData, files = [], licenseFile;

if (colorize) {
moduleInfo = { licenses: chalk.bold.red(UNKNOWN) };
Expand Down Expand Up @@ -50,16 +49,18 @@ var flatten = function(options) {
}

//Build custom format output
Object.keys(options.customFormat).forEach(function forEachCallback(item) {
if (json[item]) {
//For now, we only support strings, not JSON objects
if (typeof json[item] === 'string') {
moduleInfo[item] = json[item];
}
} else {
moduleInfo[item] = options.customFormat[item];
}
});
if (options.customFormat !== undefined) {
Object.keys(options.customFormat).forEach(function forEachCallback(item) {
if (json[item]) {
//For now, we only support strings, not JSON objects
if (typeof json[item] === 'string') {
moduleInfo[item] = json[item];
}
} else {
moduleInfo[item] = options.customFormat[item];
}
});
}

licenseData = json.license || json.licenses || undefined;
if (licenseData) {
Expand Down Expand Up @@ -108,7 +109,7 @@ var flatten = function(options) {
if (json.dependencies) {
Object.keys(json.dependencies).forEach(function(name) {
var childDependency = json.dependencies[name],
dependencyId = childDependency.name + '@' + childDependency.version;
dependencyId = childDependency.name + '@' + childDependency.version;
if (options.filter && options.filter(name, childDependency)) {
return;
}
Expand All @@ -132,14 +133,14 @@ exports.init = function(options, callback) {

read(options.start, { dev: true }, function(err, json) {
var data = flatten({
deps: json,
data: {},
color: options.color,
filter: options.filter,
customFormat: options.customFormat
}),
colorize = options.color,
sorted = {};
deps: json,
data: {},
color: options.color,
filter: options.filter,
customFormat: options.customFormat
}),
colorize = options.color,
sorted = {};
Object.keys(data).sort().forEach(function(item) {
if (options.unknown) {
if (data[item].licenses && data[item].licenses !== UNKNOWN) {
Expand Down Expand Up @@ -169,88 +170,88 @@ exports.asTree = function(sorted) {
};

exports.asCSV = function(sorted, customFormat) {
var text = [ ];
var text = [ ], textArr = [ ], lineArr = [ ];

if (Object.keys(customFormat).length > 0) {
var textArr = [ ];
textArr.push('"module name"');
textArr = [ ];
textArr.push('"module name"');

Object.keys(customFormat).forEach(function forEachCallback(item) {
textArr.push('"' + item + '"');
});
Object.keys(customFormat).forEach(function forEachCallback(item) {
textArr.push('"' + item + '"');
});

text.push(textArr.join(','));
text.push(textArr.join(','));
} else {
text.push(['"module name"','"license"','"repository"'].join(','));
text.push(['"module name"','"license"','"repository"'].join(','));
}

Object.keys(sorted).forEach(function(key) {
var module = sorted[key],
line = '';
var lineArr = [ ];
line = '';
lineArr = [ ];

//Grab the custom keys from the custom format
if (Object.keys(customFormat).length > 0) {
lineArr.push('"' + key + '"');
Object.keys(customFormat).forEach(function forEachCallback(item) {
//Grab the custom keys from the custom format
if (Object.keys(customFormat).length > 0) {
lineArr.push('"' + key + '"');
Object.keys(customFormat).forEach(function forEachCallback(item) {
lineArr.push('"' + module[item] + '"');
});
line = lineArr.join(',');
} else {
line = [
'"' + key + '"',
'"' + (module.licenses || '') + '"',
'"' + (module.repository || '') + '"'
].join(',');
}
text.push(line);
});
line = lineArr.join(',');
} else {
line = [
'"' + key + '"',
'"' + (module.licenses || '') + '"',
'"' + (module.repository || '') + '"'
].join(',');
}
text.push(line);
});

return text.join('\n');
};

/**
* Exports data as markdown (*.md) file which has it's own syntax.
* @method
* @param {JSON} sorted The sorted JSON data from all packages.
* @param {JSON} customFormat The custom format with information about the needed keys.
* @return {String} The returning plain text.
*/
* Exports data as markdown (*.md) file which has it's own syntax.
* @method
* @param {JSON} sorted The sorted JSON data from all packages.
* @param {JSON} customFormat The custom format with information about the needed keys.
* @return {String} The returning plain text.
*/
exports.asMarkDown = function(sorted, customFormat) {

var text = [];
if (Object.keys(customFormat).length > 0) {

Object.keys(sorted).forEach(function sortedCallback(sortedItem) {
Object.keys(sorted).forEach(function sortedCallback(sortedItem) {

text.push(' - **[' + sortedItem + '](' + sorted[sortedItem].repository + ')**');
Object.keys(customFormat).forEach(function customCallback(customItem) {
text.push(' - **[' + sortedItem + '](' + sorted[sortedItem].repository + ')**');
Object.keys(customFormat).forEach(function customCallback(customItem) {

text.push(' - ' + customItem + ': ' + sorted[sortedItem][customItem]);
text.push(' - ' + customItem + ': ' + sorted[sortedItem][customItem]);
});
});
});

text = text.join('\n');
text = text.join('\n');
} else {

Object.keys(sorted).forEach(function(key) {
Object.keys(sorted).forEach(function(key) {

var module = sorted[key];
text.push('[' + key + '](' + module.repository + ') - ' + module.licenses);
});
var module = sorted[key];
text.push('[' + key + '](' + module.repository + ') - ' + module.licenses);
});

text = text.join('\n');
text = text.join('\n');
}

return text;
};

exports.parseJson = function(jsonPath) {
if (typeof jsonPath !== 'string') {
return {};
}
if (typeof jsonPath !== 'string') {
return {};
}

var jsonData = fs.readFileSync(jsonPath, {encoding: 'utf8'});
var jsonData = fs.readFileSync(jsonPath, {encoding: 'utf8'});

return JSON.parse(jsonData);
return JSON.parse(jsonData);
};

0 comments on commit 38a2bd2

Please sign in to comment.