Skip to content

Commit

Permalink
Add missing file that should've been included in #891
Browse files Browse the repository at this point in the history
  • Loading branch information
kmagiera committed Jan 14, 2025
1 parent 7dc0384 commit 83a7918
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions packages/vscode-extension/scripts/mergeThirdPartyNotices.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import fs from "fs";

// Usage: node mergeThirdPartyNotices.js file1.json file2.json file3.json output.json
const inputFileNames = process.argv.slice(2, -1);
const outputFileName = process.argv[process.argv.length - 1];

const UNACCEPTABLE_LICENSES = ["GPL", "AGPL", "LGPL", "NGPL"];

function readInputs() {
return Promise.resolve(inputFileNames.map((fileName) => JSON.parse(fs.readFileSync(fileName))));
}

function mergeLibraries(dataArrays) {
const mergedResults = [];

dataArrays.forEach((data) => {
data.third_party_libraries.forEach((library) => {
if (
!mergedResults.find(
(lib) =>
lib.package_name === library.package_name &&
lib.package_version === library.package_version
)
) {
mergedResults.push(library);
}
});
});

return {
root_name: "radon-ide",
third_party_libraries: mergedResults,
};
}

function writeMergedData(data) {
const jsonData = JSON.stringify(data, null, 2); // pretty print with 2 spaces indention
return fs.promises.writeFile(outputFileName, jsonData, "utf8");
}

function verifyLicenses(data) {
const licenses = new Set();
// collect all license names
data.third_party_libraries.forEach((library) => {
library.licenses.forEach((license) => licenses.add(license.license));
});

// verify whether some of the licenses contain unacceptable license names
const unacceptableLicenses = Array.from(licenses).filter((license) =>
UNACCEPTABLE_LICENSES.some((unacceptableLicense) => license.includes(unacceptableLicense))
);
if (unacceptableLicenses.length > 0) {
console.error("Found unacceptable licenses:", unacceptableLicenses);
process.exit(1);
}

console.log("Licenses used:", Array.from(licenses).join(", "));
return data;
}

readInputs()
.then(mergeLibraries)
.then(verifyLicenses)
.then(writeMergedData)
.then(() => console.log("Finished writing merged third party libraries to:", outputFileName))
.catch((err) => console.error("Error processing files:", err));

0 comments on commit 83a7918

Please sign in to comment.