Skip to content

Commit efeba87

Browse files
committed
style(@142vip/changelog): 代码整理、风格优化
1 parent 09b8857 commit efeba87

File tree

5 files changed

+22
-14
lines changed

5 files changed

+22
-14
lines changed

packages/changelog/src/core/changelog.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ async function resolveConfig(options: ChangelogOptions) {
6464

6565
/**
6666
* 生成markdown文档信息
67-
* @param options
6867
*/
6968
async function generate(options: ChangelogOptions) {
7069
const config = await resolveConfig(options)
@@ -102,6 +101,9 @@ async function generate(options: ChangelogOptions) {
102101
return { config, markdown, commits }
103102
}
104103

104+
/**
105+
* 处理changelog业务
106+
*/
105107
async function dealChangelog(args: ChangelogOptions) {
106108
args.token = args.token || process.env.GITHUB_TOKEN
107109

packages/changelog/src/core/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import process from 'node:process'
2-
import type { ChangelogOptions } from '../types/changelog.interface'
2+
import type { ChangelogOptions } from '../types'
33

44
/**
55
* 默认配置
@@ -29,7 +29,7 @@ export const ChangelogDefaultConfig: ChangelogOptions = {
2929
}
3030

3131
/**
32-
* 定义@142vip/changelog模块的默认配置文件
32+
* 定义配置文件
3333
*/
3434
export function defineChangelogDefaultConfig(config: ChangelogOptions) {
3535
return config

packages/changelog/src/utils/git.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import semver from 'semver'
22

3+
/**
4+
* 获取github仓库
5+
*/
36
export async function getGitHubRepo(baseUrl: string) {
47
const url = await execCommand('git', ['config', '--get', 'remote.origin.url'])
58
const escapedBaseUrl = baseUrl.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')

packages/changelog/src/utils/github.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { $fetch } from 'ofetch'
2-
import { cyan, green, red, yellow } from 'kolorist'
32
import qs from 'qs'
3+
import { vipColor } from '@142vip/utils'
44
import type {
55
AuthorInfo,
66
ChangelogOptions,
@@ -36,7 +36,7 @@ export async function sendRelease(
3636
prerelease: options.prerelease,
3737
tag_name: options.to,
3838
}
39-
console.log(cyan(method === 'POST'
39+
console.log(vipColor.cyan(method === 'POST'
4040
? 'Creating release notes...'
4141
: 'Updating release notes...'),
4242
)
@@ -45,7 +45,7 @@ export async function sendRelease(
4545
body: JSON.stringify(body),
4646
headers,
4747
})
48-
console.log(green(`Released on ${res.html_url}`))
48+
console.log(vipColor.green(`Released on ${res.html_url}`))
4949
}
5050

5151
function getHeaders(options: ChangelogOptions) {
@@ -172,9 +172,9 @@ export function generateWebUrl(config: any, markdown: string) {
172172
*/
173173
export function printUrl(webUrl: string, success: boolean = true) {
174174
if (success) {
175-
console.error(`\n${yellow('使用以下链接手动发布新的版本:')}\n${yellow(webUrl)}\n`)
175+
console.error(`\n${vipColor.yellow('使用以下链接手动发布新的版本:')}\n${vipColor.yellow(webUrl)}\n`)
176176
}
177177
else {
178-
console.error(`\n${red('无法创建发布。使用以下链接手动创建:')}\n${yellow(webUrl)}\n`)
178+
console.error(`\n${vipColor.red('无法创建发布。使用以下链接手动创建:')}\n${vipColor.yellow(webUrl)}\n`)
179179
}
180180
}

packages/changelog/src/utils/markdown.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ function formatLine(commit: Commit, options: ResolvedChangelogOptions) {
4949
return [description, refs].filter(i => i?.trim()).join(' ')
5050
}
5151

52-
// 标题
52+
/**
53+
* 格式化标题
54+
*/
5355
function formatTitle(name: string, options: ResolvedChangelogOptions) {
5456
// 加表情包
5557
if (!options.emoji)
@@ -58,6 +60,9 @@ function formatTitle(name: string, options: ResolvedChangelogOptions) {
5860
return `### ${name.trim()}`
5961
}
6062

63+
/**
64+
* 格式化Section
65+
*/
6166
function formatSection(commits: Commit[], sectionName: string, options: ResolvedChangelogOptions) {
6267
if (!commits.length)
6368
return []
@@ -106,10 +111,12 @@ function formatSection(commits: Commit[], sectionName: string, options: Resolved
106111
.map(commit => `${padding}- ${prefix}${formatLine(commit, options)}`))
107112
})
108113
}
109-
110114
return lines
111115
}
112116

117+
/**
118+
* 生成Markdown文档
119+
*/
113120
export async function generateMarkdown(commits: Commit[], options: ResolvedChangelogOptions) {
114121
const lines: string[] = []
115122

@@ -154,7 +161,6 @@ export async function generateMarkdown(commits: Commit[], options: ResolvedChang
154161
/**
155162
* 年月日格式化当前时间
156163
* - 格式: 2024-08-09
157-
* @param date
158164
*/
159165
function formatDateToYMD(date: Date = new Date()): string {
160166
const year = date.getFullYear()
@@ -166,9 +172,6 @@ function formatDateToYMD(date: Date = new Date()): string {
166172

167173
/**
168174
* 更新changelog
169-
* @param outputPath
170-
* @param markdown
171-
* @param releaseVersionName
172175
*/
173176
export async function updateChangelog(outputPath: string, markdown: string, releaseVersionName: string) {
174177
let changelogMD: string

0 commit comments

Comments
 (0)