diff --git a/lib/file-writer.js b/lib/file-writer.js index 817bb8b..7e43bf6 100644 --- a/lib/file-writer.js +++ b/lib/file-writer.js @@ -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(); diff --git a/lib/license-dependency.js b/lib/license-dependency.js index 993c138..0a456f9 100644 --- a/lib/license-dependency.js +++ b/lib/license-dependency.js @@ -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: { @@ -94,6 +95,8 @@ const entry = (info, dependency, options) => { }] } }; + + return licenseData; }; // This function will populate the licenses array with @@ -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)); }