-
Notifications
You must be signed in to change notification settings - Fork 11
/
latest.js
executable file
·52 lines (48 loc) · 1.88 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
const assert = require('assert')
const order = require('./order')
// Download JSON file from spdx.org.
require('https').request('https://spdx.org/licenses/exceptions.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.exceptions.forEach(object => {
const id = object.licenseExceptionId
if (object.isDeprecatedLicenseId) {
deprecated.push(id)
} else {
identifiers.push(id)
}
})
identifiers.sort(order)
deprecated.sort(order)
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()