Skip to content

Commit

Permalink
Adding license checks in the LICENSE file (and variations)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmand3l committed Feb 21, 2014
1 parent 64170de commit 72a6f24
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
21 changes: 17 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ http://yuilibrary.com/license/

var UNKNOWN = 'UNKNOWN';
var data = {};
var fs = require('fs');
var path = require('path');
var read = require('read-installed');
var treeify = require('treeify');
var license = require('./license');
Expand All @@ -17,9 +19,8 @@ var flatten = function(json) {

data[json.name + '@' + json.version] = moduleInfo;


if (json.repository) {
if (typeof json.repository === 'object') {
if (typeof json.repository === 'object' && typeof json.repository.url === 'string') {
moduleInfo.repository = json.repository.url.replace('git://github.com', 'https://github.com').replace('.git', '');
}
}
Expand All @@ -44,9 +45,21 @@ var flatten = function(json) {
} else if (typeof licenseData === 'string') {
moduleInfo.licenses = licenseData;
}
} else if (json.readme){
moduleInfo.licenses = license(json.readme) || UNKNOWN;
} else if (license(json.readme)) {
moduleInfo.licenses = license(json.readme);
} else {
var files = fs.readdirSync(json.path);
files.forEach(function(filename) {
if (filename.indexOf('LICENSE') > -1) {
moduleInfo.licenses = license(fs.readFileSync(path.join(json.path, filename), {encoding: 'utf8'}));
}
});

if (moduleInfo.licenses == UNKNOWN) {
console.log(json.path);
}
}

if (json.dependencies) {
Object.keys(json.dependencies).forEach(function(name) {
var childDependency = json.dependencies[name],
Expand Down
22 changes: 21 additions & 1 deletion lib/license.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
var MIT_LICENSE = ["Permission is hereby granted, free of charge, to any person obtaining",
"a copy of this software and associated documentation files (the",
"'Software'), to deal in the Software without restriction, including",
"without limitation the rights to use, copy, modify, merge, publish,",
"distribute, sublicense, and/or sell copies of the Software, and to",
"permit persons to whom the Software is furnished to do so, subject to",
"the following conditions:",
"",
"The above copyright notice and this permission notice shall be",
"included in all copies or substantial portions of the Software.",
"",
"THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,",
"EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF",
"MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.",
"IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY",
"CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,",
"TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE",
"SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE."].join('\n');


module.exports = function(str) {
if (str.indexOf('MIT') > -1) {
if (str.indexOf('MIT') > -1 || str.indexOf(MIT_LICENSE) > -1) {
return 'MIT*';
} else if (str.indexOf('BSD') > -1) {
return 'BSD*';
Expand Down

0 comments on commit 72a6f24

Please sign in to comment.