mirror of
https://github.com/vuejs/vue-cli.git
synced 2026-01-24 16:18:57 -06:00
73 lines
1.5 KiB
JavaScript
73 lines
1.5 KiB
JavaScript
const chalk = require('chalk')
|
|
const readline = require('readline')
|
|
const { execSync } = require('child_process')
|
|
const padStart = require('string.prototype.padstart')
|
|
const spinner = require('./spinner')
|
|
|
|
const format = (label, msg) => {
|
|
return msg.split('\n').map((line, i) => {
|
|
return i === 0
|
|
? `${label} ${line}`
|
|
: padStart(line, chalk.reset(label).length)
|
|
}).join('\n')
|
|
}
|
|
|
|
Object.assign(exports, spinner)
|
|
|
|
exports.log = msg => console.log(msg || '')
|
|
|
|
exports.info = msg => {
|
|
console.log(format(chalk.bgBlue.black(' INFO '), msg))
|
|
}
|
|
|
|
exports.done = msg => {
|
|
console.log(format(chalk.bgGreen.black(' DONE '), msg))
|
|
}
|
|
|
|
exports.warn = msg => {
|
|
console.warn(format(chalk.bgYellow.black(' WARN '), chalk.yellow(msg)))
|
|
}
|
|
|
|
exports.error = msg => {
|
|
console.error(format(chalk.bgRed(' ERROR '), chalk.red(msg)))
|
|
if (msg instanceof Error) {
|
|
console.error(msg.stack)
|
|
}
|
|
}
|
|
|
|
exports.clearConsole = title => {
|
|
if (process.stdout.isTTY) {
|
|
const blank = '\n'.repeat(process.stdout.rows)
|
|
console.log(blank)
|
|
readline.cursorTo(process.stdout, 0, 0)
|
|
readline.clearScreenDown(process.stdout)
|
|
if (title) {
|
|
console.log(title)
|
|
}
|
|
}
|
|
}
|
|
|
|
exports.hasYarn = (() => {
|
|
if (process.env.VUE_CLI_TEST) {
|
|
return true
|
|
}
|
|
try {
|
|
execSync('yarnpkg --version', { stdio: 'ignore' })
|
|
return true
|
|
} catch (e) {
|
|
return false
|
|
}
|
|
})()
|
|
|
|
exports.hasGit = () => {
|
|
if (process.env.VUE_CLI_TEST) {
|
|
return true
|
|
}
|
|
try {
|
|
execSync('git --version', { stdio: 'ignore' })
|
|
return true
|
|
} catch (e) {
|
|
return false
|
|
}
|
|
}
|