2024-03-26 08:24:55 +00:00
|
|
|
/// @ts-check
|
2026-04-16 07:09:40 +00:00
|
|
|
import * as fs from 'node:fs';
|
2024-03-26 08:24:55 +00:00
|
|
|
import path from 'node:path';
|
|
|
|
|
import { fileURLToPath } from 'node:url';
|
2026-04-16 07:09:40 +00:00
|
|
|
import { XMLParser } from 'fast-xml-parser';
|
2024-03-26 08:24:55 +00:00
|
|
|
|
|
|
|
|
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 [];
|
2024-03-26 08:24:55 +00:00
|
|
|
}
|
|
|
|
|
|
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'] ?? [];
|
|
|
|
|
});
|
2024-03-26 08:24:55 +00:00
|
|
|
|
2026-04-16 07:09:40 +00:00
|
|
|
const changelogRecords = [];
|
2025-02-17 10:42:01 +00:00
|
|
|
|
2026-04-16 07:09:40 +00:00
|
|
|
for (const data of feed) {
|
|
|
|
|
if (data.title && data.pubDate && data.link) {
|
2024-03-26 08:24:55 +00:00
|
|
|
changelogRecords.push({
|
2026-04-16 07:09:40 +00:00
|
|
|
date: new Date(data.pubDate).toISOString().split('T')[0],
|
|
|
|
|
href: data.link,
|
2024-03-26 08:24:55 +00:00
|
|
|
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}`);
|