1
0
Fork 0
mirror of https://github.com/anyproto/anytype-ts.git synced 2025-06-08 05:57:02 +09:00

JS-1367: added linters for licenses and secrets

This commit is contained in:
Sergey Fuksman 2023-03-01 13:59:25 +02:00
parent b4bd552389
commit 8076e9230e
5 changed files with 430 additions and 14 deletions

57
check-licenses.js Normal file
View file

@ -0,0 +1,57 @@
const fs = require('fs');
const https = require('https');
const remoteConfigUrl = 'https://raw.githubusercontent.com/anytypeio/open/main/compliance/licenses-config.json';
function processLicenses(licenses, allowedLicenses) {
const disallowedPackages = Object.keys(licenses).filter(pkg => {
var pkgLicenses = licenses[pkg].licenses.replace(/[()*]/g, '')
// The hyphenation language patterns are licensed under the LGPL (unless otherwise noted) and copyrighted to their respective creators and maintainers.
// https://github.com/bramstein/hyphenation-patterns
if (pkgLicenses == "UNKNOWN") {
pkgLicenses = "LGPL"
}
// Solutions developed by Anytype are allowed
if (licenses[pkg].publisher == "Anytype") {
return false;
}
if (pkgLicenses.includes(' AND ')) {
const licenseNames = pkgLicenses.split(' AND ')
return !licenseNames.every(name => allowedLicenses.includes(name));
}
const licenseNames = pkgLicenses.split(' OR ');
return !licenseNames.some(name => allowedLicenses.includes(name));
});
if (disallowedPackages.length > 0) {
console.error('The following packages have disallowed licenses:');
disallowedPackages.forEach(pkg => {
console.error(`- ${pkg} (${licenses[pkg].licenses})`);
});
process.exit(1);
} else {
console.info('All packages have allowed licenses.')
}
}
https.get(remoteConfigUrl, (res) => {
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
const config = JSON.parse(data);
const allowedLicenses = config.allowedLicenses;
fs.readFile('./licenses.json', 'utf8', (err, data) => {
if (err) throw err;
const licenses = JSON.parse(data);
processLicenses(licenses, allowedLicenses);
});
});
}).on('error', (err) => {
console.error(`Error retrieving remote configuration: ${err}`);
process.exit(1);
});