Skip to content

Commit 3086185

Browse files
committed
replace custom logic with node-version-data package
1 parent 6b9515a commit 3086185

File tree

3 files changed

+2960
-325
lines changed

3 files changed

+2960
-325
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"metalsmith-serve": "0.0.3",
4242
"metalsmith-stylus": "1.0.0",
4343
"ncp": "2.0.0",
44+
"node-version-data": "1.0.0",
4445
"octonode": "0.7.4",
4546
"require-dir": "0.3.0",
4647
"semver": "5.0.3",

scripts/load-versions.js

Lines changed: 7 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -3,68 +3,21 @@
33
'use strict'
44

55
const fs = require('fs')
6-
const semver = require('semver')
7-
const map = require('map-async')
8-
const https = require('https')
6+
const nodeVersionData = require('node-version-data')
97

10-
function loadVersions (callback) {
11-
map(
12-
[ 'https://nodejs.org/dist/index.json', 'https://iojs.org/dist/index.json' ],
13-
download,
14-
function (err, versions) {
15-
if (err) { return callback(err) }
16-
versions = munge(versions)
17-
callback(null, versions)
18-
}
19-
)
20-
}
21-
22-
function download (url, cb) {
23-
let data = ''
24-
https.get(url, function (res) {
25-
res.on('data', function (chunk) { data += chunk })
26-
res.on('end', function () {
27-
try {
28-
cb(null, JSON.parse(data))
29-
} catch (e) {
30-
return cb(e)
31-
}
32-
})
33-
}).on('error', function (e) {
34-
console.error('Error downloading file from %s: %s', url, e.message)
35-
cb(e)
36-
})
37-
}
38-
39-
function munge (versions) {
40-
versions[0].forEach(function (v) {
41-
v.url = 'https://nodejs.org/dist/' + v.version + '/'
42-
v.name = 'Node.js'
43-
})
44-
versions[1].forEach(function (v) {
45-
v.url = 'https://iojs.org/dist/' + v.version + '/'
46-
v.name = 'io.js'
47-
})
48-
49-
let allVersions = versions[0].concat(versions[1])
50-
51-
allVersions.sort(function (a, b) {
52-
return semver.compare(b.version, a.version)
53-
})
54-
55-
return allVersions
56-
}
57-
58-
module.exports = loadVersions
8+
module.exports = nodeVersionData
599

6010
if (require.main === module) {
61-
loadVersions(function (err, versions) {
11+
nodeVersionData((err, versions) => {
6212
if (err) {
6313
console.error('Aborting due to download error from node or iojs')
6414
console.error(err.stack)
6515
return process.exit(1)
6616
}
6717

68-
fs.writeFileSync(__dirname + '/../source/versions.json', JSON.stringify(versions, null, 2))
18+
fs.writeFileSync(
19+
__dirname + '/../source/versions.json'
20+
, JSON.stringify(versions, null, 2)
21+
)
6922
})
7023
}

0 commit comments

Comments
 (0)