async function readLicenseContent()

in generate-attribution/generate-attribution-file.js [211:235]


async function readLicenseContent(dep, depLicensesDirPath) {
    const possiblePaths = [];
    const possibleNames = ['LICENSE', 'LICENSE.txt', 'LICENCE.md', 'LICENCE', 'LICENSE.md'];

    if (dep.licensePath !== 'Unknown') {
        const licensePathFromGoLicenseOutput = path.join(depLicensesDirPath, path.basename(dep.licensePath));
        possiblePaths.push(licensePathFromGoLicenseOutput);
    }

    possibleNames.forEach((possibleName) => {
        possiblePaths.push(path.join(depLicensesDirPath, possibleName));
    });

    for (let i = 0; i < possiblePaths.length; i++) {
        const possiblePath = possiblePaths[i];
        try {
            await fsPromises.access(possiblePath);
            const licenseText = await fsPromises.readFile(possiblePath, 'utf8');
            return cleanLicense(path.basename(possiblePath), dep.licenseType, licenseText);
        } catch { }
    }

    console.log('No license file for', dep);
    process.exit(1);
}