@@ -4,6 +4,11 @@ import * as fs from "fs";
44import * as path from "path" ;
55import docsConfig from "../docs-config" ;
66import { Downloads , Release , Binary } from "@/downloads-metadata-types" ;
7+ import {
8+ DownloadJSON ,
9+ DownloadRelease ,
10+ DownloadFile ,
11+ } from "@/download-json-types" ;
712import { compareFullVersion , filterUnique , majorMinor } from "./utils" ;
813
914const OUTDIR = "./generated" ;
@@ -22,6 +27,8 @@ const downloads: Downloads = {
2227 releases : [ ] ,
2328} ;
2429
30+ const downloadJSON : DownloadJSON = { } ;
31+
2532const getBinaries = ( r : OctokitRelease ) => {
2633 const binaries = r . assets
2734 . filter (
@@ -155,6 +162,33 @@ for (const repoName of docsConfig.downloads.repos) {
155162 ) ,
156163 } ) ;
157164
165+ // Build the machine-readable download.json entries for this repo.
166+ // shownReleases is sorted newest first, so the first non-prerelease is the
167+ // latest stable release.
168+ const latestStableID = shownReleases . find ( ( r ) => ! r . prerelease ) ?. id ;
169+
170+ downloadJSON [ repoName ] = shownReleases . map (
171+ ( r ) : DownloadRelease => ( {
172+ version : r . tag_name ,
173+ stable : ! r . prerelease ,
174+ latest : r . id === latestStableID ,
175+ lts :
176+ docsConfig . ltsVersions [ repoName ] ?. includes ( majorMinor ( r . tag_name ) ) ??
177+ false ,
178+ files : getBinaries ( r ) . map (
179+ ( b ) : DownloadFile => ( {
180+ url : b . url ,
181+ os : b . os ,
182+ arch : b . arch ,
183+ version : r . tag_name ,
184+ sha256 : b . checksum ,
185+ size : b . sizeBytes ,
186+ kind : "archive" ,
187+ } )
188+ ) ,
189+ } )
190+ ) ;
191+
158192 console . groupEnd ( ) ;
159193}
160194
@@ -181,3 +215,9 @@ fs.writeFileSync(
181215 path . join ( OUTDIR , "downloads-metadata.json" ) ,
182216 JSON . stringify ( downloads , null , 2 )
183217) ;
218+
219+ console . log ( `Writing download.json to ${ OUTDIR } /download.json` ) ;
220+ fs . writeFileSync (
221+ path . join ( OUTDIR , "download.json" ) ,
222+ JSON . stringify ( downloadJSON , null , 2 )
223+ ) ;
0 commit comments