Skip to content

Commit

Permalink
feat(@142vip/release-version): 使用VipConsole输出日志
Browse files Browse the repository at this point in the history
  • Loading branch information
mmdapl committed Jan 20, 2025
1 parent 3c39bae commit 0cc9304
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 26 deletions.
3 changes: 2 additions & 1 deletion packages/release-version/src/bumpx-cli.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import process from 'node:process'
import { VipConsole } from '@142vip/utils'
import { version as packageVersion } from '../package.json'
import { errorHandler, parseArgs, showProgress } from './utils'
import { versionBump } from './core/version-bump'
Expand All @@ -22,7 +23,7 @@ export async function main() {

// 查看版本
if (version) {
console.log(packageVersion)
VipConsole.log(packageVersion)
process.exit(ExitCodeEnum.Success)
}

Expand Down
36 changes: 18 additions & 18 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 { VipSymbols, execShell } from '@142vip/utils'
import { VipConsole, 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)
VipConsole.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(e)
VipConsole.log(VipSymbols.error, 'Happen Error In Generate CHANGELOG!!!')
VipConsole.log(e)
process.exit(1)
}
console.log(VipSymbols.success, 'Generate CHANGELOG.md Finished')
VipConsole.log(VipSymbols.success, 'Generate CHANGELOG.md Finished')
}

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

// 运行version钩子函数
Expand Down Expand Up @@ -107,23 +107,23 @@ export async function versionBumpInfo(arg: VersionBumpOptions | string = {}): Pr
* 打印参数
*/
function printSummary(operation: Operation) {
console.log()
console.log(` files ${operation.options.files.map(i => bold(i)).join('\n ')}`)
VipConsole.log()
VipConsole.log(` files ${operation.options.files.map(i => bold(i)).join('\n ')}`)

// 生成CHANGELOG.md文档
if (operation.options.changelog) {
console.log(` generate CHANGELOG.md`)
VipConsole.log(` generate CHANGELOG.md`)
}
if (operation.options.commit)
console.log(` commit ${bold(formatVersionString(operation.options.commit.message, operation.state.newVersion))}`)
VipConsole.log(` commit ${bold(formatVersionString(operation.options.commit.message, operation.state.newVersion))}`)
if (operation.options.tag)
console.log(` tag ${bold(formatVersionString(operation.options.tag.name, operation.state.newVersion))}`)
VipConsole.log(` tag ${bold(formatVersionString(operation.options.tag.name, operation.state.newVersion))}`)
if (operation.options.execute)
console.log(` execute ${bold(operation.options.execute)}`)
VipConsole.log(` execute ${bold(operation.options.execute)}`)
if (operation.options.push)
console.log(` push ${cyan(bold('yes'))}`)
console.log()
console.log(` from ${bold(operation.state.currentVersion)}`)
console.log(` to ${green(bold(operation.state.newVersion))}`)
console.log()
VipConsole.log(` push ${cyan(bold('yes'))}`)
VipConsole.log()
VipConsole.log(` from ${bold(operation.state.currentVersion)}`)
VipConsole.log(` to ${green(bold(operation.state.newVersion))}`)
VipConsole.log()
}
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 { VipConsole, 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}`)
VipConsole.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`)
VipConsole.log(VipSymbols.info, `${progress.skippedFiles.pop()} did not need to be updated`)
break

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

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

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

case ProgressEvent.NpmScript:
console.log(VipSymbols.success, `Npm run ${progress.script}`)
VipConsole.log(VipSymbols.success, `Npm run ${progress.script}`)
break
}
}

0 comments on commit 0cc9304

Please sign in to comment.