3 var brewReleases = require('../_common/brew.js');
5 module.exports = function (request) {
6 // So many places to get (incomplete) release info...
9 // - https://downloads.mariadb.org/mariadb/+releases/
10 // - http://archive.mariadb.org/
12 // - https://formulae.brew.sh/api/formula/mariadb@10.3.json
13 // - https://formulae.brew.sh/docs/api/
14 // - https://formulae.brew.sh/formula/mariadb@10.2#default
16 // Note: This could be very fragile due to using the html
17 // as an API. It's pretty rather than minified, but that
18 // doesn't guarantee that it's meant as a consumable API.
21 var promises = [mariaReleases(), brewReleases(request, 'mariadb')];
22 return Promise.all(promises).then(function (many) {
23 var versions = many[0];
26 var all = { download: '', releases: [] };
32 // (and mac, wedged-in from Homebrew)
33 versions.forEach(function (ver) {
42 'http://archive.mariadb.org/mariadb-{{ v }}/bintar-linux-x86_64/mariadb-{{ v }}-linux-x86_64.tar.gz'.replace(
55 'http://archive.mariadb.org/mariadb-{{ v }}/bintar-linux-x86/mariadb-{{ v }}-linux-x86.tar.gz'.replace(
70 'http://archive.mariadb.org/mariadb-{{ v }}/winx64-packages/mariadb-{{ v }}-winx64.zip'.replace(
83 'http://archive.mariadb.org/mariadb-{{ v }}/win32-packages/mariadb-{{ v }}-win32.zip'.replace(
89 // Note: versions are sorted most-recent first.
90 // We just assume that the brew version is most recent stable
91 // ... but we can't really know for sure
94 brews.some(function (brew, i) {
95 // 10.3 => ^10.2(\b|\.)
96 var reBrewVer = new RegExp(
97 '^' + brew.version.replace(/\./, '\\.') + '(\\b|\\.)',
100 if (!ver.version.match(reBrewVer)) {
104 version: ver.version,
106 channel: ver.channel,
110 download: brew.download.replace(/{{ v }}/g, ver.version)
112 brews.splice(i, 1); // remove
120 function mariaReleases() {
122 url: 'https://downloads.mariadb.org/mariadb/+releases/',
123 fail: true // https://git.coolaj86.com/coolaj86/request.js/issues/2
125 .then(failOnBadStatus)
126 .then(function (resp) {
127 // fragile, but simple
129 // Make release info go from this:
130 var html = resp.body;
133 // <td><a href="/mariadb/10.0.38/">10.0.38</a></td>
134 // <td>2019-01-31</td>
139 var reLine = /\s*(<(tr|td)[^>]*>)\s*/g;
141 // <tr><tr><td><a href="/mariadb/10.0.38/">10.0.38</a></td><td>2019-01-31</td><td>Stable</td>
142 // </tr><tr><td><a href="/mariadb/10.0.37/">10.0.37</a></td><td>2018-11-01</td><td>Stable</td>
143 // </tr><tr><td><a href="/mariadb/10.0.36/">10.0.36</a></td><td>2018-08-01</td><td>Stable</td>
147 /<tr>.*mariadb\/(10[^\/]+)\/">.*(20\d\d-\d\d-\d\d)<\/td><td>(\w+)<\/td>/;
149 // { "version": "10.0.36", "date": "2018-08-01", "channel": "stable" }
152 .replace(reLine, '$1')
154 .map(function (line) {
155 var m = line.match(reVer);
161 channel: mapChannel(m[3].toLowerCase()),
167 .catch(function (err) {
168 console.error('Error fetching (official) MariaDB versions');
175 function mapChannel(ch) {
176 if ('alpha' === ch) {
183 function failOnBadStatus(resp) {
184 if (resp.statusCode >= 400) {
185 var err = new Error('Non-successful status code: ' + resp.statusCode);
186 err.code = 'ESTATUS';
193 if (module === require.main) {
194 module.exports(require('@root/request')).then(function (all) {
195 console.info('official releases look like:');
196 console.info(JSON.stringify(all.releases.slice(0, 2), null, 2));
197 console.info('Homebrew releases look like:');
201 .filter(function (rel) {
202 return 'macos' === rel.os;