-
Notifications
You must be signed in to change notification settings - Fork 19
/
latest.js
58 lines (54 loc) · 1.66 KB
/
latest.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
const assert = require('assert');
// Download JSON file from spdx.org.
require('https').request('https://spdx.org/licenses/licenses.json')
.once('response', response => {
assert.strictEqual(response.statusCode, 200);
const chunks = [];
response
.on('data', chunk => {
chunks.push(chunk);
})
.once('error', error => {
assert.ifError(error);
})
.once('end', () => {
const buffer = Buffer.concat(chunks);
const spdxJSON = JSON.parse(buffer);
const listVersion = spdxJSON.licenseListVersion;
console.log(`License List Version: ${listVersion}`);
const identifiers = [];
const deprecated = [];
spdxJSON.licenses.forEach(object => {
const id = object.licenseId;
if (id.endsWith('+')) {
return;
}
if (object.isDeprecatedLicenseId) {
deprecated.push(id);
} else {
identifiers.push(id);
}
});
identifiers.sort();
deprecated.sort();
const indexJSON = require('./index');
const deprecatedJSON = require('./deprecated');
identifiers.forEach(identifier => {
assert(indexJSON.includes(identifier), `Missing: ${identifier}`);
});
indexJSON.forEach(identifier => {
assert(identifiers.includes(identifier), `Extra: ${identifier}`);
});
assert.deepStrictEqual(indexJSON, identifiers, 'identifiers');
console.log('index.json is up to date.');
deprecated.forEach(identifier => {
assert(deprecatedJSON.includes(identifier), `Missing Deprecated: ${identifier}`);
});
deprecatedJSON.forEach(identifier => {
assert(deprecated.includes(identifier), `Extra Deprecated: ${identifier}`);
});
assert.deepStrictEqual(deprecatedJSON, deprecated, 'deprecated');
console.log('deprecated.json is up to date.');
});
})
.end();