<commit_before>const { ProgressPlugin } = require('webpack')
const throttle = require('lodash.throttle')
const { green, grey } = require('chalk')
const log = require('../helpers/logger')('app:progress')
const logUpdate = require('log-update')
const ms = require('ms')

const isMinimalTerminal = require('../helpers/is-minimal-terminal')
const logLine = isMinimalTerminal
  ? () => {}
  : logUpdate.create(process.stdout, { showCursor: true })

const compilations = {}
const barLength = 25
const barItems = Array.apply(null, { length: barLength })

let maxLengthName = 0

function isRunningGlobally () {
  return Object.values(compilations).find(c => c.running) !== void 0
}

function renderBar (progress, color) {
  const width = progress * (barLength / 100)

  return barItems
    .map((_, index) => index < width ? '█' : ' ')
    .join('')
}

function printState () {
  const lines = Object.values(compilations).map(state => {
    return [
      ' ' + green( state.name.padEnd(maxLengthName) + ' ' + renderBar(state.progress)),
      state.msg,
      `[${state.progress}%]`.padStart(4),
      state.running
        ? grey(state.details
            ? [ state.details[0], state.details[1] ].filter(s => s).join(' ')
            : ''
        )
        : state.doneStamp
    ].filter(m => m).join(' ') + '\n'
  })

  logLine('\n' + lines.join(''))
}

const render = throttle(printState, 200)

module.exports = class WebpackProgress extends ProgressPlugin {
  constructor (opts = {}) {
    super({
      handler: (percent, msg, ...details) => {
        this.updateProgress(percent, msg, details)
      }
    })<commit_msg>feat(app): fun with gradient colored build progress bar<commit_after>const { ProgressPlugin } = require('webpack')
const throttle = require('lodash.throttle')
const chalk = require('chalk')
const log = require('../helpers/logger')('app:progress')
const logUpdate = require('log-update')
const ms = require('ms')

const isMinimalTerminal = require('../helpers/is-minimal-terminal')
const logLine = isMinimalTerminal
  ? () => {}
  : logUpdate.create(process.stdout, { showCursor: true })

const compilations = {}
const barLength = 20
const barColors = Array.apply(null, { length: barLength })
  .map((_, index) => {
    const p = index / barLength

    return p <= 0.5
      ? chalk.rgb(
          255,
          Math.round(p * 510),
          0
        )
      : chalk.rgb(
        255 - Math.round(p * 122),
        255,
        0
      )
  })

let maxLengthName = 0

function isRunningGlobally () {
  return Object.values(compilations).find(c => c.running) !== void 0
}

function renderBar (progress) {
  const width = progress * (barLength / 100)

  return barColors
    .map((color, index) => index < width ? color('█') : ' ')
    .join('')
}

function printState () {
  const lines = Object.values(compilations).map(state => {
    return [
      ' ' + chalk.green(state.name.padEnd(maxLengthName)) + ' ' + renderBar(state.progress),
      state.msg,
      `[${state.progress}%]`.padStart(4),
      state.running
        ? chalk.grey(state.details
            ? [ state.details[0], state.details[1] ].filter(s => s).join(' ')
            : ''
        )
        : state.doneStamp
    ].filter(m => m).join(' ') + '\n'
  })

  logLine('\n' + lines.join(''))
}

const render = throttle(printState, 200)

module.exports = class WebpackProgress extends ProgressPlugin {
  constructor (opts = {}) {
    super({
      handler: (percent, msg, ...details) => {
        this.updateProgress(percent, msg, details)
      }
    })
{'fraction_non_alphanumeric': 0.16638418079096046, 'fraction_numerical': 0.012711864406779662, 'mean_word_length': 2.974186307519641, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6626353', 'n_tokens_mistral': 1161, 'n_tokens_neox': 1110, 'n_words': 238}