1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.MultiProgress = undefined;
|
7 |
|
8 | var _progressEx;
|
9 |
|
10 | function _load_progressEx() {
|
11 | return _progressEx = _interopRequireDefault(require("progress-ex"));
|
12 | }
|
13 |
|
14 | var _log;
|
15 |
|
16 | function _load_log() {
|
17 | return _log = require("electron-builder-util/out/log");
|
18 | }
|
19 |
|
20 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
21 |
|
22 | class MultiProgress {
|
23 | constructor() {
|
24 | this.stream = process.stdout;
|
25 | this.cursor = 0;
|
26 | this.totalLines = 0;
|
27 | this.isLogListenerAdded = false;
|
28 | this.barCount = 0;
|
29 | }
|
30 | createBar(format, options) {
|
31 | options.stream = this.stream;
|
32 | const bar = new (_progressEx || _load_progressEx()).default(format, options);
|
33 | this.barCount++;
|
34 | let index = -1;
|
35 | const render = bar.render;
|
36 | bar.render = tokens => {
|
37 | if (index === -1) {
|
38 | index = this.totalLines;
|
39 | this.allocateLines(1);
|
40 | } else {
|
41 | this.moveCursor(index);
|
42 | }
|
43 | render.call(bar, tokens);
|
44 | if (!this.isLogListenerAdded) {
|
45 | this.isLogListenerAdded = true;
|
46 | (0, (_log || _load_log()).setPrinter)(message => {
|
47 | let newLineCount = 0;
|
48 | let newLineIndex = message.indexOf("\n");
|
49 | while (newLineIndex > -1) {
|
50 | newLineCount++;
|
51 | newLineIndex = message.indexOf("\n", ++newLineIndex);
|
52 | }
|
53 | this.allocateLines(newLineCount + 1);
|
54 | this.stream.write(message);
|
55 | });
|
56 | }
|
57 | };
|
58 | bar.terminate = () => {
|
59 | this.barCount--;
|
60 | if (this.barCount === 0 && this.totalLines > 0) {
|
61 | this.allocateLines(1);
|
62 | this.totalLines = 0;
|
63 | this.cursor = 0;
|
64 | (0, (_log || _load_log()).setPrinter)(null);
|
65 | this.isLogListenerAdded = false;
|
66 | }
|
67 | };
|
68 | bar.tick = (len, tokens) => {
|
69 | if (len !== 0) {
|
70 | len = len || 1;
|
71 | }
|
72 | if (tokens != null) {
|
73 | bar.tokens = tokens;
|
74 | }
|
75 |
|
76 | if (bar.curr == 0) {
|
77 | bar.start = new Date();
|
78 | }
|
79 | bar.curr += len;
|
80 | if (bar.complete) {
|
81 | return;
|
82 | }
|
83 | bar.render();
|
84 |
|
85 | if (bar.curr >= bar.total) {
|
86 | bar.complete = true;
|
87 | bar.terminate();
|
88 | bar.callback(this);
|
89 | }
|
90 | };
|
91 | return bar;
|
92 | }
|
93 | allocateLines(count) {
|
94 | this.stream.moveCursor(0, this.totalLines - 1);
|
95 |
|
96 | this.stream.write("\n");
|
97 | this.totalLines += count;
|
98 | this.cursor = this.totalLines - 1;
|
99 | }
|
100 | moveCursor(index) {
|
101 | this.stream.moveCursor(0, index - this.cursor);
|
102 | this.cursor = index;
|
103 | }
|
104 | terminate() {
|
105 | this.moveCursor(this.totalLines);
|
106 | this.stream.clearLine();
|
107 | this.stream.cursorTo(0);
|
108 | }
|
109 | }
|
110 | exports.MultiProgress = MultiProgress; |
\ | No newline at end of file |