Skip to content

Commit

Permalink
fix(projects): fix tags order
Browse files Browse the repository at this point in the history
  • Loading branch information
honghuangdc committed Apr 23, 2024
1 parent 3e7a319 commit 2ff7eaa
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/constant.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export const VERSION_REG = /v\d+\.\d+\.\d+(-(beta|alpha)\.\d+)?/;

export const RELEASE_VERSION_REG = /v\d+\.\d+\.\d+/;

export const VERSION_REG_OF_MARKDOWN = /## \[v\d+\.\d+\.\d+(-(beta|alpha)\.\d+)?]/g;

export const VERSION_WITH_RELEASE = /release\sv\d+\.\d+\.\d+(-(beta|alpha)\.\d+)?/;
31 changes: 29 additions & 2 deletions src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ofetch } from 'ofetch';
import dayjs from 'dayjs';
import { consola } from 'consola';
import { execCommand, notNullish } from './shared';
import { VERSION_REG } from './constant';
import { RELEASE_VERSION_REG, VERSION_REG } from './constant';
import type { GitCommit, GitCommitAuthor, GithubConfig, RawGitCommit, Reference, ResolvedAuthor } from './types';

/** Get the total git tags */
Expand All @@ -11,7 +11,34 @@ export async function getTotalGitTags() {

const tags = tagStr.split('\n');

return tags.filter(tag => VERSION_REG.test(tag));
const filtered = tags.filter(tag => VERSION_REG.test(tag));

return sortTags(filtered);
}

function sortTags(tags: string[]) {
tags.sort((a, b) => {
const versionA = a.match(RELEASE_VERSION_REG)?.[0] || '';
const versionB = b.match(RELEASE_VERSION_REG)?.[0] || '';

if (versionA < versionB) {
return -1;
} else if (versionA > versionB) {
return 1;
}

const isBetaA = isPrerelease(a);
const isBetaB = isPrerelease(b);

if (isBetaA && !isBetaB) {
return -1;
} else if (!isBetaA && isBetaB) {
return 1;
}
return 0;
});

return tags;
}

/** Get map of the git tag and date */
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,6 @@ export async function generateTotalChangelog(options?: Partial<ChangelogOption>,
await writeMarkdown(markdown, opts.output, true);
}

generateTotalChangelog();

export type { ChangelogOption };

0 comments on commit 2ff7eaa

Please sign in to comment.