Skip to content

Commit 2eb1d21

Browse files
authored
scripts: update app sorting in generate-index-json to use latest release date (#106)
1 parent 010c15c commit 2eb1d21

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

scripts/generate-index-json.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,24 @@ async function generateIndex(orgIndices: ParsedOrgFile[]): Promise<AppIndex> {
3434
appIndex.apps.push(...apps);
3535
}
3636

37-
appIndex.apps = appIndex.apps.sort((a, b) => a.name < b.name ? -1 : 1);
37+
appIndex.apps = appIndex.apps.sort((a, b) => {
38+
// Find the most recent release date for each app
39+
const getLatestDate = (app: Application) => {
40+
if (!Array.isArray(app.releases) || app.releases.length === 0) return new Date(0).toISOString();
41+
// Find the max date from the releases
42+
const initialDate = app.releases[0]?.date || new Date(0).toISOString();
43+
return app.releases.reduce((latest: string, curr: Application['releases'][number]) => {
44+
if (!curr.date) return latest;
45+
return (new Date(curr.date) > new Date(latest) ? curr.date : latest);
46+
}, initialDate);
47+
};
48+
49+
const dateA = getLatestDate(a);
50+
const dateB = getLatestDate(b);
51+
52+
// Sort descending (most recent first)
53+
return new Date(dateB).getTime() - new Date(dateA).getTime();
54+
});
3855

3956
return appIndex;
4057
}

0 commit comments

Comments
 (0)