imrpove progress

This commit is contained in:
Pooya Parsa 2018-03-13 14:33:01 +03:30
parent b27efd9e61
commit 2c6ee92c45

View File

@ -31,39 +31,53 @@ module.exports = class ProgressPlugin extends webpack.ProgressPlugin {
const progress = Math.floor(percent * 100)
this.state.progress = progress
this.state.succeed =
this.state.msg = msg
// Update spinner using shared state
let isInProgress = false
const width = 25
let line = _.range(width).fill(chalk.white(BLOCK_CHAR))
let additional = []
// Process all states
let inProgress = false
Object.keys(sharedState).forEach(name => {
const additional = []
const bars = Object.keys(sharedState).map(name => {
const state = sharedState[name]
if (state.progress >= 100) {
return
if (state.progress < 100) {
inProgress = true
}
isInProgress = true
const blockChar = chalk.keyword(state.color)(BLOCK_CHAR)
const w = state.progress * (width / 100)
const b = chalk.keyword(state.color)(BLOCK_CHAR)
additional.push(`${blockChar} ${name}(${state.progress}%) `)
for (let i = 0; i < w; i++) {
line[i] = b
return {
name,
color: state.color,
progress: state.progress,
blockChar: chalk.keyword(state.color)(BLOCK_CHAR)
}
additional.push(`${b} ${name} (${state.progress}%) `)
})
if (isInProgress) {
this.spinner.start()
this.spinner.text = 'Compiling ' + line.join('') + ' ' + additional.join(' ')
} else {
if (!inProgress) {
this.spinner.succeed('Compiled ' + this.options.name)
return
}
// Generate progressbars
const width = 25
const progressbars = _.range(width).fill(chalk.white(BLOCK_CHAR))
_.sortBy(bars, 'progress').reverse().forEach(bar => {
const w = bar.progress * (width / 100)
for (let i = 0; i < w; i++) {
progressbars[i] = bar.blockChar
}
})
// Update spinner
this.spinner.start()
this.spinner.text = 'Compiling ' + progressbars.join('') + ' ' + additional.join(' ')
}
}