mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
refactor: make progress plugin more dynamic for adding log type
This commit is contained in:
parent
061718c66d
commit
354cf88a97
@ -30,15 +30,19 @@ module.exports = function ProgressPlugin({ color, pcolor, title }) {
|
||||
|
||||
let consoleSpied = false
|
||||
|
||||
const silentConsole = {}
|
||||
const originalConsole = {}
|
||||
const consoleQueue = {
|
||||
log: [],
|
||||
warn: [],
|
||||
error: []
|
||||
}
|
||||
|
||||
const silentConsole = {
|
||||
log: (...args) => consoleQueue.log.push(args),
|
||||
error: (...args) => consoleQueue.error.push(args)
|
||||
}
|
||||
// level: log, warn, error
|
||||
Object.keys(consoleQueue).forEach((level) => {
|
||||
silentConsole[level] = (...args) => consoleQueue[level].push(args)
|
||||
originalConsole[level] = console[level] // eslint-disable-line no-console
|
||||
})
|
||||
|
||||
const muteConsole = () => {
|
||||
if (consoleSpied) return
|
||||
@ -47,22 +51,15 @@ const muteConsole = () => {
|
||||
Object.assign(console, silentConsole)
|
||||
}
|
||||
|
||||
const originalConsole = {
|
||||
log: console.log, // eslint-disable-line no-console
|
||||
error: console.error // eslint-disable-line no-console
|
||||
}
|
||||
|
||||
const restoreConsole = () => {
|
||||
if (!consoleSpied) return
|
||||
consoleSpied = false
|
||||
|
||||
Object.assign(console, originalConsole)
|
||||
|
||||
const l = consoleQueue.log
|
||||
consoleQueue.log = []
|
||||
l.forEach(args => console.log(...args)) // eslint-disable-line no-console
|
||||
|
||||
const e = consoleQueue.error
|
||||
consoleQueue.error = []
|
||||
e.forEach(args => console.error(...args)) // eslint-disable-line no-console
|
||||
// level: log, warn, error
|
||||
for (let level in consoleQueue) {
|
||||
consoleQueue[level].forEach(args => console[level](...args)) // eslint-disable-line no-console
|
||||
consoleQueue[level] = []
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user