Skip to content

Commit

Permalink
Support two operators and/or as multiple common licenses
Browse files Browse the repository at this point in the history
  • Loading branch information
watilde committed Mar 13, 2016
1 parent 3098468 commit 2191806
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 3 deletions.
23 changes: 20 additions & 3 deletions lib/licensify.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@ var props = [
'homepage',
'version'
];
var operators = [
'OR',
'AND'
]

function extractLicense (pkg, summary) {
var name;
var name = '', operator = '', names = [], licenses = [];
switch (typeName(pkg.license)) {
case 'string':
name = pkg.license;
Expand All @@ -35,8 +39,21 @@ function extractLicense (pkg, summary) {
name = pkg.license.type;
break;
}
if (name) {
summary.license = appendUrlToLicense(name);

if (name.match(/^\(.+\)$/)) {
names = name.match(/\(([^)]+)\)/)[1]
operators.forEach(function (o) {
var license = names.split(o);
if (license.length > licenses.length) {
operator = o;
licenses = license;
}
});
summary.license = licenses.map(function (license) {
return appendUrlToLicense(license.trim());
}).filter(function (v) { return !!v; }).join(' ' + operator + ' ');
} else if (name) {
summary.license = appendUrlToLicense(name);
}
}

Expand Down
2 changes: 2 additions & 0 deletions test/test-multiple-common-licenses/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
var and = require('test-conjunctive-and-operator');
var or = require('test-disjunctive-or-operator');

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions test/test-multiple-common-licenses/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "test-multiple-common-licenses",
"description": "",
"version": "0.0.1",
"dependencies": {
"test-conjunctive-and-operator": "./node_modules/test-conjunctive-and-operator",
"test-disjunctive-or-operator": "./node_modules/test-disjunctive-or-operator"
},
"license": "MIT"
}
37 changes: 37 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,3 +341,40 @@ describe('type-less licenses', function () {
});
});
});

describe('multiple common licenses', function () {
var expectedModules = [
'test-conjunctive-and-operator',
'test-disjunctive-or-operator'
];
var expectedOperators = [
'OR', 'AND'
]

describe('should also be in output', function () {
var header;
before(function (done) {
var save = saveFirstChunk();
var b = browserify();
b.add(path.normalize(path.join(__dirname, 'test-multiple-common-licenses', 'index.js')));
b.plugin(licensify);
b.bundle().pipe(save).pipe(es.wait(function(err, data) {
assert(!err);
header = save.firstChunk;
done();
}));
});
expectedModules.forEach(function (moduleName) {
var re = new RegExp(' \* ' + moduleName + '\:$', 'gm');
it('ensure header includes [' + moduleName + ']', function () {
assert(re.test(header));
});
});
expectedOperators.forEach(function (operators) {
var re = new RegExp(operators, 'gm');
it('ensure header includes [' + operators + ']', function () {
assert(re.test(header));
});
});
});
});

0 comments on commit 2191806

Please sign in to comment.