-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcollect-licenses.js
114 lines (97 loc) · 3.03 KB
/
collect-licenses.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// Credits for the original script go to Josu Goñi
// Modified for
// https://stackoverflow.com/a/70266175
// Licensed under CC BY-SA 4.0
// https://creativecommons.org/licenses/by-sa/4.0/
import FS from 'fs';
const packageJSON = JSON.parse(FS.readFileSync('package.json').toString());
const dependencies = packageJSON.dependencies;
const LICENSE_FILE_NAMES = [
'LICENSE',
'license',
'LICENSE.md',
'LICENSE.txt',
'ThirdPartyNoticeText.txt'
];
// Add ability to specify custom license URLs for packages that don't include any files
const CUSTOM_LICENSE_URLS = [
{
name: "@iconify-json/iconoir",
url: "https://raw.githubusercontent.com/iconoir-icons/iconoir/main/LICENSE",
},
{
name: "@iconify-json/ph",
url: "https://raw.githubusercontent.com/phosphor-icons/core/main/LICENSE",
},
{
name: "@iconify-icons/ph",
url: "https://raw.githubusercontent.com/phosphor-icons/core/main/LICENSE",
},
{
name: "@iconify-json/ri",
url: "https://raw.githubusercontent.com/Remix-Design/RemixIcon/master/License",
},
{
name: "@iconify-icons/ri",
url: "https://raw.githubusercontent.com/Remix-Design/RemixIcon/master/License",
},
{
name: "rehype-stringify",
url: "https://raw.githubusercontent.com/rehypejs/rehype/main/license"
},
// {
// name: "alpinejs",
// url: "https://github.com/alpinejs/alpine/raw/main/LICENSE.md",
// },
// {
// name: "@alpinejs/collapse",
// url: "https://github.com/alpinejs/alpine/raw/main/LICENSE.md"
// }
]
let FAILED_TO_FIND_LICENSES = false;
let libraries = Object.keys(dependencies);
// libraries.forEach(async key => {
for (const key of libraries) {
console.log();
console.log("==========")
console.log();
console.log(key);
console.log();
const path = 'node_modules/' + key;
// let license = null;
// Modify to handle multiple licenses, such as third party notice files + own licenses
let licenses = [];
LICENSE_FILE_NAMES.forEach(name => {
try {
licenses.push(FS.readFileSync(path + '/' + name).toString());
} catch (e) {}
});
let additional_custom_license = CUSTOM_LICENSE_URLS.find(entry => entry.name == key)
if (additional_custom_license !== undefined) {
const response = await fetch(additional_custom_license.url);
licenses.push(await response.text())
}
// if (licenses.length === 0) {
// try {
// let libraryPackageFile = FS.readFileSync(path + '/package.json').toString();
// // You can try to get the license from the package.json here
// } catch (e) {}
// }
if (licenses.length > 0) {
// console.log(license);
licenses.forEach(licenseEntry => console.log(licenseEntry));
} else {
console.log('License not found');
FAILED_TO_FIND_LICENSES = true;
try { // This is to help update the LICENSE_NAMES before re-run it
let files = FS.readdirSync(path);
files.forEach(file => {
console.log(file);
});
} catch (e) {}
}
// });
}
if (FAILED_TO_FIND_LICENSES) {
console.error('WARN: The license for some dependencies was not found!');
}