-
Notifications
You must be signed in to change notification settings - Fork 12
/
list-builds.js
46 lines (36 loc) · 1.03 KB
/
list-builds.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
'use strict'
const jsonist = require('jsonist')
const indexUrl = 'https://nodejs.org/download/{type}/index.json'
function listBuilds (type, config, callback) {
const url = indexUrl.replace(/\{type\}/, `${config.urlTypePrefix || ''}${type}`)
jsonist.get(url, (err, data) => {
if (err) {
return callback(err)
}
if (!data || !Array.isArray(data) || !data.length) {
return callback(new Error(`no builds for "${type}"`))
}
data = data.map((d) => {
const m = d.version.match(/(?:nightly|v8-canary)(20\d\d)(\d\d)(\d\d)([0-9a-f]{7,})/)
const date = new Date((m && `${m[1]}-${m[2]}-${m[3]}`) || d.date)
const commit = m && m[4]
if (m && commit) {
return {
version: d.version,
date: date,
commit: commit
}
}
})
callback(null, data)
})
}
module.exports = listBuilds
if (require.main === module) {
listBuilds(process.argv[2] || 'nightly', (err, data) => {
if (err) {
throw err
}
console.log('data', data)
})
}