-
Notifications
You must be signed in to change notification settings - Fork 135
Expand file tree
/
Copy pathLogUtils.js
More file actions
52 lines (43 loc) · 1.13 KB
/
LogUtils.js
File metadata and controls
52 lines (43 loc) · 1.13 KB
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
/*eslint no-console: 0*/
import prompt from 'prompt'
import { red, yellow, green } from 'cli-color'
function logWithColor(color, msgs) {
console.log(...[ color('[react-project]') ].concat(msgs))
}
export function log(...msgs) {
console.log(...[ '[react-project]' ].concat(msgs))
}
export function logError(...msgs) {
logWithColor(red, msgs)
}
//weiweiwowo
export function logPrompt(...msgs) {
logWithColor(yellow, msgs)
}
export function logTask(...msgs) {
logWithColor(green, msgs)
}
export function promptApproval(msg, cb) {
if (process.env.NODE_ENV === 'test' || process.env.NODE_ENV === 'production') {
logError('Wanted to prompt approval but skipping because we are in production or test')
log('Prompt message was: ', msg)
cb()
} else {
prompt.start()
const property = {
name: 'yesno',
message: msg + ' (y|n)',
validator: /y|n/,
warning: 'Must respond "y" for yes or "n" for no',
default: 'n'
}
prompt.get(property, (err, result) => {
if (result.yesno === 'y') {
cb && cb()
} else {
logError('FINE!')
process.exit()
}
})
}
}