-
Notifications
You must be signed in to change notification settings - Fork 12
/
post-install.js
61 lines (48 loc) · 1.52 KB
/
post-install.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* eslint-disable */
const chalk = require('chalk')
const { execSync } = require('child_process')
const isWin32 = process.platform === 'win32'
const print = (color = null) => (str = '') => {
const terminalCols = retrieveCols()
const strLength = str.replace(/\u001B\[[0-9]{2}m/g, '').length
const leftPaddingLength = Math.floor((terminalCols - strLength) / 2)
const leftPadding = ' '.repeat(Math.max(leftPaddingLength, 0))
if (color) {
str = chalk[color](str)
}
console.log(leftPadding, str)
}
const retrieveCols = (() => {
let result = false
return () => {
if (result) {
return result
}
const defaultCols = 80
try {
const terminalCols = execSync('tput cols', { stdio: ['pipe', 'pipe', 'ignore'] })
result = parseInt(terminalCols.toString()) || defaultCols
} catch (e) {
result = defaultCols
}
return result
}
})()
// 只在 osx 系统上展示 emoji
const emoji = (emoji) => (process.stdout.isTTY && !isWin32 ? emoji : '')
function printFooter() {
const yellow = print('yellow')
// const yellow = str => console.log(chalk.yellow(str))
const emptyLine = print()
emptyLine()
yellow('了解如何使用 CloudBase CLI')
yellow('请查看使用文档')
print()(
' '.repeat(15) +
`${chalk.bold(emoji('👉'))} ${chalk.underline(
'https://docs.cloudbase.net/cli-v1/quick-start.html'
)}`
)
emptyLine()
}
printFooter()