forked from brave/brave-browser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogging.js
More file actions
62 lines (51 loc) · 1.5 KB
/
logging.js
File metadata and controls
62 lines (51 loc) · 1.5 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
52
53
54
55
56
57
58
59
60
61
62
// Copyright (c) 2019 The Brave Authors. All rights reserved.
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// you can obtain one at http://mozilla.org/MPL/2.0/.
const os = require('os')
const chalk = require('chalk')
const logUpdate = require('log-update')
let divider
function setLineLength () {
divider = Array(process.stdout.columns || 32).join('-')
}
setLineLength()
process.stdout.on('resize', setLineLength)
const progressStyle = chalk.bold.inverse
const statusStyle = chalk.green.italic
const warningStyle = chalk.black.bold.bgYellow
const cmdDirStyle = chalk.blue
const cmdCmdStyle = chalk.green
const cmdArrowStyle = chalk.magenta
function progress (message) {
console.log(progressStyle(message))
}
function status(message) {
console.log(statusStyle(message))
}
function error (message) {
console.error(progressStyle(message))
}
function warn (message) {
console.error(warningStyle(message))
}
function updateStatus (projectUpdateStatus) {
const statusLines = Object.values(projectUpdateStatus).map(entry =>
`${chalk.bold(entry.name)} (${entry.ref}): ${chalk.green.italic(entry.phase)}`
)
logUpdate(statusLines.join(os.EOL))
}
function command (dir, cmd, args) {
console.log(divider)
if (dir)
console.log(cmdDirStyle(dir))
console.log(`${cmdArrowStyle('>')} ${cmdCmdStyle(cmd)} ${args.join(' ')}`)
}
module.exports = {
progress,
status,
error,
warn,
command,
updateStatus
}