Skip to content

Commit

Permalink
fix(projects): use semver sort tags
Browse files Browse the repository at this point in the history
  • Loading branch information
honghuangdc committed Apr 23, 2024
1 parent e0b05ee commit 83bb053
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 28 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
"convert-gitmoji": "0.1.5",
"dayjs": "1.11.10",
"execa": "8.0.1",
"ofetch": "1.3.4"
"ofetch": "1.3.4",
"semver": "7.6.0"
},
"devDependencies": {
"@soybeanjs/cli": "1.0.11",
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 3 additions & 27 deletions src/git.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { ofetch } from 'ofetch';
import dayjs from 'dayjs';
import { consola } from 'consola';
import semver from 'semver';
import { execCommand, notNullish } from './shared';
import { RELEASE_VERSION_REG, VERSION_REG } from './constant';
import { VERSION_REG } from './constant';
import type { GitCommit, GitCommitAuthor, GithubConfig, RawGitCommit, Reference, ResolvedAuthor } from './types';

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

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;
return semver.sort(filtered);
}

/** Get map of the git tag and date */
Expand Down

0 comments on commit 83bb053

Please sign in to comment.