Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports = async function licenseTask(app, options, project) {
const licenseFile = project.file('LICENSE');
const licenseCode = (project.get('license') || 'unlicensed').toLowerCase();
if (licenseCode === 'unlicensed') {
// Package is unlicensed.
if (licenseFile.exists()) {
licenseFile.unlink();
}
app.logger.warn('no license found', project.localPath);
return;
}
// Package actually is licensed.
const list = require('spdx-license-list/spdx-full.json');
const licenses = Object.keys(list).reduce((obj, key) => {
obj[key.toLowerCase()] = list[key].licenseText;
return obj;
}, {});
if (!(licenseCode in licenses)) {
// We don't have a license document for the specified license code.
app.logger.error('invalid license', project.localPath);
return;
}
// Replace placeholders with actual values.
const text = licenses[licenseCode]
.replace(//gi, (new Date()).getFullYear())
.replace(/<(owner|author|copyright\sholders)>/gi, () => {
if (project.get('author')) {
return project.get('author');