Skip to content

Commit b6689bd

Browse files
committed
feat: improve guides
1 parent 395a4ca commit b6689bd

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

packages/upgrade/scripts/generate-guide.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ function loadChanges(version, sdk) {
5050
return [];
5151
}
5252

53-
const files = fs.readdirSync(changesDir).filter(f => f.endsWith('.md'));
53+
const files = fs
54+
.readdirSync(changesDir)
55+
.filter(f => f.endsWith('.md'))
56+
.sort();
5457
const changes = [];
5558

5659
for (const file of files) {
@@ -94,11 +97,18 @@ function groupByCategory(changes) {
9497

9598
function getCategoryHeading(category) {
9699
const headings = {
100+
'behavior-change': 'Behavior Change',
97101
breaking: 'Breaking Changes',
102+
deprecation: 'Deprecations',
98103
'deprecation-removal': 'Deprecation Removals',
99104
warning: 'Warnings',
105+
version: 'Version',
100106
};
101-
return headings[category] || category;
107+
if (headings[category]) {
108+
return headings[category];
109+
}
110+
111+
return category.replace(/[-_]+/g, ' ').replace(/\b\w/g, char => char.toUpperCase());
102112
}
103113

104114
function generateMarkdown(sdk, versionConfig, changes) {
@@ -114,18 +124,20 @@ function generateMarkdown(sdk, versionConfig, changes) {
114124
}
115125

116126
const grouped = groupByCategory(changes);
117-
const categoryOrder = ['breaking', 'deprecation-removal', 'warning'];
127+
const categoryOrder = ['breaking', 'deprecation-removal', 'deprecation', 'warning', 'version', 'behavior-change'];
128+
const seenCategories = new Set();
118129

119130
for (const category of categoryOrder) {
120131
const categoryChanges = grouped[category];
121132
if (!categoryChanges || categoryChanges.length === 0) {
122133
continue;
123134
}
124135

136+
seenCategories.add(category);
125137
lines.push(`## ${getCategoryHeading(category)}`);
126138
lines.push('');
127139

128-
for (const change of categoryChanges) {
140+
for (const change of [...categoryChanges].sort((a, b) => a.title.localeCompare(b.title))) {
129141
lines.push(`### ${change.title}`);
130142
lines.push('');
131143
lines.push(change.content);
@@ -134,15 +146,15 @@ function generateMarkdown(sdk, versionConfig, changes) {
134146
}
135147

136148
// Handle any categories not in the predefined order
137-
for (const [category, categoryChanges] of Object.entries(grouped)) {
138-
if (categoryOrder.includes(category)) {
149+
for (const [category, categoryChanges] of Object.entries(grouped).sort(([a], [b]) => a.localeCompare(b))) {
150+
if (seenCategories.has(category)) {
139151
continue;
140152
}
141153

142154
lines.push(`## ${getCategoryHeading(category)}`);
143155
lines.push('');
144156

145-
for (const change of categoryChanges) {
157+
for (const change of [...categoryChanges].sort((a, b) => a.title.localeCompare(b.title))) {
146158
lines.push(`### ${change.title}`);
147159
lines.push('');
148160
lines.push(change.content);

0 commit comments

Comments
 (0)