1 | const ora = require('ora');
|
2 |
|
3 | const Reporter = require('./Reporter');
|
4 |
|
5 | module.exports = class BasicReporter extends Reporter {
|
6 | constructor(...args) {
|
7 | super(...args);
|
8 |
|
9 | this.spinner = ora({ spinner: 'toggle6' });
|
10 | }
|
11 |
|
12 |
|
13 |
|
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} ${
|
24 | data.fileName
|
25 | }`;
|
26 | } else {
|
27 | this.spinner.text = `${percent} ${name} ${data.scope}`;
|
28 | }
|
29 |
|
30 | if (data.step.percentage >= 1) {
|
31 | this.spinner.stop();
|
32 | }
|
33 | }
|
34 |
|
35 | render(error, stats) {
|
36 | const { log } = console;
|
37 |
|
38 | if (error) {
|
39 | return error;
|
40 | }
|
41 |
|
42 | const compilers = this.compiler.compilers || [this.compiler];
|
43 |
|
44 | const targetCompiler = compilers.find((comp) => !!comp.options.stats);
|
45 | const { options } = targetCompiler || { options: {} };
|
46 | const result = stats.toString(options.stats);
|
47 |
|
48 | log(result);
|
49 |
|
50 | return result;
|
51 | }
|
52 | };
|