async function groupByLicense()

in generate-attribution/generate-attribution-file.js [471:500]


async function groupByLicense(dependencies) {
    const uniqLicenses = {};
    const sortedDeps = dependencies.sort(sortByModule);
    sortedDeps.forEach(function (dep) {
        const canBeMerged = typesCanBeMergedWithoutCopyRight.indexOf(dep.licenseType) !== -1;
        if (canBeMerged) {
            // If the differnce in content is only the copyright we can merge them into the same group
            const { licenseContent, copyrights } = extractCopyRights(dep.licenseContent);
            dep.copyrights = copyrights;
            dep.licenseContent = licenseContent;
        }

        let uniqueLicense = Object.entries(uniqLicenses)
            .find(([licenseType, { licenseContent }]) => {
                return (canBeMerged && isLicenseFuzzyMatch(dep.licenseContent, licenseContent)) ||
                    (dep.licenseContent === licenseContent)
            });
        let type = uniqueLicense ? uniqueLicense[0] : dep.licenseType;
        if (!uniqueLicense) {
            if (uniqLicenses[type]) {
                // Same license type but different content, jsut add module name to type to factor in for sorting later
                type = `${dep.licenseType}+${dep.module}`
            }
            uniqLicenses[type] = { licenseContent: dep.licenseContent, deps: [] };
        }
        uniqLicenses[type].deps.push(dep);
    });

    return uniqLicenses;
}