|
1
|
|
|
'use strict' |
|
2
|
|
|
|
|
3
|
|
|
const ora = require('ora') |
|
4
|
|
|
const chalk = require('chalk') |
|
5
|
|
|
const format = require('util').format |
|
6
|
|
|
const eraseLine = require('ansi-escapes').eraseLine |
|
7
|
|
|
const slice = Array.prototype.slice |
|
8
|
|
|
|
|
9
|
|
|
var theme = { |
|
10
|
|
|
success: chalk.green, |
|
11
|
|
|
warn: chalk.yellow, |
|
12
|
|
|
yellow: chalk.yellow, |
|
13
|
|
|
err: chalk.red, |
|
14
|
|
|
errEmphasis: chalk.red.underline, |
|
15
|
|
|
info: chalk.underline.white, |
|
16
|
|
|
offset: chalk.italic, |
|
17
|
|
|
notice: chalk.underline |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
var themeChars = { |
|
21
|
|
|
notice: '', |
|
22
|
|
|
log: '•', |
|
23
|
|
|
err: '• ', |
|
24
|
|
|
warn: 'Warning: ', |
|
25
|
|
|
errEmphasis: '', |
|
26
|
|
|
success: '', |
|
27
|
|
|
offset: '', |
|
28
|
|
|
info: '', |
|
29
|
|
|
yellow: '' |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
function log () { |
|
33
|
|
|
var args = slice.call(arguments) |
|
34
|
|
|
var level = args.shift() |
|
35
|
|
|
|
|
36
|
|
|
args[0] = args[0] ? themeChars[level] + args[0] : '' |
|
37
|
|
|
args[0] = args[0] ? theme[level](args[0]) : '' |
|
38
|
|
|
console.log.apply(null, args) |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
function write () { |
|
42
|
|
|
var out = process.stdout |
|
43
|
|
|
var args = slice.call(arguments) |
|
44
|
|
|
var level = args.shift() |
|
45
|
|
|
|
|
46
|
|
|
out.write(theme[level](format.apply(null, [themeChars[level]].concat(args)))) |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
exports.log = function () { |
|
50
|
|
|
console.log.apply(null, [themeChars.log].concat(slice.call(arguments))) |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
exports.write = function (str) { |
|
54
|
|
|
process.stdout.write(str) |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
exports.newline = function () { |
|
58
|
|
|
process.stdout.write('\n') |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
exports.wait = function (msg) { |
|
62
|
|
|
var spinner = ora(chalk.gray(msg)) |
|
63
|
|
|
spinner.color = 'gray' |
|
64
|
|
|
spinner.start() |
|
65
|
|
|
|
|
66
|
|
|
return function () { |
|
67
|
|
|
spinner.stop() |
|
68
|
|
|
process.stdout.write(eraseLine) |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
exports.notice = exports.info = exports.err = exports.warn = function () { |
|
73
|
|
|
// will be overwritten later, only here for syntax completion |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
Object.keys(theme).forEach(function (level) { |
|
77
|
|
|
exports[level] = function () { |
|
78
|
|
|
log.apply(null, [level].concat(slice.call(arguments))) |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
var c = level[0].toUpperCase() |
|
82
|
|
|
exports['write' + c + level.slice(1)] = function () { |
|
83
|
|
|
write.apply(null, [level].concat(slice.call(arguments))) |
|
84
|
|
|
} |
|
85
|
|
|
}) |
|
86
|
|
|
|