1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-01-11 18:24:43 +02:00
joplin/Tools/build-release-stats.js

154 lines
4.6 KiB
JavaScript
Raw Normal View History

/* eslint-disable require-atomic-updates */
2019-09-19 23:51:18 +02:00
require('app-module-path').addPath(`${__dirname}/../ReactNativeClient`);
2018-03-28 19:41:14 +02:00
const fetch = require('node-fetch');
const fs = require('fs-extra');
Plugins: Added support for content scripts - For now, supports Markdown-it plugins - Also fixed slow rendering of notes in some cases - Simplified how Markdown-It plugins are created and cleaned MdToHtml code commit 89576de2896c99134f25f2a2db25008514cb1315 Merge: c75aa21f 5292fc14 Author: Laurent Cozic <laurent@cozic.net> Date: Wed Oct 21 00:23:00 2020 +0100 Merge branch 'release-1.3' into plugin_content_scripts commit c75aa21ffdc42764d71dc9deadba7a7ef4233995 Author: Laurent Cozic <laurent@cozic.net> Date: Wed Oct 21 00:19:52 2020 +0100 Fixed tests commit 075187729d11a16d385b651cbf1ebb89f14935e0 Author: Laurent Cozic <laurent@cozic.net> Date: Wed Oct 21 00:11:53 2020 +0100 Fixed tests commit 14696b8c651e7afdaf71269bcdbadf0d58d3ef8a Author: Laurent Cozic <laurent@cozic.net> Date: Tue Oct 20 23:27:58 2020 +0100 Fixed slow rendering of note commit 61c09f5bf856481f91b00cfe87ff05596c63d4bc Author: Laurent Cozic <laurent@cozic.net> Date: Tue Oct 20 22:35:21 2020 +0100 Clean up commit 9f7ea7d865a990b3a21cc8c59093390d9db61653 Author: Laurent Cozic <laurent@cozic.net> Date: Tue Oct 20 20:05:31 2020 +0100 Updated doc commit 98bf3bde8d6663f2f91ff965304b4aac00bdd98b Author: Laurent Cozic <laurent@cozic.net> Date: Tue Oct 20 19:56:34 2020 +0100 Finished converting plugins commit fe90d92e01427bd2b38200393713ea28763507a9 Author: Laurent Cozic <laurent@cozic.net> Date: Tue Oct 20 17:52:02 2020 +0100 Simplified how Markdown-It plugins are created commit 47c7b864cbb864d5df79849f27625aecf312df4b Author: Laurent Cozic <laurent@cozic.net> Date: Mon Oct 19 16:40:11 2020 +0100 Clean up rules commit d927a238bb635a4be45f9216d776f7d07cb0a584 Author: Laurent Cozic <laurent@cozic.net> Date: Mon Oct 19 14:29:40 2020 +0100 Fixed tests commit 388a56c5dde4c382e3ee0035791137150adaba1b Author: Laurent Cozic <laurent@cozic.net> Date: Mon Oct 19 14:00:47 2020 +0100 Add support for content scripts
2020-10-21 01:23:55 +02:00
const { dirname } = require('lib/path-utils');
const markdownUtils = require('lib/markdownUtils').default;
2018-03-28 19:41:14 +02:00
const rootDir = dirname(__dirname);
function endsWith(str, suffix) {
return str.indexOf(suffix, str.length - suffix.length) !== -1;
}
function downloadCounts(release) {
const output = {
mac_count: 0,
windows_count: 0,
linux_count: 0,
};
for (let i = 0; i < release.assets.length; i++) {
const asset = release.assets[i];
const n = asset.name;
if (endsWith(n, '-mac.zip') || endsWith(n, '.dmg')) {
output.mac_count += asset.download_count;
} else if (endsWith(n, '.AppImage') || endsWith(n, '.snap')) {
output.linux_count += asset.download_count;
} else if (endsWith(n, '.exe')) {
output.windows_count += asset.download_count;
}
}
output.total_count = output.mac_count + output.linux_count + output.windows_count;
return output;
}
function createChangeLog(releases) {
const output = [];
output.push('# Joplin changelog');
for (let i = 0; i < releases.length; i++) {
const r = releases[i];
const s = [];
2019-09-19 23:51:18 +02:00
s.push(`## ${r.tag_name} - ${r.published_at}`);
2018-03-28 19:41:14 +02:00
s.push('');
const body = r.body.replace(/#(\d+)/g, '[#$1](https://github.com/laurent22/joplin/issues/$1)');
2018-03-28 19:41:14 +02:00
s.push(body);
output.push(s.join('\n'));
}
return output.join('\n\n');
}
async function main() {
const rows = [];
const totals = {
windows_count: 0,
mac_count: 0,
linux_count: 0,
};
2019-01-12 02:01:58 +02:00
const processReleases = (releases) => {
for (let i = 0; i < releases.length; i++) {
const release = releases[i];
if (!release.tag_name.match(/^v\d+\.\d+\.\d+$/)) continue;
if (release.draft) continue;
2019-01-12 02:01:58 +02:00
let row = {};
row = Object.assign(row, downloadCounts(release));
2019-09-19 23:51:18 +02:00
row.tag_name = `[${release.tag_name}](https://github.com/laurent22/joplin/releases/tag/${release.tag_name})`;
2019-01-12 02:01:58 +02:00
row.published_at = release.published_at;
row.body = release.body;
totals.windows_count += row.windows_count;
totals.mac_count += row.mac_count;
totals.linux_count += row.linux_count;
rows.push(row);
}
};
2019-01-12 02:01:58 +02:00
console.info('Build stats: Downloading releases info...');
const baseUrl = 'https://api.github.com/repos/laurent22/joplin/releases?page=';
// const baseUrl = 'http://test.local/releases.json?page='
let pageNum = 1;
while (true) {
2019-09-19 23:51:18 +02:00
console.info(`Build stats: Page ${pageNum}`);
const response = await fetch(`${baseUrl}${pageNum}`);
2019-01-12 02:01:58 +02:00
const releases = await response.json();
if (!releases || !releases.length) break;
processReleases(releases);
pageNum++;
2018-03-28 19:41:14 +02:00
}
const changelogText = createChangeLog(rows);
2019-09-19 23:51:18 +02:00
await fs.writeFile(`${rootDir}/readme/changelog.md`, changelogText);
2018-03-28 19:41:14 +02:00
const grandTotal = totals.windows_count + totals.mac_count + totals.linux_count;
totals.windows_percent = totals.windows_count / grandTotal;
totals.mac_percent = totals.mac_count / grandTotal;
totals.linux_percent = totals.linux_count / grandTotal;
2019-01-12 02:01:58 +02:00
const formatter = new Intl.NumberFormat('en-US', { style: 'decimal' });
2018-03-28 19:41:14 +02:00
const totalsMd = [
2019-01-12 02:01:58 +02:00
{ name: 'Total Windows downloads', value: formatter.format(totals.windows_count) },
{ name: 'Total macOs downloads', value: formatter.format(totals.mac_count) },
{ name: 'Total Linux downloads', value: formatter.format(totals.linux_count) },
2019-09-19 23:51:18 +02:00
{ name: 'Windows %', value: `${Math.round(totals.windows_percent * 100)}%` },
{ name: 'macOS %', value: `${Math.round(totals.mac_percent * 100)}%` },
{ name: 'Linux %', value: `${Math.round(totals.linux_percent * 100)}%` },
2018-03-28 19:41:14 +02:00
];
2019-01-12 02:01:58 +02:00
for (let i = 0; i < rows.length; i++) {
rows[i].mac_count = formatter.format(rows[i].mac_count);
rows[i].windows_count = formatter.format(rows[i].windows_count);
rows[i].linux_count = formatter.format(rows[i].linux_count);
rows[i].total_count = formatter.format(rows[i].total_count);
}
2018-03-28 19:41:14 +02:00
const statsMd = [];
statsMd.push('# Joplin statistics');
statsMd.push(markdownUtils.createMarkdownTable([
2018-03-28 19:41:14 +02:00
{ name: 'name', label: 'Name' },
{ name: 'value', label: 'Value' },
], totalsMd));
statsMd.push(markdownUtils.createMarkdownTable([
2018-03-28 19:41:14 +02:00
{ name: 'tag_name', label: 'Version' },
{ name: 'published_at', label: 'Date' },
{ name: 'windows_count', label: 'Windows' },
{ name: 'mac_count', label: 'macOS' },
{ name: 'linux_count', label: 'Linux' },
{ name: 'total_count', label: 'Total' },
], rows));
const statsText = statsMd.join('\n\n');
2019-09-19 23:51:18 +02:00
await fs.writeFile(`${rootDir}/readme/stats.md`, statsText);
2018-03-28 19:41:14 +02:00
}
main().catch((error) => {
console.error('Fatal error');
console.error(error);
process.exit(1);
});