fetch-node-release
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -5,2 +5,9 @@ # Change Log | ||
<a name="1.0.1"></a> | ||
## [1.0.1](https://github.com/panva/fetch-node-release/compare/v1.0.0...v1.0.1) (2018-10-24) | ||
### Refactor | ||
* now uses https://nodejs.org/dist/index.json instead ([08cb2e2](https://github.com/panva/fetch-node-release/commit/08cb2e2)) | ||
<a name="1.0.0"></a> | ||
@@ -7,0 +14,0 @@ # 1.0.0 (2018-10-24) |
@@ -8,43 +8,30 @@ 'use strict' | ||
function fetchRelease (keyword) { | ||
let location | ||
if (STABLE.has(keyword)) { | ||
location = Promise.resolve('https://nodejs.org/dist/latest/') | ||
} else if (/lts\/([a-z]+)/.test(keyword)) { | ||
location = Promise.resolve(`https://nodejs.org/dist/latest-${RegExp.$1}/`) | ||
} else if (keyword === 'lts/*') { | ||
location = got('https://nodejs.org/dist/').then(function (res) { | ||
const lts = res.body | ||
.split('\n') | ||
.map(function (line) { | ||
return /latest-([a-z]+)\//.test(line) && RegExp.$1 | ||
}) | ||
.filter(Boolean) | ||
.sort() | ||
.reverse() | ||
return `https://nodejs.org/dist/latest-${lts[0]}/` | ||
}) | ||
} else { | ||
location = Promise.reject(new TypeError('invalid keyword')) | ||
} | ||
return location.then(function (url) { | ||
return got(url) | ||
if (STABLE.has(keyword) || /lts\/([a-z]+)/.test(keyword) || keyword === 'lts/*') { | ||
return got('https://nodejs.org/dist/index.json', { json: true }) | ||
.then(function (res) { | ||
const match = res.body | ||
.split('\n') | ||
.find(function (line) { | ||
return /<\/a>/.test(line) && /([0-9]+\.[0-9]+\.[0-9]+)/.test(line) | ||
let match | ||
if (STABLE.has(keyword)) { | ||
// match the latest release | ||
match = res.body[0] | ||
} else if (/lts\/([a-z]+)/.test(keyword)) { | ||
// match the first matching lts codename | ||
match = res.body.find(function (release) { | ||
return typeof release.lts === 'string' && release.lts.toLowerCase() === RegExp.$1 | ||
}) | ||
} else if (keyword === 'lts/*') { | ||
// match the first lts in the array | ||
match = res.body.find(function (release) { | ||
return typeof release.lts === 'string' | ||
}) | ||
} | ||
const release = match && RegExp.$1 | ||
if (!release) { | ||
if (match) { | ||
return match.version.slice(1) | ||
} else { | ||
throw new Error(`no release found for ${keyword}`) | ||
} | ||
return release | ||
}) | ||
}) | ||
} else { | ||
return Promise.reject(new TypeError('invalid keyword')) | ||
} | ||
} | ||
@@ -51,0 +38,0 @@ |
{ | ||
"name": "fetch-node-release", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Fetch latest Node.js release version by keyword such as \"stable\", \"lts/carbon\" or \"lts/*\"", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
4792
34