diff --git a/build.js b/build.js index a1b2d52..e40c3e3 100644 --- a/build.js +++ b/build.js @@ -1,7 +1,8 @@ var https = require('https') -var URL = 'https://spdx.org/licenses/licenses.json' +var SPDX_URL = 'https://spdx.org/licenses/licenses.json' +var ids = {} -https.get(URL, function (response) { +https.get(SPDX_URL, function (response) { var chunks = [] response .on('data', function (chunk) { @@ -14,7 +15,7 @@ https.get(URL, function (response) { .once('end', function () { var body = Buffer.concat(chunks) var parsed = JSON.parse(body) - var ids = parsed.licenses + ids.spdx = parsed.licenses .filter(function (license) { return license.isOsiApproved }) @@ -25,6 +26,41 @@ https.get(URL, function (response) { return license.licenseId }) .sort() - console.log(JSON.stringify(ids, null, 2)) + if (ids.osi) compare() }) }) + +var OSI_URL = 'https://opensource.org/api/license' +https.get(OSI_URL, function (response) { + var chunks = [] + response + .on('data', function (chunk) { + chunks.push(chunk) + }) + .once('error', function (error) { + console.error(error) + process.exit(1) + }) + .once('end', function () { + var body = Buffer.concat(chunks) + var parsed = JSON.parse(body) + ids.osi = parsed + .map(function (license) { + return license.id + }) + .sort() + if (ids.spdx) compare() + }) +}) + +function compare () { + console.log(ids) + var combined = [] + ;[ids.spdx, ids.osi].forEach(function (list) { + list.forEach(function (id) { + if (combined.indexOf(id) === -1) combined.push(id) + }) + }) + combined.sort() + console.log(JSON.stringify(combined, null, 2)) +}