-
Notifications
You must be signed in to change notification settings - Fork 11
/
generate_foss_list.js
37 lines (33 loc) · 1.44 KB
/
generate_foss_list.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const package = require('./package.json');
require("fix-esm").register();
const got = require('got');
let licences_Def = {
"MIT": "http://www.opensource.org/licenses/MIT",
"ISC": "http://www.opensource.org/licenses/ISC",
"Apache-2.0": "http://www.opensource.org/licenses/Apache-2.0",
"BSD 3-Clause": "https://opensource.org/licenses/BSD-3-Clause"
};
let promises = [];
Object.keys(package.dependencies).forEach((key) => {
if (key === "got") return;
promises.push(got("https://registry.npmjs.org/" + key.toLowerCase())
.then(function (data) {
let currentPackage = require("./node_modules/" + key + "/package.json");
let version = currentPackage.version;
var dataParsed = JSON.parse(data.body);
let name = dataParsed.name;
let license = dataParsed.license || "MIT";
let homepage = dataParsed.homepage || dataParsed.repository.url.replace('git:', 'https:').replace('.git', '');
let licenseUrl = licences_Def[license] || "https://opensource.org/licenses";
let result = name + " | [www](" + homepage + ") | [" + license + "](" + licenseUrl + ") | NO | " + version;
return Promise.resolve(result);
}));
});
Promise.all(promises).then((values) => {
values.sort((valueA, valueB) => {
if (valueA < valueB) return -1;
if (valueA > valueB) return 1;
return 0;
});
console.log(values.join("\r\n"));
});