console/scripts/generate-changelog.js

50 lines
1.5 KiB
JavaScript
Raw Normal View History

/// @ts-check
2026-04-16 07:09:40 +00:00
import * as fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
2026-04-16 07:09:40 +00:00
import { XMLParser } from 'fast-xml-parser';
const __dirname = fileURLToPath(new URL('.', import.meta.url));
2026-04-16 07:09:40 +00:00
const feedUrl = 'https://the-guild.dev/graphql/hive/feed.xml';
const feed = await fetch(feedUrl).then(async res => {
if (res.status !== 200) {
console.log('skip feed building; feed is unavailable.');
return [];
}
2026-04-16 07:09:40 +00:00
const parser = new XMLParser();
const body = await res.text();
const data = parser.parse(body);
return data['rss']?.['channel']?.['item'] ?? [];
});
2026-04-16 07:09:40 +00:00
const changelogRecords = [];
2026-04-16 07:09:40 +00:00
for (const data of feed) {
if (data.title && data.pubDate && data.link) {
changelogRecords.push({
2026-04-16 07:09:40 +00:00
date: new Date(data.pubDate).toISOString().split('T')[0],
href: data.link,
title: data.title,
description: data.description || '',
});
}
}
// Sort changelogs by date and get the latest 4 records
const latestChangelog = changelogRecords
.sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime())
.slice(0, 4);
// Generate a TypeScript file with the latest changelogs
const outputFilePath = path.join(
__dirname,
'../packages/web/app/src/components/ui/changelog/generated-changelog.ts',
);
const outputContent = `export const latestChangelog = ${JSON.stringify(latestChangelog, null, 2)};\n`;
fs.writeFileSync(outputFilePath, outputContent, 'utf-8');
console.log(`Generated successfully at: ${outputFilePath}`);