mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-30 09:27:13 +00:00
imrpove progress
This commit is contained in:
parent
b27efd9e61
commit
2c6ee92c45
@ -31,39 +31,53 @@ module.exports = class ProgressPlugin extends webpack.ProgressPlugin {
|
|||||||
const progress = Math.floor(percent * 100)
|
const progress = Math.floor(percent * 100)
|
||||||
|
|
||||||
this.state.progress = progress
|
this.state.progress = progress
|
||||||
this.state.succeed =
|
|
||||||
this.state.msg = msg
|
this.state.msg = msg
|
||||||
|
|
||||||
// Update spinner using shared state
|
// Process all states
|
||||||
let isInProgress = false
|
let inProgress = false
|
||||||
const width = 25
|
|
||||||
let line = _.range(width).fill(chalk.white(BLOCK_CHAR))
|
|
||||||
let additional = []
|
|
||||||
|
|
||||||
Object.keys(sharedState).forEach(name => {
|
const additional = []
|
||||||
|
|
||||||
|
const bars = Object.keys(sharedState).map(name => {
|
||||||
const state = sharedState[name]
|
const state = sharedState[name]
|
||||||
|
|
||||||
if (state.progress >= 100) {
|
if (state.progress < 100) {
|
||||||
return
|
inProgress = true
|
||||||
}
|
}
|
||||||
|
|
||||||
isInProgress = true
|
const blockChar = chalk.keyword(state.color)(BLOCK_CHAR)
|
||||||
|
|
||||||
const w = state.progress * (width / 100)
|
additional.push(`${blockChar} ${name}(${state.progress}%) `)
|
||||||
const b = chalk.keyword(state.color)(BLOCK_CHAR)
|
|
||||||
|
|
||||||
for (let i = 0; i < w; i++) {
|
return {
|
||||||
line[i] = b
|
name,
|
||||||
|
color: state.color,
|
||||||
|
progress: state.progress,
|
||||||
|
blockChar: chalk.keyword(state.color)(BLOCK_CHAR)
|
||||||
}
|
}
|
||||||
|
|
||||||
additional.push(`${b} ${name} (${state.progress}%) `)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if (isInProgress) {
|
if (!inProgress) {
|
||||||
this.spinner.start()
|
|
||||||
this.spinner.text = 'Compiling ' + line.join('') + ' ' + additional.join(' ')
|
|
||||||
} else {
|
|
||||||
this.spinner.succeed('Compiled ' + this.options.name)
|
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(' ')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user