UNPKG

1.26 kBJavaScriptView Raw
1const ora = require('ora');
2
3const Reporter = require('./Reporter');
4
5module.exports = class BasicReporter extends Reporter {
6 constructor(...args) {
7 super(...args);
8
9 this.spinner = ora({ spinner: 'toggle6' });
10 }
11
12 // TODO: create proper testing for this with a large build an stdout hooks.
13 /* istanbul ignore next */
14 progress(data) {
15 if (!this.spinner.isSpinning && data.step.percentage < 1) {
16 this.spinner.start(data.step.name);
17 }
18
19 const { name, modulePosition, totalModules } = data.step;
20 const percent = Math.floor(data.step.percentage * 100);
21
22 if (modulePosition) {
23 this.spinner.text = `${percent}% ${modulePosition}/${totalModules} ${name} ${data.fileName}`;
24 } else {
25 this.spinner.text = `${percent} ${name} ${data.scope}`;
26 }
27
28 if (data.step.percentage >= 1) {
29 this.spinner.stop();
30 }
31 }
32
33 render(error, stats) {
34 const { log } = console;
35
36 if (error) {
37 return error;
38 }
39
40 const compilers = this.compiler.compilers || [this.compiler];
41
42 const targetCompiler = compilers.find((comp) => !!comp.options.stats);
43 const { options } = targetCompiler || { options: {} };
44 const result = stats.toString(options.stats);
45
46 log(result);
47
48 return result;
49 }
50};