-
Notifications
You must be signed in to change notification settings - Fork 20
/
build.js
37 lines (35 loc) · 884 Bytes
/
build.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 https = require('https');
const fs = require('fs');
https.get('https://spdx.org/licenses/licenses.json', response => {
const chunks = [];
response
.on('data', chunk => {
chunks.push(chunk);
})
.once('error', error => {
throw error;
})
.once('end', () => {
const buffer = Buffer.concat(chunks);
const data = JSON.parse(buffer);
const {licenses} = data;
const index = [];
const deprecated = [];
for (const {licenseId: id, isDeprecatedLicenseId: isDeprecated} of licenses) {
if (isDeprecated) {
if (!id.endsWith('+')) {
deprecated.push(id);
}
} else {
index.push(id);
}
}
index.sort();
deprecated.sort();
fs.writeFileSync('index.json', stringify(index, null, 2));
fs.writeFileSync('deprecated.json', stringify(deprecated, null, 2));
});
});
function stringify(data) {
return `${JSON.stringify(data, null, '\t')}\n`;
}