Skip to content

Commit

Permalink
docs: link to the latest release of the current version (#2856)
Browse files Browse the repository at this point in the history
  • Loading branch information
ST-DDT authored Apr 30, 2024
1 parent b87acb8 commit 13dc420
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 28 deletions.
4 changes: 2 additions & 2 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { apiPages } from './api-pages';
import {
algoliaIndex,
currentVersion,
oldVersions,
versionBannerInfix,
versionLinks,
} from './versions';

type SidebarItem = DefaultTheme.SidebarItem;
Expand Down Expand Up @@ -225,7 +225,7 @@ const config: UserConfig<DefaultTheme.Config> = {
text: 'Release Notes',
link: 'https://github.com/faker-js/faker/releases',
},
...oldVersions.map(({ version, link }) => ({
...versionLinks.map(({ version, link }) => ({
text: version,
link,
})),
Expand Down
24 changes: 7 additions & 17 deletions docs/.vitepress/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@ function readBranchName(): string {
}

function readOtherLatestReleaseTagNames(): string[] {
const currentMajorVersion = semver.major(version);
const latestReleaseTagNames = execSync('git tag -l')
.toString('utf8')
.split('\n')
.filter((tag) => semver.valid(tag))
.filter((tag) => {
// Only consider tags for our deployed website versions,
// excluding the current major version.
const majorVersion = semver.major(tag);
return majorVersion >= 6 && majorVersion !== currentMajorVersion;
})
// Only consider tags for our deployed website versions
.filter((tag) => semver.major(tag) >= 6)
// Find the latest tag for each major version
.reduce<Record<number, string>>((latestTagByMajor, tag) => {
const majorVersion = semver.major(tag);

Expand All @@ -39,10 +35,6 @@ const {
BRANCH: branchName = readBranchName(),
} = process.env;

const hiddenLink =
deployContext === 'production'
? 'https://fakerjs.dev/'
: `https://${branchName}.fakerjs.dev/`;
const otherVersions = readOtherLatestReleaseTagNames();
const isReleaseBranch = /^v\d+$/.test(branchName);

Expand All @@ -60,11 +52,7 @@ export const versionBannerInfix: string | null = (() => {
})();

export const currentVersion = isReleaseBranch ? `v${version}` : branchName;
export const oldVersions = [
{
version: 'latest',
link: 'https://fakerjs.dev/',
},
export const versionLinks = [
{
version: 'next',
link: 'https://next.fakerjs.dev/',
Expand All @@ -73,7 +61,9 @@ export const oldVersions = [
version,
link: `https://v${semver.major(version)}.fakerjs.dev/`,
})),
].filter(({ link }) => link !== hiddenLink);
]
// Don't link to the current branch's version.
.filter(({ link }) => link !== `https://${branchName}.fakerjs.dev/`);

export const algoliaIndex = isReleaseBranch
? `fakerjs-v${semver.major(version)}`
Expand Down
13 changes: 4 additions & 9 deletions test/docs/versions.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { execSync } from 'node:child_process';
import * as semver from 'semver';
import { describe, expect, it } from 'vitest';
import { oldVersions } from '../../docs/.vitepress/versions';
import { versionLinks } from '../../docs/.vitepress/versions';

function isFakerOrigin(): boolean {
try {
Expand All @@ -22,19 +22,14 @@ function isFakerOrigin(): boolean {
describe.runIf(isFakerOrigin())('docs versions', () => {
describe('oldVersions', () => {
it('should have a complete set of oldVersions', () => {
expect(oldVersions.length).toBeGreaterThanOrEqual(2);
expect(versionLinks.length).toBeGreaterThanOrEqual(1);

expect(oldVersions[0]).toEqual({
version: 'latest',
link: 'https://fakerjs.dev/',
});

const versionEntry = oldVersions[1];
const versionEntry = versionLinks[0];
if (versionEntry.version === 'next') {
expect(versionEntry.link).toBe('https://next.fakerjs.dev/');
}

const releaseVersions = oldVersions.filter(({ version }) =>
const releaseVersions = versionLinks.filter(({ version }) =>
semver.valid(version)
);
const latestMajorRelease = semver.major(releaseVersions[0].version);
Expand Down

0 comments on commit 13dc420

Please sign in to comment.