chore(project): enhance logging in github actions (#5425)

This commit is contained in:
jeremywu 2022-01-17 17:44:29 +08:00 committed by GitHub
parent 58c4040b45
commit 7ddb04b36c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 8 deletions

View File

@ -38,6 +38,8 @@ jobs:
- name: Build Element Plus
run: pnpm build
env:
FORCE_COLOR: 2
- name: Build website
run: pnpm docs:build

View File

@ -54,3 +54,4 @@ jobs:
TAG_VERSION: ${{env.TAG_VERSION}}
GIT_HEAD: ${{env.GIT_HEAD}}
REGISTRY: https://registry.npmjs.com/
FORCE_COLOR: 2

View File

@ -1,9 +1,11 @@
import { cyan, bold, yellow, green } from 'chalk'
import { command } from '../utils/log'
import type { FileSizeReporter } from 'rollup-plugin-filesize'
export const reporter: FileSizeReporter = (opt, outputOptions, info) => {
return `${cyan(bold(info.fileName))}: bundle size ${yellow(
info.bundleSize
)} -> minified ${green(info.minSize)}`
return command(
`${cyan(bold(info.fileName))}: bundle size ${yellow(
info.bundleSize
)} -> minified ${green(info.minSize)}`
)
}

View File

@ -1,23 +1,36 @@
import process from 'process'
import chalk from 'chalk'
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
const [command, info, error] = ['command', 'info', 'error'].map(
(symbol: string) => {
return (msg: string) => `[${symbol}] ${msg}`
}
)
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
const [group, endGroup] = ['group', 'endgroup'].map((symbol) => {
return (groupMsg: string) => `##[${symbol}] ${groupMsg}`
})
export function cyan(str: string) {
console.log(chalk.cyan(str))
console.log(command(chalk.cyan(str)))
}
export function yellow(str: string) {
console.log(chalk.yellow(str))
console.log(command(chalk.yellow(str)))
}
export function green(str: string) {
console.log(chalk.green(str))
console.log(command(chalk.green(str)))
}
export function red(str: string) {
console.error(chalk.red(str))
console.log(error(chalk.red(str)))
}
export function errorAndExit(e: Error): never {
red(e.stack ?? e.message)
process.exit(1)
}
export { command, info, error, group, endGroup }