Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: fix version list creation for dropdown #1391

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 16 additions & 17 deletions tools/bin/gen_versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,26 @@ function main () {
// go through directory that contains all languages
util.listdirsSync(rootDir).forEach(function (langId) {
const langPath = path.join(rootDir, langId);
let versionNames = util.listdirsSync(langPath);

// Remove dev version for semver sort. We'll add it back later.
versionNames.splice(versionNames.indexOf('dev'), 1);
// Get all directories, excluding dev, and make sure it is in lexicographically order.
const versionNames = util.listdirsSync(langPath)
.filter(dir => dir !== 'dev')
.sort((a, b) => a.localeCompare(b));

// semver doesn't like a value of 10.x, so we'll coerce the values into proper 10.0.0,
// and store a map to easily convert map our sorted away back to our desired text.
const coercionMap = {};
versionNames = versionNames.map((v) => {
const coerced = semver.coerce(v).toString();
coercionMap[coerced] = v;
return coerced;
// Semver cant sort invalid values. E.g. 10.x or 12.x-2025.01
// Will create an array of objects containing the coerce value (10.0.0) for sorting and
// the original readable name for display.
const versionMap = versionNames.map((readable) => {
const [versionPart] = readable.split('-');
const coerced = semver.coerce(versionPart)?.toString() || versionPart;
return { readable, semantic: coerced };
});

versionNames = semver.sort(versionNames);
const sortedVersions = versionMap.filter(v => semver.valid(v.semantic))
.sort((a, b) => semver.compare(a.semantic, b.semantic))
.map(v => v.readable);

// Now we can restore our desired labelling
versionNames = versionNames.map((v) => coercionMap[v]);

// Finally, don't forget to restore our dev version
versionNames.push('dev');
sortedVersions.push('dev'); // add back dev

// get language ID
const langName = LANGUAGE_MAP[langId];
Expand All @@ -72,7 +71,7 @@ function main () {
// set the language name and the versions it has
config[langId] = {
name: langName,
versions: versionNames
versions: sortedVersions
};
});

Expand Down
Loading