This repository was archived by the owner on Sep 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
executable file
·71 lines (66 loc) · 2.08 KB
/
build.js
File metadata and controls
executable file
·71 lines (66 loc) · 2.08 KB
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
#!/usr/bin/env node
const assert = require('assert')
const fs = require('fs')
const https = require('https')
// Download JSON file from spdx.org.
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)
let parsed
try {
parsed = JSON.parse(buffer)
} catch (error) {
assert.ifError(error)
}
// Read list version from JSON.
const version = parsed.licenseListVersion
assert.strictEqual(typeof version, 'string')
// Read identifiers from JSON.
const licenses = parsed.licenses
assert.strictEqual(Array.isArray(licenses), true)
const index = []
licenses.forEach(object => {
const id = object.licenseId
assert.strictEqual(typeof id, 'string')
if (object.isDeprecatedLicenseId) {
index.push({ id, deprecated: true })
} else {
index.push({ id, deprecated: false })
}
})
// Sort identifier lists.
index.sort((a, b) => a.id - b.id)
// Write JSON files.
let todo = 2
function finishTask (error) {
assert.ifError(error)
if (--todo === 0) process.exit(0)
}
function writeFile (path, data) {
fs.writeFile(
path, JSON.stringify(data, null, 2) + '\n',
finishTask
)
}
writeFile('index.json', index)
fs.readFile('package.json', (error, buffer) => {
assert.ifError(error)
let parsed
try {
parsed = JSON.parse(buffer)
} catch (error) {
assert.ifError(error)
}
const patch = process.env.PATCH || '0'
parsed.version = version + '.' + patch
writeFile('package.json', parsed)
})
})
})
.end()