bigbuffet-rw/scripts/lib/changelog.ts

32 lines
893 B
TypeScript
Raw Normal View History

2022-12-28 17:38:19 -08:00
import fs from 'fs';
import { join } from 'path';
2023-01-08 14:34:50 -08:00
/** Parse the changelog into an object. */
const parseChangelog = (changelog: string): Record<string, string> => {
2022-12-28 17:38:19 -08:00
const result: Record<string, string> = {};
let currentVersion: string;
changelog.split('\n').forEach(line => {
const match = line.match(/^## \[([\d.]+)\](?: - [\d-]+)?$/);
if (match) {
currentVersion = match[1];
} else if (currentVersion) {
result[currentVersion] = (result[currentVersion] || '') + line + '\n';
}
});
return result;
};
2022-12-28 17:38:19 -08:00
2023-01-08 14:34:50 -08:00
/** Get Markdown changes for a specific version. */
const getChanges = (version: string) => {
2023-01-08 14:34:50 -08:00
version = version.replace('v', '');
const content = fs.readFileSync(join(__dirname, '..', '..', 'CHANGELOG.md'), 'utf8');
const parsed = parseChangelog(content);
return (parsed[version] || '').trim();
};
2022-12-28 17:38:19 -08:00
2023-01-08 14:34:50 -08:00
export {
parseChangelog,
getChanges,
};