1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 |
|
7 | var _toConsumableArray2;
|
8 |
|
9 | function _load_toConsumableArray() {
|
10 | return _toConsumableArray2 = _interopRequireDefault(require('babel-runtime/helpers/toConsumableArray'));
|
11 | }
|
12 |
|
13 | var _chalk;
|
14 |
|
15 | function _load_chalk() {
|
16 | return _chalk = _interopRequireDefault(require('chalk'));
|
17 | }
|
18 |
|
19 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
20 |
|
21 | var _bundleProgressBar = void 0;
|
22 |
|
23 | var _printNewLineBeforeNextLog = false;
|
24 | var _isLastLineNewLine = false;
|
25 | function _updateIsLastLineNewLine(args) {
|
26 | if (args.length === 0) {
|
27 | _isLastLineNewLine = true;
|
28 | } else {
|
29 | var lastArg = args[args.length - 1];
|
30 | if (typeof lastArg === 'string' && (lastArg === '' || lastArg.match(/[\r\n]$/))) {
|
31 | _isLastLineNewLine = true;
|
32 | } else {
|
33 | _isLastLineNewLine = false;
|
34 | }
|
35 | }
|
36 | }
|
37 |
|
38 | function _maybePrintNewLine() {
|
39 | if (_printNewLineBeforeNextLog) {
|
40 | _printNewLineBeforeNextLog = false;
|
41 | console.log();
|
42 | }
|
43 | }
|
44 |
|
45 | function consoleLog() {
|
46 | var _console;
|
47 |
|
48 | _maybePrintNewLine();
|
49 |
|
50 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
51 | args[_key] = arguments[_key];
|
52 | }
|
53 |
|
54 | _updateIsLastLineNewLine(args);
|
55 |
|
56 | (_console = console).log.apply(_console, args);
|
57 | }
|
58 |
|
59 | function consoleWarn() {
|
60 | var _console2;
|
61 |
|
62 | _maybePrintNewLine();
|
63 |
|
64 | for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
65 | args[_key2] = arguments[_key2];
|
66 | }
|
67 |
|
68 | _updateIsLastLineNewLine(args);
|
69 |
|
70 | (_console2 = console).warn.apply(_console2, args);
|
71 | }
|
72 |
|
73 | function consoleError() {
|
74 | var _console3;
|
75 |
|
76 | _maybePrintNewLine();
|
77 |
|
78 | for (var _len3 = arguments.length, args = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
79 | args[_key3] = arguments[_key3];
|
80 | }
|
81 |
|
82 | _updateIsLastLineNewLine(args);
|
83 |
|
84 | (_console3 = console).error.apply(_console3, args);
|
85 | }
|
86 |
|
87 | function respectProgressBars(commitLogs) {
|
88 | if (_bundleProgressBar) {
|
89 | _bundleProgressBar.terminate();
|
90 | _bundleProgressBar.lastDraw = '';
|
91 | commitLogs();
|
92 | _bundleProgressBar.render();
|
93 | } else {
|
94 | commitLogs();
|
95 | }
|
96 | }
|
97 |
|
98 | function getPrefix(chalkColor) {
|
99 | return chalkColor('[' + new Date().toTimeString().slice(0, 8) + ']');
|
100 | }
|
101 |
|
102 | function withPrefixAndTextColor(args) {
|
103 | var chalkColor = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : (_chalk || _load_chalk()).default.gray;
|
104 |
|
105 | return [getPrefix(chalkColor)].concat((0, (_toConsumableArray2 || _load_toConsumableArray()).default)(args.map(function (arg) {
|
106 | return chalkColor(arg);
|
107 | })));
|
108 | }
|
109 |
|
110 | function withPrefix(args) {
|
111 | var chalkColor = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : (_chalk || _load_chalk()).default.gray;
|
112 |
|
113 | return [getPrefix(chalkColor)].concat((0, (_toConsumableArray2 || _load_toConsumableArray()).default)(args));
|
114 | }
|
115 |
|
116 | function log() {
|
117 | for (var _len4 = arguments.length, args = Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
118 | args[_key4] = arguments[_key4];
|
119 | }
|
120 |
|
121 | if (log.config.raw) {
|
122 | return;
|
123 | }
|
124 |
|
125 | respectProgressBars(function () {
|
126 | consoleLog.apply(undefined, (0, (_toConsumableArray2 || _load_toConsumableArray()).default)(withPrefix(args)));
|
127 | });
|
128 | }
|
129 |
|
130 | log.nested = function (message) {
|
131 | respectProgressBars(function () {
|
132 | consoleLog(message);
|
133 | });
|
134 | };
|
135 |
|
136 | log.newLine = function newLine() {
|
137 | respectProgressBars(function () {
|
138 | consoleLog();
|
139 | });
|
140 | };
|
141 |
|
142 | log.addNewLineIfNone = function addNewLineIfNone() {
|
143 | if (!_isLastLineNewLine && !_printNewLineBeforeNextLog) {
|
144 | log.newLine();
|
145 | }
|
146 | };
|
147 |
|
148 | log.printNewLineBeforeNextLog = function printNewLineBeforeNextLog() {
|
149 | _printNewLineBeforeNextLog = true;
|
150 | };
|
151 |
|
152 | log.setBundleProgressBar = function setBundleProgressBar(bar) {
|
153 | _bundleProgressBar = bar;
|
154 | };
|
155 |
|
156 | log.error = function error() {
|
157 | for (var _len5 = arguments.length, args = Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
|
158 | args[_key5] = arguments[_key5];
|
159 | }
|
160 |
|
161 | if (log.config.raw) {
|
162 | return;
|
163 | }
|
164 |
|
165 | respectProgressBars(function () {
|
166 | consoleError.apply(undefined, (0, (_toConsumableArray2 || _load_toConsumableArray()).default)(withPrefixAndTextColor(args, (_chalk || _load_chalk()).default.red)));
|
167 | });
|
168 | };
|
169 |
|
170 | log.nestedError = function (message) {
|
171 | respectProgressBars(function () {
|
172 | consoleError((_chalk || _load_chalk()).default.red(message));
|
173 | });
|
174 | };
|
175 |
|
176 | log.warn = function warn() {
|
177 | for (var _len6 = arguments.length, args = Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
|
178 | args[_key6] = arguments[_key6];
|
179 | }
|
180 |
|
181 | if (log.config.raw) {
|
182 | return;
|
183 | }
|
184 |
|
185 | respectProgressBars(function () {
|
186 | consoleWarn.apply(undefined, (0, (_toConsumableArray2 || _load_toConsumableArray()).default)(withPrefixAndTextColor(args, (_chalk || _load_chalk()).default.yellow)));
|
187 | });
|
188 | };
|
189 |
|
190 | log.nestedWarn = function (message) {
|
191 | respectProgressBars(function () {
|
192 | consoleWarn((_chalk || _load_chalk()).default.yellow(message));
|
193 | });
|
194 | };
|
195 |
|
196 | log.gray = function () {
|
197 | for (var _len7 = arguments.length, args = Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
|
198 | args[_key7] = arguments[_key7];
|
199 | }
|
200 |
|
201 | if (log.config.raw) {
|
202 | return;
|
203 | }
|
204 |
|
205 | respectProgressBars(function () {
|
206 | consoleLog.apply(undefined, (0, (_toConsumableArray2 || _load_toConsumableArray()).default)(withPrefixAndTextColor(args)));
|
207 | });
|
208 | };
|
209 |
|
210 | log.raw = function () {
|
211 | for (var _len8 = arguments.length, args = Array(_len8), _key8 = 0; _key8 < _len8; _key8++) {
|
212 | args[_key8] = arguments[_key8];
|
213 | }
|
214 |
|
215 | if (!log.config.raw) {
|
216 | return;
|
217 | }
|
218 |
|
219 | respectProgressBars(function () {
|
220 | consoleLog.apply(undefined, args);
|
221 | });
|
222 | };
|
223 |
|
224 | log.chalk = (_chalk || _load_chalk()).default;
|
225 |
|
226 | log.config = {
|
227 | raw: false
|
228 | };
|
229 |
|
230 | exports.default = log;
|
231 | module.exports = exports['default'];
|
232 |
|