improve progress

This commit is contained in:
Pooya Parsa 2018-03-13 12:15:46 +03:30
parent 1a0d263180
commit fab9b44890

View File

@ -1,17 +1,11 @@
const ProgressBar = require('node-progress-bars') const ProgressBar = require('node-progress-bars')
const webpack = require('webpack') const webpack = require('webpack')
const throttle = require('lodash/debounce') const throttle = require('lodash/throttle')
module.exports = class ProgressPlugin extends webpack.ProgressPlugin { module.exports = class ProgressPlugin extends webpack.ProgressPlugin {
constructor(options) { constructor(options) {
super(options) super(options)
if (typeof options === 'function') {
options = {
handler: options
}
}
this.handler = (percent, msg) => this.updateProgress(percent, msg) this.handler = (percent, msg) => this.updateProgress(percent, msg)
this.options = options || {} this.options = options || {}
@ -21,9 +15,6 @@ module.exports = class ProgressPlugin extends webpack.ProgressPlugin {
// BUG: plugin.appy is being called twice! // BUG: plugin.appy is being called twice!
// So initialize progress here // So initialize progress here
this.startProgress() this.startProgress()
this.lastPrgoress = 0
this.lastMsg = ''
} }
updateProgress(percent, msg) { updateProgress(percent, msg) {
@ -31,15 +22,6 @@ module.exports = class ProgressPlugin extends webpack.ProgressPlugin {
this.startProgress() this.startProgress()
} }
const progress = Math.floor(percent * 100)
if (progress === this.lastPrgoress || msg === this.lastMsg) {
return
}
this.lastPrgoress = progress
this.lastMsg = msg
if (percent === 1) { if (percent === 1) {
this.stopProgress() this.stopProgress()
return return
@ -75,50 +57,3 @@ module.exports = class ProgressPlugin extends webpack.ProgressPlugin {
this.bar = undefined this.bar = undefined
} }
} }
// -----------------------------------------------------------
// Shared console utils
// -----------------------------------------------------------
// let consoleSpied = 0
// const silentConsole = {}
// const originalConsole = {}
// const consoleQueue = {
// log: [],
// warn: [],
// error: []
// }
// // 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 = () => {
// // eslint-disable-next-line no-console
// if (console.spiedInTest) {
// return
// }
// consoleSpied++
// Object.assign(console, silentConsole)
// }
// const restoreConsole = () => {
// if (consoleSpied === 0) {
// return
// }
// consoleSpied--
// Object.assign(console, originalConsole)
// // level: log, warn, error
// for (let level in consoleQueue) {
// const q = consoleQueue[level]
// consoleQueue[level] = []
// q.forEach(args => console[level](...args)) // eslint-disable-line no-console
// }
// }