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
|
let consoleSpied = false
|
||||||
|
|
||||||
|
const silentConsole = {}
|
||||||
|
const originalConsole = {}
|
||||||
const consoleQueue = {
|
const consoleQueue = {
|
||||||
log: [],
|
log: [],
|
||||||
|
warn: [],
|
||||||
error: []
|
error: []
|
||||||
}
|
}
|
||||||
|
|
||||||
const silentConsole = {
|
// level: log, warn, error
|
||||||
log: (...args) => consoleQueue.log.push(args),
|
Object.keys(consoleQueue).forEach((level) => {
|
||||||
error: (...args) => consoleQueue.error.push(args)
|
silentConsole[level] = (...args) => consoleQueue[level].push(args)
|
||||||
}
|
originalConsole[level] = console[level] // eslint-disable-line no-console
|
||||||
|
})
|
||||||
|
|
||||||
const muteConsole = () => {
|
const muteConsole = () => {
|
||||||
if (consoleSpied) return
|
if (consoleSpied) return
|
||||||
@ -47,22 +51,15 @@ const muteConsole = () => {
|
|||||||
Object.assign(console, silentConsole)
|
Object.assign(console, silentConsole)
|
||||||
}
|
}
|
||||||
|
|
||||||
const originalConsole = {
|
|
||||||
log: console.log, // eslint-disable-line no-console
|
|
||||||
error: console.error // eslint-disable-line no-console
|
|
||||||
}
|
|
||||||
|
|
||||||
const restoreConsole = () => {
|
const restoreConsole = () => {
|
||||||
if (!consoleSpied) return
|
if (!consoleSpied) return
|
||||||
consoleSpied = false
|
consoleSpied = false
|
||||||
|
|
||||||
Object.assign(console, originalConsole)
|
Object.assign(console, originalConsole)
|
||||||
|
|
||||||
const l = consoleQueue.log
|
// level: log, warn, error
|
||||||
consoleQueue.log = []
|
for (let level in consoleQueue) {
|
||||||
l.forEach(args => console.log(...args)) // eslint-disable-line no-console
|
consoleQueue[level].forEach(args => console[level](...args)) // eslint-disable-line no-console
|
||||||
|
consoleQueue[level] = []
|
||||||
const e = consoleQueue.error
|
}
|
||||||
consoleQueue.error = []
|
|
||||||
e.forEach(args => console.error(...args)) // eslint-disable-line no-console
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user