human/server/changelog.js

56 lines
1.6 KiB
JavaScript
Raw Normal View History

2020-10-16 21:21:56 +02:00
const fs = require('fs');
const path = require('path');
const dayjs = require('dayjs');
const simpleGit = require('simple-git/promise');
const logger = require('@vladmandic/pilogger');
2020-11-08 15:56:02 +01:00
const app = require('../package.json');
2020-10-16 21:21:56 +02:00
const git = simpleGit();
2021-03-03 15:59:04 +01:00
let text = `# ${app.name}
2020-10-16 21:21:56 +02:00
Version: **${app.version}**
Description: **${app.description}**
Author: **${app.author}**
License: **${app.license}** </LICENSE>
Repository: **<${app.repository.url}>**
## Changelog
`;
async function update(f) {
2021-02-08 17:39:09 +01:00
const gitLog = await git.log();
2021-01-03 16:23:45 +01:00
// @ts-ignore
2021-02-08 17:39:09 +01:00
const log = gitLog.all.sort((a, b) => (new Date(b.date).getTime() - new Date(a.date).getTime()));
2020-10-16 21:21:56 +02:00
let previous = '';
2021-03-03 15:59:04 +01:00
const headings = [];
2020-10-16 21:21:56 +02:00
for (const l of log) {
const msg = l.message.toLowerCase();
2021-03-03 15:59:04 +01:00
if ((l.refs !== '') || msg.match(/^[0-99].[0-99].[0-99]/)) {
2020-10-16 21:21:56 +02:00
const dt = dayjs(l.date).format('YYYY/MM/DD');
2021-03-03 15:59:04 +01:00
let ver = msg.match(/[0-99].[0-99].[0-99]/) ? msg : l.refs;
ver = ver.replace('tag: v', '').replace('tag: ', 'release: ').split(',')[0];
const heading = `\n### **${ver}** ${dt} ${l.author_email}\n\n`;
if (!headings.includes(heading) && !ver.startsWith('tag')) {
headings.push(heading);
text += heading;
}
2020-10-16 21:21:56 +02:00
} else if ((msg.length > 2) && !msg.startsWith('update') && (previous !== msg)) {
previous = msg;
text += `- ${msg}\n`;
}
}
const name = path.join(__dirname, f);
fs.writeFileSync(name, text);
2021-03-14 04:31:09 +01:00
logger.info('Update Change log:', [name]);
2020-10-16 21:21:56 +02:00
}
2021-03-14 04:31:09 +01:00
if (require.main === module) {
update('../CHANGELOG.md');
} else {
exports.update = update;
2020-10-16 21:21:56 +02:00
}