mirror of
https://github.com/webinstall/webi-installers.git
synced 2026-08-19 12:06:25 +00:00
ref(fetch) replace request in _common/brew.js
This commit is contained in:
+15
-24
@@ -1,27 +1,28 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Gets a releases from 'brew'.
|
||||
* Gets releases from 'brew'.
|
||||
*
|
||||
* @param request
|
||||
* @param {null} _
|
||||
* @param {string} formula
|
||||
* @returns {PromiseLike<any> | Promise<any>}
|
||||
*/
|
||||
function getDistributables(request, formula) {
|
||||
function getDistributables(_, formula) {
|
||||
if (!formula) {
|
||||
return Promise.reject('missing formula for brew');
|
||||
}
|
||||
return request({
|
||||
url: 'https://formulae.brew.sh/api/formula/' + formula + '.json',
|
||||
fail: true, // https://git.coolaj86.com/coolaj86/request.js/issues/2
|
||||
json: true,
|
||||
})
|
||||
.then(failOnBadStatus)
|
||||
return fetch('https://formulae.brew.sh/api/formula/' + formula + '.json')
|
||||
.then(function (resp) {
|
||||
var ver = resp.body.versions.stable;
|
||||
if (!resp.ok) {
|
||||
throw new Error(`HTTP error! Status: ${resp.status}`);
|
||||
}
|
||||
return resp.json(); // Parse JSON response
|
||||
})
|
||||
.then(function (body) {
|
||||
var ver = body.versions.stable;
|
||||
var dl = (
|
||||
resp.body.bottle.stable.files.high_sierra ||
|
||||
resp.body.bottle.stable.files.catalina
|
||||
body.bottle.stable.files.high_sierra ||
|
||||
body.bottle.stable.files.catalina
|
||||
).url.replace(new RegExp(ver.replace(/\./g, '\\.'), 'g'), '{{ v }}');
|
||||
return [
|
||||
{
|
||||
@@ -29,7 +30,7 @@ function getDistributables(request, formula) {
|
||||
download: dl.replace(/{{ v }}/g, ver),
|
||||
},
|
||||
].concat(
|
||||
resp.body.versioned_formulae.map(function (f) {
|
||||
body.versioned_formulae.map(function (f) {
|
||||
var ver = f.replace(/.*@/, '');
|
||||
return {
|
||||
version: ver,
|
||||
@@ -45,20 +46,10 @@ function getDistributables(request, formula) {
|
||||
});
|
||||
}
|
||||
|
||||
function failOnBadStatus(resp) {
|
||||
if (resp.statusCode >= 400) {
|
||||
var err = new Error('Non-successful status code: ' + resp.statusCode);
|
||||
err.code = 'ESTATUS';
|
||||
err.response = resp;
|
||||
throw err;
|
||||
}
|
||||
return resp;
|
||||
}
|
||||
|
||||
module.exports = getDistributables;
|
||||
|
||||
if (module === require.main) {
|
||||
getDistributables(require('@root/request'), 'mariadb').then(function (all) {
|
||||
getDistributables(null, 'mariadb').then(function (all) {
|
||||
console.info(JSON.stringify(all, null, 2));
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user