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) {
41 download: 'http://archive.mariadb.org/mariadb-{{ v }}/bintar-linux-x86_64/mariadb-{{ v }}-linux-x86_64.tar.gz'.replace(
53 download: 'http://archive.mariadb.org/mariadb-{{ v }}/bintar-linux-x86/mariadb-{{ v }}-linux-x86.tar.gz'.replace(
67 download: 'http://archive.mariadb.org/mariadb-{{ v }}/winx64-packages/mariadb-{{ v }}-winx64.zip'.replace(
79 download: 'http://archive.mariadb.org/mariadb-{{ v }}/win32-packages/mariadb-{{ v }}-win32.zip'.replace(
85 // Note: versions are sorted most-recent first.
86 // We just assume that the brew version is most recent stable
87 // ... but we can't really know for sure
90 brews.some(function (brew, i) {
91 // 10.3 => ^10.2(\b|\.)
92 var reBrewVer = new RegExp(
93 '^' + brew.version.replace(/\./, '\\.') + '(\\b|\\.)',
96 if (!ver.version.match(reBrewVer)) {
100 version: ver.version,
102 channel: ver.channel,
106 download: brew.download.replace(/{{ v }}/g, ver.version)
108 brews.splice(i, 1); // remove
116 function mariaReleases() {
118 url: 'https://downloads.mariadb.org/mariadb/+releases/',
119 fail: true // https://git.coolaj86.com/coolaj86/request.js/issues/2
121 .then(failOnBadStatus)
122 .then(function (resp) {
123 // fragile, but simple
125 // Make release info go from this:
126 var html = resp.body;
129 // <td><a href="/mariadb/10.0.38/">10.0.38</a></td>
130 // <td>2019-01-31</td>
135 var reLine = /\s*(<(tr|td)[^>]*>)\s*/g;
137 // <tr><tr><td><a href="/mariadb/10.0.38/">10.0.38</a></td><td>2019-01-31</td><td>Stable</td>
138 // </tr><tr><td><a href="/mariadb/10.0.37/">10.0.37</a></td><td>2018-11-01</td><td>Stable</td>
139 // </tr><tr><td><a href="/mariadb/10.0.36/">10.0.36</a></td><td>2018-08-01</td><td>Stable</td>
142 var reVer = /<tr>.*mariadb\/(10[^\/]+)\/">.*(20\d\d-\d\d-\d\d)<\/td><td>(\w+)<\/td>/;
144 // { "version": "10.0.36", "date": "2018-08-01", "channel": "stable" }
147 .replace(reLine, '$1')
149 .map(function (line) {
150 var m = line.match(reVer);
156 channel: mapChannel(m[3].toLowerCase()),
162 .catch(function (err) {
163 console.error('Error fetching (official) MariaDB versions');
170 function mapChannel(ch) {
171 if ('alpha' === ch) {
178 function failOnBadStatus(resp) {
179 if (resp.statusCode >= 400) {
180 var err = new Error('Non-successful status code: ' + resp.statusCode);
181 err.code = 'ESTATUS';
188 if (module === require.main) {
189 module.exports(require('@root/request')).then(function (all) {
190 console.info('official releases look like:');
191 console.info(JSON.stringify(all.releases.slice(0, 2), null, 2));
192 console.info('Homebrew releases look like:');
196 .filter(function (rel) {
197 return 'macos' === rel.os;