How to show percent done in terminal
<p>Good day all.</p>

<p>Today i'm working in this complex script that makes request's to a site with server-side rendering, get's the HTML, breaks and grabs some data. The script has 4 phases: phaseOne, phaseTwo, phaseThree and phaseFour.</p>

<p>Which phases has a similar interface:</p>

<pre><code>class PhaseOne {
  constructor(MAP) {
    this.MAP = MAP || MAP;
  }

  // All code related with the phase here.
  process() {}
}
</code></pre>

<p>So i'm working upon this MAP object in all phases, and i'm calling each phase in a stack, like this:</p>

<pre><code>let phases = require('./phases');

[
  // 'Initial',
  'PhaseOne',
  'PhaseTwo',
  'PhaseThree',
  'PhaseFour',
].reduce((m, fn) =&gt; {
  return new phases[fn](m).process();
}, MAP);
</code></pre>

<p>Everything is working fine. My problem is: Some phases are REALLY slow.. all the program will take 30 minutes to finish.. and i would like to see in my terminal the percentage of each phase.</p>

<p>Like:</p>

<pre><code>PhaseOne: 10%
PhaseOne: 11%
PhaseOne: 12%
</code></pre>

<p>But i don't have any idea and i can't find a good tutorial to do that..</p>

<p>Currently inside my process functions i have for loops, if statements.. in general i'm using imperative style..</p>

<p>An example of PhaseOne:</p>

<pre><code>   // In this phase we need the property string in MAP.aguia01 to
    // assign the first context and extract the data with regex.
    if (typeof this.MAP.aguia01.string === 'undefined') {
      cli.fatal(
        'MAP doesn\'t have the necessary properties to run in Aguia01 phase. Exiting...'
      );
    }

    for (let month of months) {
      this.MAP.aguia01.string += requests.aguia01.apply(this, [month]);
    }

    for (let info of patterns.aguia01.infos) {
      this.MAP.aguia01.infos[info.name] = (
        this.MAP.aguia01.string.match(info.pattern)
      )[1];
    }

    for (let line of patterns.aguia01.lines) {
      this.MAP.aguia01.lines[line.name] = (
        this.MAP.aguia01.string.match(line.pattern)
      )[1];
    }
</code></pre>

<p>So.. Is it possible to do what i want with imperative style?</p>

<p>Thanks.</p>