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

Include Copyright Message in Output #156

Merged
merged 8 commits into from
May 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions customFormatExample.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "",
"description": "",
"licenses": "",
"copyright": "",
"licenseFile": "none",
"licenseText": "none",
"licenseModified": "no"
Expand Down
32 changes: 31 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ var flatten = function(options) {
}

if (index === 0) {
// Treat the file with the highest precedense as licenseFile
// Treat the file with the highest precedence as licenseFile
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haha, 🇬🇧 vs 🇺🇸 fight

/*istanbul ignore else*/
if (include("licenseFile")) {
moduleInfo.licenseFile = options.basePath ? path.relative(options.basePath, licenseFile) : licenseFile;
Expand All @@ -195,6 +195,36 @@ var flatten = function(options) {
moduleInfo.licenseText = content.replace(/"/g, '\'').replace(/\r?\n|\r/g, " ").trim();
}
}

if(include('copyright') && options.customFormat) {
if (!content) {
content = fs.readFileSync(licenseFile, { encoding: 'utf8' });
}

var linesWithCopyright = content
.replace(/\r\n/g, '\n')
.split('\n\n')
.filter(function selectCopyRightStatements(value) {
return value.startsWith('opyright', 1) && // include copyright statements
!value.startsWith('opyright notice', 1) && // exclude lines from from license text
!value.startsWith('opyright and related rights', 1);
})
.filter(function removeDuplicates(value, index, list) {
return index === 0 || value !== list[0];
});

if(linesWithCopyright.length > 0) {
moduleInfo.copyright = linesWithCopyright[0]
.replace(/\n/g, '. ')
.trim();
}

// Mark files with multiple copyright statements. This might be
// an indicator to take a closer look at the LICENSE file.
if(linesWithCopyright.length > 1) {
moduleInfo.copyright += '*';
}
}
}
}
});
Expand Down
22 changes: 22 additions & 0 deletions tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,28 @@ describe('main tests', function() {
});
});

describe('handle copytight statement', function(){

it('should output copyright statements when configured in custom format', function(done) {
checker.init({
start: path.join(__dirname, '../'),
customFormat: {
copyright: '', // specify custom format
email: false,
licenseFile: false,
licenseText: false,
publisher: false
}
}, function(err, output) {
assert(output.hasOwnProperty('abbrev@1.0.9'), 'Check if the expected package still exists.');
assert.equal(output['abbrev@1.0.9'].copyright, 'Copyright (c) Isaac Z. Schlueter and Contributors');
done();
});

});

});

describe('should only list UNKNOWN or guessed licenses successful', function() {
var output;
before(function(done) {
Expand Down