@conecli/cone-cli
Version:
松果编辑器命令行工具
54 lines (45 loc) • 1.14 kB
JavaScript
const chalk = require('chalk')
const format = require('util').format
/**
* Prefix.
*/
const prefix = ''
const sep = chalk.gray('')
/**
* Log a `message` to the console.
*
* @param {String} message
*/
exports.log = function (...args) {
const msg = format.apply(format, args)
console.log(chalk.white(prefix), sep, msg)
}
/**
* Log an error `message` to the console and exit.
*
* @param {String} message
*/
exports.fatal = function (...args) {
if (args[0] instanceof Error) args[0] = args[0].message.trim()
const msg = format.apply(format, args)
console.error(chalk.bgRed(' ERROR '), chalk.red(prefix + sep + msg))
process.exit(1)
}
/**
* Log a success `message` to the console and exit.
*
* @param {String} message
*/
exports.success = function (...args) {
const msg = format.apply(format, args)
console.log(chalk.bgGreen.black(' DONE '), prefix + sep + msg)
}
/**
*
* Log an warning `message` to the console.
* @param args
*/
exports.warning = function (...args) {
const msg = format.apply(format, args)
console.log(chalk.bgYellow.black(' WARN '), chalk.yellow(prefix + sep + msg))
}