Skip to content
This repository has been archived by the owner on Sep 13, 2022. It is now read-only.

Commit

Permalink
src: fixes remaining issues from dual license
Browse files Browse the repository at this point in the history
* src: fixes remaining issues from dual license
* fix: lint
  • Loading branch information
helio-frota authored Nov 2, 2017
1 parent c135604 commit a272cad
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
9 changes: 7 additions & 2 deletions lib/file-writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,13 @@ function createHtml (options, xmlObject, dependencyLicenseFiles) {
const finalName = `${dependencyFound.name}_${dependencyFound.type}.txt`;
const link = path.join('./', finalName);
if (notUsingReadmeAsLicenseFile(d.packageName, dependencyLicenseFiles)) {
d.localLicense = require('querystring').escape(link).replace(/%2F/gi, '/');
d.linkLabel = link;
if (dependencyFound.file.includes(dependencyFound.type.split(' ')[0].toUpperCase())) {
d.localLicense = require('querystring').escape(link).replace(/%2F/gi, '/');
d.linkLabel = link;
} else {
d.localLicense = '#';
d.linkLabel = messages.NO_LOCAL_LICENSE_FOUND();
}
} else {
d.localLicense = '#';
d.linkLabel = messages.NO_LOCAL_LICENSE_FOUND();
Expand Down
36 changes: 27 additions & 9 deletions lib/license-dependency.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ const entry = (info, dependency, options) => {
dependencyLicenseFiles.push(createDependencyLicenseFile(dependency.name, canonicalName, info.licenseFile));
unifiedList.init(options);
const url = unifiedList.urlForName(options, canonicalName);
return {

const licenseData = {
packageName: dependency.name,
version: dependency.version,
licenses: {
Expand All @@ -94,6 +95,8 @@ const entry = (info, dependency, options) => {
}]
}
};

return licenseData;
};

// This function will populate the licenses array with
Expand All @@ -108,14 +111,29 @@ function addLicenseEntry (xmlElement, identifier, json, options) {
const nameVersion = versionHandler.fromNpmVersion(identifier);

if (dual.isDual(json[identifier].licenses)) {
// clone the json item.
const first = JSON.parse(JSON.stringify(json[identifier]));
first.licenses = dual.first(first.licenses);
xmlElement.dependencies.dependency.push(entry(first, nameVersion, options));

const last = JSON.parse(JSON.stringify(json[identifier]));
last.licenses = dual.last(json[identifier].licenses);
xmlElement.dependencies.dependency.push(entry(last, nameVersion, options));
if (options.html) {
// clone the json item.
const first = JSON.parse(JSON.stringify(json[identifier]));
first.licenses = dual.first(first.licenses);
const licenseDataFirst = entry(first, nameVersion, options);
xmlElement.dependencies.dependency.push(licenseDataFirst);
const last = JSON.parse(JSON.stringify(json[identifier]));
last.licenses = dual.last(json[identifier].licenses);
const licenseDataLast = entry(last, nameVersion, options);
xmlElement.dependencies.dependency.push(licenseDataLast);
} else {
// clone the json item.
const first = JSON.parse(JSON.stringify(json[identifier]));
first.licenses = dual.first(first.licenses);
const licenseDataFirst = entry(first, nameVersion, options);

const last = JSON.parse(JSON.stringify(json[identifier]));
last.licenses = dual.last(json[identifier].licenses);
const licenseDataLast = entry(last, nameVersion, options);

licenseDataFirst.licenses.license.push(licenseDataLast.licenses.license[0]);
xmlElement.dependencies.dependency.push(licenseDataFirst);
}
} else {
xmlElement.dependencies.dependency.push(entry(json[identifier], nameVersion, options));
}
Expand Down

0 comments on commit a272cad

Please sign in to comment.