Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(@142vip/utils): vipColorvipSymbols重命名,大驼峰格式 #313

Merged
merged 1 commit into from
Jan 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -438,14 +438,14 @@ All notable changes to this project will be documented in this file. See [commit

- 使用`VipProjectTable`组件,优化首页显示效果,`首页-趋势`支持暗夜模式 &nbsp;-&nbsp; by **chufan** [<samp>(4e1b0)</samp>](https://github.com/142vip/core-x/commit/4e1b0d6)
- 使用`VipTeam`组件,优化首页展示 &nbsp;-&nbsp; by **chufan** [<samp>(f2e9f)</samp>](https://github.com/142vip/core-x/commit/f2e9f7a)
- 移除全局`chalk`模块,使用`vipColor`变量处理日志格式 &nbsp;-&nbsp; by **chufan** [<samp>(51156)</samp>](https://github.com/142vip/core-x/commit/5115623)
- 移除全局`chalk`模块,使用`VipColor`变量处理日志格式 &nbsp;-&nbsp; by **chufan** [<samp>(51156)</samp>](https://github.com/142vip/core-x/commit/5115623)
- **@142vip/fairy-cli**:
- 移除`log-symbols`模块,优化`check`命令的日志输出 &nbsp;-&nbsp; by **chufan** [<samp>(47635)</samp>](https://github.com/142vip/core-x/commit/4763593)
- `release`发布命令增加`--filter`可选参数,支持多次调用,用于指定模块路径 &nbsp;-&nbsp; by **chufan** [<samp>(d0cc1)</samp>](https://github.com/142vip/core-x/commit/d0cc1e7)
- **@142vip/release-version**:
- 移除`log-symbols`模块,替换为`vipSymbols`变量 &nbsp;-&nbsp; by **chufan** [<samp>(6347b)</samp>](https://github.com/142vip/core-x/commit/6347bc5)
- 移除`log-symbols`模块,替换为`VipSymbols`变量 &nbsp;-&nbsp; by **chufan** [<samp>(6347b)</samp>](https://github.com/142vip/core-x/commit/6347bc5)
- **@142vip/utils**:
- 移除`chalk`,使用`ansi-colors`模块,新增`vipColor`和`vipSymbols`常用终端日志输出变量 &nbsp;-&nbsp; by **chufan** [<samp>(55ae6)</samp>](https://github.com/142vip/core-x/commit/55ae636)
- 移除`chalk`,使用`ansi-colors`模块,新增`VipColor`和`VipSymbols`常用终端日志输出变量 &nbsp;-&nbsp; by **chufan** [<samp>(55ae6)</samp>](https://github.com/142vip/core-x/commit/55ae636)
- **@142vip/vitepress**:
- 封装`VipBackTop`组件,优化`VipProjectTable`组件显示样式 &nbsp;-&nbsp; by **chufan** [<samp>(0392e)</samp>](https://github.com/142vip/core-x/commit/0392e18)
- 拓展项目表格和团队介绍组件封装,优化使用 &nbsp;-&nbsp; by **chufan** [<samp>(854ab)</samp>](https://github.com/142vip/core-x/commit/854ab43)
Expand Down
20 changes: 10 additions & 10 deletions packages/changelog/src/core/changelog.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import process from 'node:process'
import { getGitDiff, parseGitCommit } from 'changelogen'
import { VipCommander, VipJSON, vipColor } from '@142vip/utils'
import { VipColor, VipCommander, VipJSON } from '@142vip/utils'
import { name as packageName, version as packageVersion } from '../../package.json'
import {
generateMarkdown,
Expand Down Expand Up @@ -67,7 +67,7 @@
// 发布子模块时,需要考虑根模块迭代一个版本,子模块迭代多个版本但只需要记录一个版本
let newRawCommits = []
if (options.scopeName != null) {
console.log(`chore(${options.scopeName})`, rawCommits)

Check warning on line 70 in packages/changelog/src/core/changelog.ts

View workflow job for this annotation

GitHub Actions / 基础编译构建

Unexpected console statement
for (const rawCommit of rawCommits) {
if (rawCommit.message.includes(`release(${options.scopeName})`)) {
break
Expand Down Expand Up @@ -104,21 +104,21 @@
let webUrl = ''

try {
console.log()

Check warning on line 107 in packages/changelog/src/core/changelog.ts

View workflow job for this annotation

GitHub Actions / 基础编译构建

Unexpected console statement
console.log(vipColor.dim(`${vipColor.bold(packageName)} `) + vipColor.dim(`v${packageVersion}`))
console.log(VipColor.dim(`${VipColor.bold(packageName)} `) + VipColor.dim(`v${packageVersion}`))

Check warning on line 108 in packages/changelog/src/core/changelog.ts

View workflow job for this annotation

GitHub Actions / 基础编译构建

Unexpected console statement

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

console.log(vipColor.cyan(config.from) + vipColor.dim(' -> ') + vipColor.blue(config.to) + vipColor.dim(` (${commits.length} commits)`))
console.log(vipColor.dim('--------------'))
console.log(VipColor.cyan(config.from) + VipColor.dim(' -> ') + VipColor.blue(config.to) + VipColor.dim(` (${commits.length} commits)`))

Check warning on line 113 in packages/changelog/src/core/changelog.ts

View workflow job for this annotation

GitHub Actions / 基础编译构建

Unexpected console statement
console.log(VipColor.dim('--------------'))

Check warning on line 114 in packages/changelog/src/core/changelog.ts

View workflow job for this annotation

GitHub Actions / 基础编译构建

Unexpected console statement
console.log()

Check warning on line 115 in packages/changelog/src/core/changelog.ts

View workflow job for this annotation

GitHub Actions / 基础编译构建

Unexpected console statement
console.log(markdown.replace(/&nbsp;/g, ''))

Check warning on line 116 in packages/changelog/src/core/changelog.ts

View workflow job for this annotation

GitHub Actions / 基础编译构建

Unexpected console statement
console.log()

Check warning on line 117 in packages/changelog/src/core/changelog.ts

View workflow job for this annotation

GitHub Actions / 基础编译构建

Unexpected console statement
console.log(vipColor.dim('--------------'))
console.log(VipColor.dim('--------------'))

Check warning on line 118 in packages/changelog/src/core/changelog.ts

View workflow job for this annotation

GitHub Actions / 基础编译构建

Unexpected console statement

if (config.dry) {
console.log(vipColor.yellow('试运行。已跳过版本发布。'))
console.log(VipColor.yellow('试运行。已跳过版本发布。'))

Check warning on line 121 in packages/changelog/src/core/changelog.ts

View workflow job for this annotation

GitHub Actions / 基础编译构建

Unexpected console statement
printUrl(webUrl)
return
}
Expand All @@ -131,14 +131,14 @@

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

if (!commits.length && await isRepoShallow()) {
console.error(vipColor.yellow('存储库似乎克隆得很浅,这使得更改日志无法生成。您可能希望在 CI 配置中指定 \'fetch-depth: 0\'。'))
console.error(VipColor.yellow('存储库似乎克隆得很浅,这使得更改日志无法生成。您可能希望在 CI 配置中指定 \'fetch-depth: 0\'。'))
printUrl(webUrl)
process.exitCode = 1
return
Expand All @@ -148,9 +148,9 @@
await sendRelease(config, markdown)
}
catch (e: any) {
console.error(vipColor.red(String(e)))
console.error(VipColor.red(String(e)))
if (e?.stack)
console.error(vipColor.dim(e.stack?.split('\n').slice(1).join('\n')))
console.error(VipColor.dim(e.stack?.split('\n').slice(1).join('\n')))

// 手动执行,创建release
if (webUrl) {
Expand Down
12 changes: 6 additions & 6 deletions packages/changelog/src/utils/github.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { $fetch } from 'ofetch'
import { vipColor, vipQs } from '@142vip/utils'
import { VipColor, vipQs } from '@142vip/utils'
import type {
AuthorInfo,
ChangelogOptions,
Expand Down Expand Up @@ -32,7 +32,7 @@ export async function sendRelease(options: ChangelogOptions, content: string): P
prerelease: options.prerelease,
tag_name: options.to,
}
console.log(vipColor.cyan(method === 'POST'
console.log(VipColor.cyan(method === 'POST'
? 'Creating release notes...'
: 'Updating release notes...'),
)
Expand All @@ -41,7 +41,7 @@ export async function sendRelease(options: ChangelogOptions, content: string): P
body: JSON.stringify(body),
headers,
})
console.log(vipColor.green(`Released on ${res.html_url}`))
console.log(VipColor.green(`Released on ${res.html_url}`))
}

function getHeaders(options: ChangelogOptions) {
Expand Down Expand Up @@ -162,8 +162,8 @@ export function generateWebUrl(config: any, markdown: string): string {
*/
export function printUrl(webUrl: string, success: boolean = true): void {
const errMsg = success
? `\n${vipColor.yellow('使用以下链接手动发布新的版本:')}\n`
: `\n${vipColor.red('无法创建发布。使用以下链接手动创建:')}\n`
? `\n${VipColor.yellow('使用以下链接手动发布新的版本:')}\n`
: `\n${VipColor.red('无法创建发布。使用以下链接手动创建:')}\n`

console.error(`${errMsg}${vipColor.yellow(webUrl)}\n`)
console.error(`${errMsg}${VipColor.yellow(webUrl)}\n`)
}
8 changes: 4 additions & 4 deletions packages/fairy-cli/src/commands/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import process from 'node:process'
import type { VersionBumpOptions } from '@142vip/release-version'
import { versionBump } from '@142vip/release-version'
import type { VipCommander } from '@142vip/utils'
import { promptConfirm, promptList, vipColor } from '@142vip/utils'
import { VipColor, promptConfirm, promptList } from '@142vip/utils'
import {
CliCommandEnum,
getBranchName,
Expand Down Expand Up @@ -87,13 +87,13 @@ function execVipRelease(args: VipReleaseExtraOptions) {
defaultRepoName,
...packageNames,
]
promptList(choices, `选择需要使用${vipColor.red('Release')}命令发布的模块名称:`)
promptList(choices, `选择需要使用${VipColor.red('Release')}命令发布的模块名称:`)
.then(async (packageName) => {
// 确认框
const isRelease = await promptConfirm(`将对模块${vipColor.green(packageName)}进行版本迭代,是否继续操作?`)
const isRelease = await promptConfirm(`将对模块${VipColor.green(packageName)}进行版本迭代,是否继续操作?`)

if (!isRelease) {
console.log(vipColor.yellow('用户取消发布操作!!'))
console.log(VipColor.yellow('用户取消发布操作!!'))
process.exit(0)
}

Expand Down
8 changes: 4 additions & 4 deletions packages/fairy-cli/src/shared/release-package.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { execSync } from 'node:child_process'
import process from 'node:process'
import { versionBump } from '@142vip/release-version'
import { vipColor, vipSymbols } from '@142vip/utils'
import { VipColor, VipSymbols } from '@142vip/utils'
import { getCommitLogs, getLatestTagName } from './git'

interface PackageJSON {
Expand Down Expand Up @@ -68,18 +68,18 @@ export function printPreCheckRelease(packageNames: string[]) {
console.log('\n对仓库各模块进行版本变更校验,结果如下:\n')
for (const pkg of packages) {
if (pkg.release) {
console.log(vipColor.red(`${vipSymbols.error} ${pkg.name}`))
console.log(VipColor.red(`${VipSymbols.error} ${pkg.name}`))
}
else {
console.log(vipColor.green(`${vipSymbols.success} ${pkg.name}`))
console.log(VipColor.green(`${VipSymbols.success} ${pkg.name}`))
}
}

// 输出空行
console.log()

if (!isRootRelease) {
console.log(`${vipColor.yellow(`${vipSymbols.warning} 存在未发布的模块,请先进行模块的版本变更,再更新仓库版本!!!`)}`)
console.log(`${VipColor.yellow(`${VipSymbols.warning} 存在未发布的模块,请先进行模块的版本变更,再更新仓库版本!!!`)}`)
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/release-version/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ All notable changes to this project will be documented in this file. See [commit

### ✨ Features

- 移除`log-symbols`模块,替换为`vipSymbols`变量 &nbsp;-&nbsp; by **chufan** [<samp>(6347b)</samp>](https://github.com/142vip/core-x/commit/6347bc5)
- 移除`log-symbols`模块,替换为`VipSymbols`变量 &nbsp;-&nbsp; by **chufan** [<samp>(6347b)</samp>](https://github.com/142vip/core-x/commit/6347bc5)

**Release New Version v0.0.1-alpha.9 [👉 View New Package On NPM](https://www.npmjs.com/package/@142vip/release-version)**

Expand Down
12 changes: 6 additions & 6 deletions packages/release-version/src/core/version-bump.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import process from 'node:process'
import path from 'node:path'
import prompts from 'prompts'
import { bold, cyan, green } from 'kolorist'
import { execShell, vipSymbols } from '@142vip/utils'
import { VipSymbols, execShell } from '@142vip/utils'
import type { VersionBumpOptions, VersionBumpResults } from '../types'
import { NpmScript } from '../types'
import { getNewVersion } from './get-new-version'
Expand Down Expand Up @@ -46,7 +46,7 @@ export async function versionBump(arg: (VersionBumpOptions) | string = {}): Prom
await updateFiles(operation)

if (operation.options.changelog) {
console.log(vipSymbols.info, 'Generate CHANGELOG.md By @142vip/changelog', operation.options.execute)
console.log(VipSymbols.info, 'Generate CHANGELOG.md By @142vip/changelog', operation.options.execute)
try {
const filePath = path.join(operation.options.cwd, 'CHANGELOG.md')
const baseCommand = `changelog --output "${filePath}" --name v${operation.state.newVersion}`
Expand All @@ -56,18 +56,18 @@ export async function versionBump(arg: (VersionBumpOptions) | string = {}): Prom
: { command: baseCommand, description: '普通模式,生成CHANGELOG文档' })
}
catch (e) {
console.log(vipSymbols.error, 'Happen Error In Generate CHANGELOG!!!')
console.log(VipSymbols.error, 'Happen Error In Generate CHANGELOG!!!')
console.log(e)
process.exit(1)
}
console.log(vipSymbols.success, 'Generate CHANGELOG.md Finished')
console.log(VipSymbols.success, 'Generate CHANGELOG.md Finished')
}

// 执行命令
if (operation.options.execute) {
console.log(vipSymbols.info, 'Executing Script', operation.options.execute)
console.log(VipSymbols.info, 'Executing Script', operation.options.execute)
await execShell({ command: operation.options.execute, description: '执行execute提供的命令' })
console.log(vipSymbols.success, 'Script Finished')
console.log(VipSymbols.success, 'Script Finished')
}

// 运行version钩子函数
Expand Down
14 changes: 7 additions & 7 deletions packages/release-version/src/utils/progress.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { vipSymbols } from '@142vip/utils'
import { VipSymbols } from '@142vip/utils'
import type { VersionBumpProgress } from '../types'
import { ProgressEvent } from '../types'

Expand All @@ -9,27 +9,27 @@ import { ProgressEvent } from '../types'
export function showProgress(progress: VersionBumpProgress) {
switch (progress.event) {
case ProgressEvent.FileUpdated:
console.log(vipSymbols.success, `Updated ${progress.updatedFiles.pop()} to ${progress.newVersion}`)
console.log(VipSymbols.success, `Updated ${progress.updatedFiles.pop()} to ${progress.newVersion}`)
break

case ProgressEvent.FileSkipped:
console.log(vipSymbols.info, `${progress.skippedFiles.pop()} did not need to be updated`)
console.log(VipSymbols.info, `${progress.skippedFiles.pop()} did not need to be updated`)
break

case ProgressEvent.GitCommit:
console.log(vipSymbols.success, 'Git commit')
console.log(VipSymbols.success, 'Git commit')
break

case ProgressEvent.GitTag:
console.log(vipSymbols.success, 'Git tag')
console.log(VipSymbols.success, 'Git tag')
break

case ProgressEvent.GitPush:
console.log(vipSymbols.success, 'Git push')
console.log(VipSymbols.success, 'Git push')
break

case ProgressEvent.NpmScript:
console.log(vipSymbols.success, `Npm run ${progress.script}`)
console.log(VipSymbols.success, `Npm run ${progress.script}`)
break
}
}
2 changes: 1 addition & 1 deletion packages/utils/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ All notable changes to this project will be documented in this file. See [commit

### ✨ Features

- 移除`chalk`,使用`ansi-colors`模块,新增`vipColor`和`vipSymbols`常用终端日志输出变量 &nbsp;-&nbsp; by **chufan** [<samp>(55ae6)</samp>](https://github.com/142vip/core-x/commit/55ae636)
- 移除`chalk`,使用`ansi-colors`模块,新增`VipColor`和`VipSymbols`常用终端日志输出变量 &nbsp;-&nbsp; by **chufan** [<samp>(55ae6)</samp>](https://github.com/142vip/core-x/commit/55ae636)

**Release New Version v0.0.1-alpha.2 [👉 View New Package On NPM](https://www.npmjs.com/package/@142vip/utils)**

Expand Down
18 changes: 9 additions & 9 deletions packages/utils/src/core/color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ import { create } from 'ansi-colors'
/**
* 终端修改颜色
*/
export const vipColor = create()
export const VipColor = create()

/**
* 终端标记
*/
export const vipSymbols = {
success: vipColor.symbols.check,
error: vipColor.symbols.cross,
warning: vipColor.symbols.warning,
info: vipColor.symbols.info,
question: vipColor.symbols.question,
heart: vipColor.symbols.heart,
mark: vipColor.symbols.mark,
export const VipSymbols = {
success: VipColor.symbols.check,
error: VipColor.symbols.cross,
warning: VipColor.symbols.warning,
info: VipColor.symbols.info,
question: VipColor.symbols.question,
heart: VipColor.symbols.heart,
mark: VipColor.symbols.mark,
}
14 changes: 7 additions & 7 deletions packages/utils/src/core/docker.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as process from 'node:process'
import { commandStandardExecutor, execCommand } from './exec'
import { VipLogger } from './logger'
import { vipSymbols } from './color'
import { VipSymbols } from './color'

const vipLog = new VipLogger()

Expand Down Expand Up @@ -73,11 +73,11 @@ export async function isInstallDocker(args?: DockerOptions) {
if (args?.logger) {
const vipLog = new VipLogger()
if (code === 0) {
vipLog.log(`检测到docker,版本信息:\n`, { startLabel: vipSymbols.success })
vipLog.log(`检测到docker,版本信息:\n`, { startLabel: VipSymbols.success })
vipLog.log(stdout)
}
else {
vipLog.log(`未检测到docker,请先安装!!\n`, { startLabel: vipSymbols.error })
vipLog.log(`未检测到docker,请先安装!!\n`, { startLabel: VipSymbols.error })
vipLog.error(stderr)
}
}
Expand All @@ -94,11 +94,11 @@ export async function isInstallDockerCompose(args?: DockerOptions) {
// 打印日志
if (args?.logger) {
if (code === 0) {
vipLog.log(`检测到docker-compose,版本信息:\n`, { startLabel: vipSymbols.success })
vipLog.log(`检测到docker-compose,版本信息:\n`, { startLabel: VipSymbols.success })
vipLog.log(stdout)
}
else {
vipLog.log(`未检测到docker-compose,请先安装!!\n`, { startLabel: vipSymbols.error })
vipLog.log(`未检测到docker-compose,请先安装!!\n`, { startLabel: VipSymbols.error })
vipLog.error(stderr)
}
}
Expand Down Expand Up @@ -139,8 +139,8 @@ export async function buildImage(args: BuildImageDockerOptions) {
const command = `docker build ${buildArg} ${targetParams} ${memoryParams} -t '${args.imageName}' .`

if (args.logger) {
vipLog.log(`执行的命令:\n`, { startLabel: vipSymbols.success })
vipLog.log(`${command}\n`, { startLabel: vipSymbols.success })
vipLog.log(`执行的命令:\n`, { startLabel: VipSymbols.success })
vipLog.log(`${command}\n`, { startLabel: VipSymbols.success })
}
vipLog.log(args.imageName, { startLabel: '构建镜像' })

Expand Down
8 changes: 4 additions & 4 deletions packages/utils/src/core/logger.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { vipColor } from './color'
import { VipColor } from './color'

export interface LoggerOptions {
startLabel?: string
Expand Down Expand Up @@ -32,17 +32,17 @@ export class VipLogger {
}

public info(msg: string, opts?: LoggerOptions) {
const infoText = `${vipColor.green(opts?.startLabel ?? '')} ${vipColor.magenta(msg)} ${vipColor.yellow(opts?.endLabel ?? '')}`
const infoText = `${VipColor.green(opts?.startLabel ?? '')} ${VipColor.magenta(msg)} ${VipColor.yellow(opts?.endLabel ?? '')}`
console.info(infoText)
}

public log(msg: string, opts?: LoggerOptions) {
const logText = `${vipColor.blue(opts?.startLabel ?? '')} ${vipColor.magenta(msg)} ${vipColor.yellow(opts?.endLabel ?? '')}`
const logText = `${VipColor.blue(opts?.startLabel ?? '')} ${VipColor.magenta(msg)} ${VipColor.yellow(opts?.endLabel ?? '')}`
console.log(logText)
}

public error(msg: string, opts?: LoggerOptions) {
const text = `${vipColor.red(opts?.startLabel ?? '')} ${vipColor.magenta(msg)} ${vipColor.yellow(opts?.endLabel ?? '')}`
const text = `${VipColor.red(opts?.startLabel ?? '')} ${VipColor.magenta(msg)} ${VipColor.yellow(opts?.endLabel ?? '')}`
console.error(text)
}
}
4 changes: 2 additions & 2 deletions packages/utils/src/core/shell.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { name, version } from '../../package.json'
import { execCommand } from './exec'
import { VipLogger } from './logger'
import { vipColor } from './color'
import { VipColor } from './color'

export interface ShellCommand {
command: string
Expand All @@ -10,7 +10,7 @@ export interface ShellCommand {
// 全局日志
const vipLog = VipLogger.getInstance()

const projectName = vipColor.greenBright(`[${name}@${version}]`)
const projectName = VipColor.greenBright(`[${name}@${version}]`)

/**
* 脚本执行器,执行shell命令
Expand Down
Loading
Loading