From 83a791865d415e9c4caf9d87c46b118998144030 Mon Sep 17 00:00:00 2001 From: Krzysztof Magiera Date: Tue, 14 Jan 2025 13:19:05 +0100 Subject: [PATCH] Add missing file that should've been included in #891 --- .../scripts/mergeThirdPartyNotices.mjs | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 packages/vscode-extension/scripts/mergeThirdPartyNotices.mjs diff --git a/packages/vscode-extension/scripts/mergeThirdPartyNotices.mjs b/packages/vscode-extension/scripts/mergeThirdPartyNotices.mjs new file mode 100644 index 000000000..725e973f6 --- /dev/null +++ b/packages/vscode-extension/scripts/mergeThirdPartyNotices.mjs @@ -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));