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
87 lines (78 loc) · 2.59 KB
/
logging.js
File metadata and controls
87 lines (78 loc) · 2.59 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// 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')
const GitPatcher = require('../gitPatcher')
let divider
function setLineLength () {
divider = Array(process.stdout.columns || 32).join('-')
}
setLineLength()
process.stdout.on('resize', setLineLength)
const progressStyle = chalk.bold.inverse
function progressLog (message) {
console.log(progressStyle(message))
}
function errorLog (message) {
console.error(progressStyle(message))
}
function logUpdateStatus (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 logAllPatchStatus(allPatchStatus, patchGroupName) {
if (!allPatchStatus.length) {
console.log(chalk.bold.italic(`There were no ${patchGroupName} code patch updates to apply.`))
} else {
const successfulPatches = []
const failedPatches = []
for (const patchStatus of allPatchStatus) {
if (!patchStatus.error) {
successfulPatches.push(patchStatus)
} else {
failedPatches.push(patchStatus)
}
}
console.log(chalk.bold(`There were ${allPatchStatus.length} ${patchGroupName} code patch updates to apply.`))
if (successfulPatches.length) {
console.log(chalk.green(`${successfulPatches.length} successful patches:`))
successfulPatches.forEach(logPatchStatus)
}
if (failedPatches.length) {
console.log(chalk.red(`${failedPatches.length} failed patches:`))
failedPatches.forEach(logPatchStatus)
}
}
}
function logPatchStatus ({ reason, path, patchPath, error, warning }) {
const success = !error
const statusColor = success ? chalk.green : chalk.red
console.log(statusColor.bold.underline(path || patchPath))
console.log(` - Patch applied because: ${GitPatcher.patchApplyReasonMessages[reason]}`)
if (error) {
console.log(chalk.red(` - Error - ${error.message}`))
}
if (warning) {
console.warn(chalk.yellow(` - Warning - ${warning}`))
}
if (error) {
if (error.stdout) {
console.log(chalk.blue(error.stdout))
}
if (error.stderr) {
console.error(chalk.red(error.stderr))
}
}
console.log(divider)
}
module.exports = {
progressLog,
errorLog,
logUpdateStatus,
logAllPatchStatus
}