| 1 | import source from '../../../release-notes/releases.json'; |
| 2 | import { readFileSync } from 'node:fs'; |
| 3 | import { resolve } from 'node:path'; |
| 4 | |
| 5 | export type LocalizedText = { en: string; zh: string }; |
| 6 | |
| 7 | export type ReleaseItem = { |
| 8 | title: LocalizedText; |
| 9 | body: LocalizedText; |
| 10 | refs?: number[]; |
| 11 | }; |
| 12 | |
| 13 | export type ReleaseHighlight = ReleaseItem & { |
| 14 | kind: 'new' | 'improved' | 'fixed' | 'security'; |
| 15 | }; |
| 16 | |
| 17 | export type ReleaseGuide = ReleaseItem & { href: string }; |
| 18 | export type ReleaseUpgrade = ReleaseItem & { level: 'info' | 'warning' }; |
| 19 | |
| 20 | export type ReleaseRecord = { |
| 21 | version: string; |
| 22 | releaseId?: string; |
| 23 | baseVersion?: string; |
| 24 | date: string; |
| 25 | channel: 'stable' | 'prerelease'; |
| 26 | status?: 'reviewed' | 'published'; |
| 27 | candidateSha?: string; |
| 28 | previousRelease?: string; |
| 29 | builds?: { cli: string; desktop: string; npm: string }; |
| 30 | title: LocalizedText; |
| 31 | summary: LocalizedText; |
| 32 | surfaces: string[]; |
| 33 | guides: ReleaseGuide[]; |
| 34 | highlights: ReleaseHighlight[]; |
| 35 | changes: { new: ReleaseItem[]; improved: ReleaseItem[]; fixed: ReleaseItem[] }; |
| 36 | upgrade: ReleaseUpgrade[]; |
| 37 | risks: ReleaseItem[]; |
| 38 | contributors: string[]; |
| 39 | links: { github: string; compare: string; download: string }; |
| 40 | }; |
| 41 | |
| 42 | export const releaseCatalog = source as { schemaVersion: number; releases: ReleaseRecord[] }; |
| 43 | export const allReleases = releaseCatalog.releases; |
| 44 | |
| 45 | let publishedIds = new Set<string>(); |
| 46 | try { |
| 47 | const generated = JSON.parse( |
| 48 | readFileSync(resolve(process.cwd(), '.generated/publications.json'), 'utf8'), |
| 49 | ) as { publications?: string[] }; |
| 50 | publishedIds = new Set(generated.publications ?? []); |
| 51 | } catch { |
| 52 | // Before prebuild, preserve legacy entries and fail closed for reviewed |
| 53 | // releases that require a successful all-surface publication marker. |
| 54 | } |
| 55 | |
| 56 | export const publishedReleases = allReleases.filter( |
| 57 | (release) => !release.status || release.status === 'published' || publishedIds.has(release.version), |
| 58 | ); |
| 59 | // Public navigation contains official releases only. Historical prereleases |
| 60 | // remain addressable by their exact version URL for compatibility. |
| 61 | export const releases = publishedReleases.filter((release) => release.channel === 'stable'); |
| 62 | export const stableReleases = releases; |
| 63 | export const previewReleases = publishedReleases.filter((release) => release.channel === 'prerelease'); |
| 64 | export const latestStableRelease = stableReleases[0]; |
| 65 | export const latestPreviewRelease = previewReleases[0]; |
| 66 | export const latestRelease = latestStableRelease; |
| 67 | |
| 68 | export function releasePath(version: string): string { |
| 69 | return `/changelog/v${version}/`; |
| 70 | } |
| 71 |