From efeba8771d9b2ca3821fa24da926d3ed5e3301a3 Mon Sep 17 00:00:00 2001 From: chufan Date: Sat, 5 Oct 2024 09:24:23 +0800 Subject: [PATCH] =?UTF-8?q?style(@142vip/changelog):=20=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E6=95=B4=E7=90=86=E3=80=81=E9=A3=8E=E6=A0=BC=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/changelog/src/core/changelog.ts | 4 +++- packages/changelog/src/core/config.ts | 4 ++-- packages/changelog/src/utils/git.ts | 3 +++ packages/changelog/src/utils/github.ts | 10 +++++----- packages/changelog/src/utils/markdown.ts | 15 +++++++++------ 5 files changed, 22 insertions(+), 14 deletions(-) diff --git a/packages/changelog/src/core/changelog.ts b/packages/changelog/src/core/changelog.ts index a73fd8d..ba54a3e 100644 --- a/packages/changelog/src/core/changelog.ts +++ b/packages/changelog/src/core/changelog.ts @@ -64,7 +64,6 @@ async function resolveConfig(options: ChangelogOptions) { /** * 生成markdown文档信息 - * @param options */ async function generate(options: ChangelogOptions) { const config = await resolveConfig(options) @@ -102,6 +101,9 @@ async function generate(options: ChangelogOptions) { return { config, markdown, commits } } +/** + * 处理changelog业务 + */ async function dealChangelog(args: ChangelogOptions) { args.token = args.token || process.env.GITHUB_TOKEN diff --git a/packages/changelog/src/core/config.ts b/packages/changelog/src/core/config.ts index a86604c..2ba28ec 100644 --- a/packages/changelog/src/core/config.ts +++ b/packages/changelog/src/core/config.ts @@ -1,5 +1,5 @@ import process from 'node:process' -import type { ChangelogOptions } from '../types/changelog.interface' +import type { ChangelogOptions } from '../types' /** * 默认配置 @@ -29,7 +29,7 @@ export const ChangelogDefaultConfig: ChangelogOptions = { } /** - * 定义@142vip/changelog模块的默认配置文件 + * 定义配置文件 */ export function defineChangelogDefaultConfig(config: ChangelogOptions) { return config diff --git a/packages/changelog/src/utils/git.ts b/packages/changelog/src/utils/git.ts index 79e569a..06f162f 100644 --- a/packages/changelog/src/utils/git.ts +++ b/packages/changelog/src/utils/git.ts @@ -1,5 +1,8 @@ import semver from 'semver' +/** + * 获取github仓库 + */ export async function getGitHubRepo(baseUrl: string) { const url = await execCommand('git', ['config', '--get', 'remote.origin.url']) const escapedBaseUrl = baseUrl.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') diff --git a/packages/changelog/src/utils/github.ts b/packages/changelog/src/utils/github.ts index 9712eb7..d2e1723 100644 --- a/packages/changelog/src/utils/github.ts +++ b/packages/changelog/src/utils/github.ts @@ -1,6 +1,6 @@ import { $fetch } from 'ofetch' -import { cyan, green, red, yellow } from 'kolorist' import qs from 'qs' +import { vipColor } from '@142vip/utils' import type { AuthorInfo, ChangelogOptions, @@ -36,7 +36,7 @@ export async function sendRelease( prerelease: options.prerelease, tag_name: options.to, } - console.log(cyan(method === 'POST' + console.log(vipColor.cyan(method === 'POST' ? 'Creating release notes...' : 'Updating release notes...'), ) @@ -45,7 +45,7 @@ export async function sendRelease( body: JSON.stringify(body), headers, }) - console.log(green(`Released on ${res.html_url}`)) + console.log(vipColor.green(`Released on ${res.html_url}`)) } function getHeaders(options: ChangelogOptions) { @@ -172,9 +172,9 @@ export function generateWebUrl(config: any, markdown: string) { */ export function printUrl(webUrl: string, success: boolean = true) { if (success) { - console.error(`\n${yellow('使用以下链接手动发布新的版本:')}\n${yellow(webUrl)}\n`) + console.error(`\n${vipColor.yellow('使用以下链接手动发布新的版本:')}\n${vipColor.yellow(webUrl)}\n`) } else { - console.error(`\n${red('无法创建发布。使用以下链接手动创建:')}\n${yellow(webUrl)}\n`) + console.error(`\n${vipColor.red('无法创建发布。使用以下链接手动创建:')}\n${vipColor.yellow(webUrl)}\n`) } } diff --git a/packages/changelog/src/utils/markdown.ts b/packages/changelog/src/utils/markdown.ts index 30ca5d2..38f70a3 100644 --- a/packages/changelog/src/utils/markdown.ts +++ b/packages/changelog/src/utils/markdown.ts @@ -49,7 +49,9 @@ function formatLine(commit: Commit, options: ResolvedChangelogOptions) { return [description, refs].filter(i => i?.trim()).join(' ') } -// 标题 +/** + * 格式化标题 + */ function formatTitle(name: string, options: ResolvedChangelogOptions) { // 加表情包 if (!options.emoji) @@ -58,6 +60,9 @@ function formatTitle(name: string, options: ResolvedChangelogOptions) { return `### ${name.trim()}` } +/** + * 格式化Section + */ function formatSection(commits: Commit[], sectionName: string, options: ResolvedChangelogOptions) { if (!commits.length) return [] @@ -106,10 +111,12 @@ function formatSection(commits: Commit[], sectionName: string, options: Resolved .map(commit => `${padding}- ${prefix}${formatLine(commit, options)}`)) }) } - return lines } +/** + * 生成Markdown文档 + */ export async function generateMarkdown(commits: Commit[], options: ResolvedChangelogOptions) { const lines: string[] = [] @@ -154,7 +161,6 @@ export async function generateMarkdown(commits: Commit[], options: ResolvedChang /** * 年月日格式化当前时间 * - 格式: 2024-08-09 - * @param date */ function formatDateToYMD(date: Date = new Date()): string { const year = date.getFullYear() @@ -166,9 +172,6 @@ function formatDateToYMD(date: Date = new Date()): string { /** * 更新changelog - * @param outputPath - * @param markdown - * @param releaseVersionName */ export async function updateChangelog(outputPath: string, markdown: string, releaseVersionName: string) { let changelogMD: string