function findLicense()

in generate-third-party-notice.js [43:63]


function findLicense(packagePath) {
    log.info(`Finding the license for '${packagePath}'`);
    const children = fs.readdirSync(packagePath);
    const licenseNames = [
        'LICENSE',
        'LICENSE.md',
        'LICENSE.txt',
        'LICENSE-MIT.txt'
    ].map(x => x.toLowerCase());
    const candidates = children.filter(x => licenseNames.includes(x.toLowerCase()));
    if (!candidates || candidates.length === 0) {
        log.warning(`Could not find a license for ${packagePath}`);
        return null;
    } else {
        //console.log(JSON.stringify(candidates));
        if (candidates.length > 1) {
            log.warning(`Found multiple license files for ${packagePath}: ${candidates.join(', ')}`);
        }
        return trace('Found license', path.join(packagePath, candidates[0]));
    }
}