mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +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)
|
||||
|
||||
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(' ')
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user