Skip to content

Commit b50d804

Browse files
committed
fix(projects): fix version date
1 parent a3cf896 commit b50d804

File tree

7 files changed

+136
-116
lines changed

7 files changed

+136
-116
lines changed

CHANGELOG.md

Lines changed: 94 additions & 108 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
"@types/node": "20.2.5",
6464
"eslint": "8.41.0",
6565
"eslint-config-soybeanjs": "0.4.7",
66-
"githublogen": "link:../githublogen",
6766
"simple-git-hooks": "2.8.1",
6867
"tsx": "3.12.7",
6968
"typescript": "5.0.4",

pnpm-lock.yaml

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/changelog/git.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ofetch } from 'ofetch';
2+
import dayjs from 'dayjs';
23
import { execCommand, notNullish } from '../shared';
34
import type { RawGitCommit, GitCommit, GitCommitAuthor, Reference, AuthorInfo } from '../types';
45

@@ -10,6 +11,35 @@ export async function getTotalGitTags() {
1011
return tags;
1112
}
1213

14+
export async function getTagDateMap() {
15+
const tagDateStr = await execCommand('git', [
16+
'--no-pager',
17+
'log',
18+
'--tags',
19+
'--simplify-by-decoration',
20+
'--pretty=format:%ci %d'
21+
]);
22+
23+
const TAG_MARK = '(tag: ';
24+
25+
const map = new Map<string, string>();
26+
27+
const dates = tagDateStr.split('\n').filter(item => item.includes(TAG_MARK));
28+
dates.forEach(item => {
29+
const [dateStr, tagStr] = item.split(TAG_MARK);
30+
31+
const date = dayjs(dateStr.trim()).format('YYYY-MM-DD');
32+
33+
const VERSION_REG = /v\d+\.\d+\.\d+/;
34+
const tag = tagStr.match(VERSION_REG)?.[0];
35+
if (tag && date) {
36+
map.set(tag.trim(), date);
37+
}
38+
});
39+
40+
return map;
41+
}
42+
1343
export function getFromToTags(tags: string[]) {
1444
const result: { from: string; to: string }[] = [];
1545

src/changelog/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import cliProgress from 'cli-progress';
22
import { readFile } from 'fs/promises';
33
import {
44
getTotalGitTags,
5+
getTagDateMap,
56
getLastGitTag,
67
getFromToTags,
78
getCurrentGitBranch,
@@ -39,6 +40,7 @@ function createDefaultOptions() {
3940
from: '',
4041
to: '',
4142
tags: [],
43+
tagDateMap: new Map(),
4244
prerelease: false,
4345
capitalize: true,
4446
emoji: true,
@@ -98,6 +100,8 @@ export async function initOptions() {
98100

99101
options.tags = await getTotalGitTags();
100102

103+
options.tagDateMap = await getTagDateMap();
104+
101105
options.github = await getGitHubRepo();
102106

103107
options.prerelease = isPrerelease(options.to);

src/changelog/markdown.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { existsSync } from 'fs';
22
import { readFile, writeFile } from 'fs/promises';
3-
import dayjs from 'dayjs';
43
import { convert } from 'convert-gitmoji';
54
import { partition, groupBy, capitalize, join } from '../shared';
65
import type { Reference, GitCommit, ChangelogOption, AuthorInfo } from '../types';
@@ -133,11 +132,15 @@ export function generateMarkdown(params: {
133132
const url = `https://github.com/${options.github}/compare/${options.from}...${options.to}`;
134133

135134
if (showTitle) {
136-
const today = dayjs().format('YYYY-MM-DD');
137-
138135
const version = VERSION_REG.test(options.to) ? options.to : options.newVersion;
139136

140-
const title = `## [${version}](${url})(${today})`;
137+
const date = options.tagDateMap.get(options.to);
138+
139+
let title = `## [${version}](${url})`;
140+
141+
if (date) {
142+
title += ` (${date})`;
143+
}
141144

142145
lines.push(title);
143146
}

src/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export interface ChangelogOption {
4141
from: string;
4242
to: string;
4343
tags: string[];
44+
tagDateMap: Map<string, string>;
4445
prerelease: boolean;
4546
capitalize: boolean;
4647
/**

0 commit comments

Comments
 (0)