Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose raw license details #27

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Expose raw license details
  • Loading branch information
jbergknoff-rival committed Jan 3, 2019
commit d1e3dbca060b670740add4635851567f05603307
9 changes: 7 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ module.exports = function checkPath (packageName, basePath, overrides, includeDe
}
}

var licensesRaw = []
var license = 'unknown'
var licenseFilePath

Expand All @@ -242,15 +243,17 @@ module.exports = function checkPath (packageName, basePath, overrides, includeDe
} else if (packageJson.license) {
licenses.push(packageJson.license)
}
license = licenses.map(getJsonLicense).map(formatLicense).join(', ')
licensesRaw = licenses.map(getJsonLicense)
license = licensesRaw.map(formatLicense).join(', ')
} else {
// Look for file with "license" or "copying" in its name
var files = fs.readdirSync(basePath)
files.some(function (name) {
if (/licen[sc]e/i.test(name) || /copying.*/i.test(name)) {
var file = path.join(basePath, name)
if (fs.statSync(file).isFile()) {
license = formatLicense(getFileLicense(file))
licensesRaw = [getFileLicense(file)]
license = formatLicense(licensesRaw[0])
licenseFilePath = file
return true
}
Expand All @@ -265,6 +268,7 @@ module.exports = function checkPath (packageName, basePath, overrides, includeDe
if (fs.statSync(file).isFile()) {
var result = getReadmeLicense(file)
if (result) {
licensesRaw = [result]
license = formatLicense(result)
licenseFilePath = file
return license !== 'nomatch'
Expand Down Expand Up @@ -303,6 +307,7 @@ module.exports = function checkPath (packageName, basePath, overrides, includeDe
name: packageJson.name,
version: packageJson.version,
license: license,
licensesRaw: licensesRaw,
licenseFile: licenseFilePath && path.relative(process.cwd(), licenseFilePath),
deps: dependencies.sort(function (dep1, dep2) { return dep1.name.localeCompare(dep2.name) })
}
Expand Down