lizi-wxapp-cli
Version:
微信小程序快速创建cli脚手架
46 lines (33 loc) • 1.07 kB
text/typescript
import chalk from 'chalk'
import cliTable, { HorizontalTable } from 'cli-table3'
interface LogInterface {
info(msg: string): void
success(msg: string, wrap?: boolean): void
error(msg: string, wrap?: boolean): void
warning(msg: string, wrap?: boolean): void
table(msg: any, tips?: boolean): void
}
export default class Logs implements LogInterface {
constructor() {}
public info(msg: string) {
console.log(chalk.white(msg))
}
public success(msg: string, wrap = true) {
console.log(chalk.green(`${wrap ? '\n\r️' : ''}${msg}`))
}
public error(msg: string, wrap = true) {
console.log(chalk.red(`${wrap ? '\n\r️' : ''}${msg}`))
}
public warning(msg: string, wrap = true) {
console.log(chalk.yellow(`${wrap ? '\n\r️' : ''}${msg}`))
}
public table(msg: any, tips = true): void {
let table = new cliTable({
style: {'border': []}
}) as HorizontalTable
table.push(...msg)
if (tips) this.error('请输入有效命令:', false)
console.log(table.toString())
}
}
export const log = new Logs()