Created
November 6, 2016 19:10
-
-
Save grauwoelfchen/d01899aa46c10f079dfdb8833a57df56 to your computer and use it in GitHub Desktop.
extract-license.js.patch
This file contains 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
--- index.js 2016-11-07 03:39:19.000000000 +0900 | |
+++ extract-license.js 2016-11-07 03:40:03.000000000 +0900 | |
@@ -20,15 +20,33 @@ | |
var packagejson = this.readPackageJson(mod); | |
return packagejson; | |
}, | |
+ extractLicense: function(packagejson) { | |
+ var license = packagejson.license; | |
+ // add support license like `{type: '...', url: '...'}` | |
+ if (license && license.type) { | |
+ license = license.type; | |
+ } | |
+ // add support licenses like `[{type: '...', url: '...'}]` | |
+ if (!license) { | |
+ var licenses = packagejson.licenses; | |
+ if (!!licenses && | |
+ licenses.constructor.toString().indexOf('Array') > -1 && | |
+ licenses.length == 1 && | |
+ licenses[0].type) { | |
+ license = licenses[0].type; | |
+ } | |
+ } | |
+ return license; | |
+ }, | |
parseModuleInfo: function(mod) { | |
var packagejson = this.moduleCache[mod]; | |
+ var license = this.extractLicense(packagejson); | |
return { | |
name: mod, | |
url: packagejson.repository && packagejson.repository.url, | |
version: packagejson.version, | |
- license: (packagejson.license && packagejson.license.type) | |
- || packagejson.license, | |
- licenseText: this.getLicenseText(mod, packagejson.license) | |
+ license: license, | |
+ licenseText: this.getLicenseText(mod, license) | |
}; | |
}, | |
findPackageName: function(jsFilePath) { | |
@@ -49,7 +67,8 @@ | |
return false; | |
} | |
var moduleInfo = this.getModuleInfo(mod); | |
- var isMatching = this.pattern.test(moduleInfo.license) || !moduleInfo.license && this.includeUndefined; | |
+ var license = this.extractLicense(moduleInfo); | |
+ var isMatching = this.pattern.test(license) || !license && this.includeUndefined; | |
if (isMatching) { | |
this.moduleCache[mod] = moduleInfo; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment