Skip to content

Commit 9a99642

Browse files
author
微信公众号:储凡
authored
Merge pull request #149 from 142vip/feat/del-qs
feat(@142vip/changelog): 移除`qs`、`kolorist`模块,使用`@142vip/utils`进行替换
2 parents bcae3ca + 22e6617 commit 9a99642

File tree

4 files changed

+20
-25
lines changed

4 files changed

+20
-25
lines changed

packages/changelog/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,8 @@
4747
"changelogen": "0.5.5",
4848
"commander": "^12.1.0",
4949
"convert-gitmoji": "^0.1.5",
50-
"kolorist": "^1.8.0",
50+
"@142vip/utils": "workspace:*",
5151
"ofetch": "^1.3.4",
52-
"qs": "^6.13.0",
5352
"semver": "^7.6.2"
5453
},
5554
"devDependencies": {

packages/changelog/src/core/changelog.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/* eslint-disable no-console */
22
import process from 'node:process'
3-
import { blue, bold, cyan, dim, red, yellow } from 'kolorist'
43
import { Command } from 'commander'
54
import { getGitDiff, parseGitCommit } from 'changelogen'
5+
import { vipColor } from '@142vip/utils'
66
import { name as packageName, version as packageVersion } from '../../package.json'
77
import {
88
generateMarkdown,
@@ -111,20 +111,20 @@ async function dealChangelog(args: ChangelogOptions) {
111111

112112
try {
113113
console.log()
114-
console.log(dim(`${bold('@142vip/changelog')} `) + dim(`v${packageVersion}`))
114+
console.log(vipColor.dim(`${vipColor.bold('@142vip/changelog')} `) + vipColor.dim(`v${packageVersion}`))
115115

116116
const { config, markdown, commits } = await generate(args)
117117
webUrl = generateWebUrl(config, markdown)
118118

119-
console.log(cyan(config.from) + dim(' -> ') + blue(config.to) + dim(` (${commits.length} commits)`))
120-
console.log(dim('--------------'))
119+
console.log(vipColor.cyan(config.from) + vipColor.dim(' -> ') + vipColor.blue(config.to) + vipColor.dim(` (${commits.length} commits)`))
120+
console.log(vipColor.dim('--------------'))
121121
console.log()
122122
console.log(markdown.replace(/ /g, ''))
123123
console.log()
124-
console.log(dim('--------------'))
124+
console.log(vipColor.dim('--------------'))
125125

126126
if (config.dry) {
127-
console.log(yellow('试运行。已跳过版本发布。'))
127+
console.log(vipColor.yellow('试运行。已跳过版本发布。'))
128128
printUrl(webUrl)
129129
return
130130
}
@@ -137,14 +137,14 @@ async function dealChangelog(args: ChangelogOptions) {
137137

138138
// 带token上传
139139
if (!config.tokens) {
140-
console.error(red('未找到 GitHub 令牌,请通过 GITHUB_TOKEN 环境变量指定。已跳过版本发布。'))
140+
console.error(vipColor.red('未找到 GitHub 令牌,请通过 GITHUB_TOKEN 环境变量指定。已跳过版本发布。'))
141141
printUrl(webUrl)
142142
process.exitCode = 1
143143
return
144144
}
145145

146146
if (!commits.length && await isRepoShallow()) {
147-
console.error(yellow('存储库似乎克隆得很浅,这使得更改日志无法生成。您可能希望在 CI 配置中指定 \'fetch-depth: 0\'。'))
147+
console.error(vipColor.yellow('存储库似乎克隆得很浅,这使得更改日志无法生成。您可能希望在 CI 配置中指定 \'fetch-depth: 0\'。'))
148148
printUrl(webUrl)
149149
process.exitCode = 1
150150
return
@@ -154,9 +154,9 @@ async function dealChangelog(args: ChangelogOptions) {
154154
await sendRelease(config, markdown)
155155
}
156156
catch (e: any) {
157-
console.error(red(String(e)))
157+
console.error(vipColor.red(String(e)))
158158
if (e?.stack)
159-
console.error(dim(e.stack?.split('\n').slice(1).join('\n')))
159+
console.error(vipColor.dim(e.stack?.split('\n').slice(1).join('\n')))
160160

161161
// 手动执行,创建release
162162
if (webUrl) {

packages/changelog/src/utils/github.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { $fetch } from 'ofetch'
2-
import { cyan, green, red, yellow } from 'kolorist'
3-
import qs from 'qs'
2+
import { vipColor, vipQs } from '@142vip/utils'
43
import type {
54
AuthorInfo,
65
ChangelogOptions,
@@ -36,7 +35,7 @@ export async function sendRelease(
3635
prerelease: options.prerelease,
3736
tag_name: options.to,
3837
}
39-
console.log(cyan(method === 'POST'
38+
console.log(vipColor.cyan(method === 'POST'
4039
? 'Creating release notes...'
4140
: 'Updating release notes...'),
4241
)
@@ -45,7 +44,7 @@ export async function sendRelease(
4544
body: JSON.stringify(body),
4645
headers,
4746
})
48-
console.log(green(`Released on ${res.html_url}`))
47+
console.log(vipColor.green(`Released on ${res.html_url}`))
4948
}
5049

5150
function getHeaders(options: ChangelogOptions) {
@@ -154,7 +153,7 @@ export async function hasTagOnGitHub(tag: string, options: ChangelogOptions) {
154153
*/
155154
export function generateWebUrl(config: any, markdown: string) {
156155
const baseUrl = `https://${config.baseUrl}/${config.repo}/releases/new`
157-
const queryParams = qs.stringify({
156+
const queryParams = vipQs.stringify({
158157
title: config.name || config.to,
159158
body: markdown,
160159
tag: config.to,
@@ -172,9 +171,9 @@ export function generateWebUrl(config: any, markdown: string) {
172171
*/
173172
export function printUrl(webUrl: string, success: boolean = true) {
174173
if (success) {
175-
console.error(`\n${yellow('使用以下链接手动发布新的版本:')}\n${yellow(webUrl)}\n`)
174+
console.error(`\n${vipColor.yellow('使用以下链接手动发布新的版本:')}\n${vipColor.yellow(webUrl)}\n`)
176175
}
177176
else {
178-
console.error(`\n${red('无法创建发布。使用以下链接手动创建:')}\n${yellow(webUrl)}\n`)
177+
console.error(`\n${vipColor.red('无法创建发布。使用以下链接手动创建:')}\n${vipColor.yellow(webUrl)}\n`)
179178
}
180179
}

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)