release stats script

This commit is contained in:
antelle 2017-05-21 13:40:47 +02:00
parent d796dd36e1
commit 6626fde49f
2 changed files with 149 additions and 0 deletions

87
util/release-stats.html Normal file
View File

@ -0,0 +1,87 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>KeeWeb Release Stats</title>
<!--<script src="http://code.highcharts.com/highcharts.js"></script>-->
<script src="https://code.highcharts.com/stock/highstock.js"></script>
<script>
const xhr = new XMLHttpRequest();
xhr.responseType = 'json';
xhr.open('GET', 'release-stats.json', true);
xhr.addEventListener('load', () => {
drawChart(xhr.response);
});
xhr.send();
function drawChart(data) {
Highcharts.chart('chart-size', {
title: {
text: 'KeeWeb Code Size'
},
chart: {
zoomType: 'x'
},
xAxis: {
type: 'datetime'
},
yAxis: {
title: {
text: 'Bytes'
}
},
legend: {
enabled: true
},
plotOptions: {
area: {
marker: {
radius: 2
},
lineWidth: 1,
states: {
hover: {
lineWidth: 1
}
},
threshold: null
},
series: {
stacking: 'normal'
}
},
tooltip: {
split: true
},
series: [{
type: 'area',
name: 'Favicons',
data: data.map(item => [item.dt, item.size.favicons])
}, {
type: 'area',
name: 'CSS',
data: data.map(item => [item.dt, item.size.css])
}, {
type: 'area',
name: 'JS-Vendor',
data: data.map(item => [item.dt, item.size.jsVendor])
}, {
type: 'area',
name: 'JS-App',
data: data.map(item => [item.dt, item.size.jsApp])
}, {
type: 'flags',
shape: 'squarepin',
y: -55,
showInLegend: false,
stacking: false,
data: data.filter(item => /.0$/.test(item.tag)).map(item => ({ x: item.dt, title: item.tag }))
}]
});
}
</script>
</head>
<body>
<div id="chart-size" style="height: 90vh;"></div>
</body>
</html>

62
util/release-stats.js Normal file
View File

@ -0,0 +1,62 @@
/* eslint-disable no-console */
const fs = require('fs');
const path = require('path');
const ps = require('child_process');
const cwd = path.resolve(__dirname, 'keeweb');
if (!fs.existsSync(cwd)) {
console.log('Cloning...');
ps.spawnSync('git', ['clone', 'git@github.com:keeweb/keeweb.git', '-b', 'gh-pages'], {cwd: __dirname});
}
console.log('Getting log...');
ps.spawnSync('git', ['reset', '--hard'], {cwd});
ps.spawnSync('git', ['checkout', 'gh-pages'], {cwd});
const gitLog = ps.spawnSync('git', ['log'], {cwd}).stdout.toString();
console.log('Gettings tags...');
const tags = ps.spawnSync('git', ['tag', '-l'], {cwd})
.stdout.toString()
.split('\n')
.filter(tag => tag);
console.log(`Found ${tags.length} tags`);
const stats = [];
for (const tag of tags) {
console.log(`Tag: ${tag}`);
const match = new RegExp(`commit (\\w+)\\nAuthor[^\\n]+\\nDate:\\s*([^\\n]+)\\n\\n\\s*${tag}`).exec(gitLog);
const [, rev, date] = match;
const dt = new Date(date).getTime();
const checkoutRes = ps.spawnSync('git', ['checkout', rev], {cwd});
if (checkoutRes.error) {
console.error('Checkout error', checkoutRes.error);
throw 'Checkout error';
}
const size = {};
const data = fs.readFileSync(path.join(cwd, 'index.html'));
const html = data.toString();
size.total = data.byteLength;
size.favicons = /<link rel="shortcut icon"[^>]+>/.exec(html)[0].length +
(/<link rel="apple-touch-icon"[^>]+>/.exec(html) || [''])[0].length;
size.css = /<style>.*?<\/style>/.exec(html)[0].length;
size.jsVendor = /<\/style><script>[\s\S]*?<\/script>/.exec(html)[0].length;
size.jsApp = /<\/script><script>[\s\S]*?<\/script>/.exec(html)[0].length;
stats.push({ tag, rev, dt, size });
}
// https://api.github.com/repos/keeweb/keeweb/issues?state=all&sort=created&direction=asc
console.log('Saving stats...');
fs.writeFileSync(path.resolve(__dirname, 'release-stats.json'), JSON.stringify(stats, null, 2));
console.log('Done');