Skip to content

Commit b447d1e

Browse files
committed
sort event groups and events within them alphabetically
1 parent a371149 commit b447d1e

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

scripts/create_app_events_docs_markdown.mjs

+13-3
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ import { markdownTable } from "markdown-table";
66
const discourseGithubRepoBase =
77
"https://github.com/discourse/discourse/blob/main";
88
const emptyValuePlaceholder = "-";
9+
const miscEventGroup = "other events";
910

1011
function extractEventGroup(eventId) {
1112
if (eventId.startsWith("LIGHTBOX")) {
1213
return "lightbox";
1314
} else if (eventId.startsWith("this.composerEventPrefix")) {
1415
return "composer";
1516
} else if (eventId.split(":").length === 1) {
16-
return "other events";
17+
return miscEventGroup;
1718
}
1819
return eventId.split(":")[0];
1920
}
@@ -29,6 +30,7 @@ function createDocumentationForEventGroup(eventGroup, details) {
2930
return (
3031
markdown +
3132
Object.entries(detailsByEventId)
33+
.sort(([a], [b]) => a.localeCompare(b))
3234
.map(([eventId, appEvents]) => {
3335
return createDocumentationForAppEvent(eventId, appEvents);
3436
})
@@ -134,14 +136,14 @@ function consolidateAppEventCalls(appEventCalls) {
134136

135137
// Add to count map that will be used to determine isAlwaysPresent later for the arg
136138
argCountMap[position] ||= 0;
137-
argCountMap[position] ++;
139+
argCountMap[position]++;
138140

139141
if (arg.argType === "object") {
140142
arg.argValue.forEach((nestedArg) => {
141143
const key = `objectArg${position}.${nestedArg.key}`;
142144
// argCountMap[key] += 1;
143145
argCountMap[key] ||= 0;
144-
argCountMap[key] ++;
146+
argCountMap[key]++;
145147
});
146148
}
147149
});
@@ -262,6 +264,14 @@ function createDetailsDocumentation(appEvent, headingLevel = 5) {
262264
}, {});
263265

264266
const docs = Object.keys(groupedByEventGroup)
267+
.sort((a, b) => {
268+
if (a === miscEventGroup) {
269+
return 1;
270+
} else if (b === miscEventGroup) {
271+
return -1;
272+
}
273+
return a.localeCompare(b);
274+
})
265275
.map((eventGroup) => {
266276
return createDocumentationForEventGroup(
267277
eventGroup,

0 commit comments

Comments
 (0)