UNPKG

13.9 kBJavaScriptView Raw
1"use strict";
2
3var cov_1ia30hret7 = function () {
4 var path = "/home/travis/build/commitizen/cz-cli/src/configLoader/getContent.js";
5 var hash = "dd54b9863cc28669094c54e487b6ac45b6fa0f1b";
6 var global = new Function("return this")();
7 var gcv = "__coverage__";
8 var coverageData = {
9 path: "/home/travis/build/commitizen/cz-cli/src/configLoader/getContent.js",
10 statementMap: {
11 "0": {
12 start: {
13 line: 20,
14 column: 23
15 },
16 end: {
17 line: 20,
18 column: 45
19 }
20 },
21 "1": {
22 start: {
23 line: 21,
24 column: 21
25 },
26 end: {
27 line: 21,
28 column: 75
29 }
30 },
31 "2": {
32 start: {
33 line: 22,
34 column: 23
35 },
36 end: {
37 line: 22,
38 column: 56
39 }
40 },
41 "3": {
42 start: {
43 line: 23,
44 column: 18
45 },
46 end: {
47 line: 25,
48 column: 40
49 }
50 },
51 "4": {
52 start: {
53 line: 24,
54 column: 20
55 },
56 end: {
57 line: 24,
58 column: 59
59 }
60 },
61 "5": {
62 start: {
63 line: 25,
64 column: 20
65 },
66 end: {
67 line: 25,
68 column: 40
69 }
70 },
71 "6": {
72 start: {
73 line: 27,
74 column: 4
75 },
76 end: {
77 line: 42,
78 column: 5
79 }
80 },
81 "7": {
82 start: {
83 line: 28,
84 column: 23
85 },
86 end: {
87 line: 28,
88 column: 40
89 }
90 },
91 "8": {
92 start: {
93 line: 30,
94 column: 8
95 },
96 end: {
97 line: 32,
98 column: 11
99 }
100 },
101 "9": {
102 start: {
103 line: 34,
104 column: 8
105 },
106 end: {
107 line: 34,
108 column: 22
109 }
110 },
111 "10": {
112 start: {
113 line: 36,
114 column: 8
115 },
116 end: {
117 line: 39,
118 column: 21
119 }
120 },
121 "11": {
122 start: {
123 line: 41,
124 column: 8
125 },
126 end: {
127 line: 41,
128 column: 20
129 }
130 },
131 "12": {
132 start: {
133 line: 52,
134 column: 4
135 },
136 end: {
137 line: 54,
138 column: 5
139 }
140 },
141 "13": {
142 start: {
143 line: 53,
144 column: 6
145 },
146 end: {
147 line: 53,
148 column: 13
149 }
150 },
151 "14": {
152 start: {
153 line: 56,
154 column: 25
155 },
156 end: {
157 line: 56,
158 column: 64
159 }
160 },
161 "15": {
162 start: {
163 line: 57,
164 column: 27
165 },
166 end: {
167 line: 57,
168 column: 54
169 }
170 },
171 "16": {
172 start: {
173 line: 59,
174 column: 4
175 },
176 end: {
177 line: 61,
178 column: 5
179 }
180 },
181 "17": {
182 start: {
183 line: 60,
184 column: 6
185 },
186 end: {
187 line: 60,
188 column: 47
189 }
190 },
191 "18": {
192 start: {
193 line: 63,
194 column: 20
195 },
196 end: {
197 line: 63,
198 column: 51
199 }
200 },
201 "19": {
202 start: {
203 line: 64,
204 column: 4
205 },
206 end: {
207 line: 64,
208 column: 56
209 }
210 },
211 "20": {
212 start: {
213 line: 75,
214 column: 22
215 },
216 end: {
217 line: 75,
218 column: 49
219 }
220 },
221 "21": {
222 start: {
223 line: 77,
224 column: 2
225 },
226 end: {
227 line: 79,
228 column: 3
229 }
230 },
231 "22": {
232 start: {
233 line: 78,
234 column: 4
235 },
236 end: {
237 line: 78,
238 column: 96
239 }
240 },
241 "23": {
242 start: {
243 line: 81,
244 column: 2
245 },
246 end: {
247 line: 81,
248 column: 50
249 }
250 }
251 },
252 fnMap: {
253 "0": {
254 name: "readConfigContent",
255 decl: {
256 start: {
257 line: 19,
258 column: 9
259 },
260 end: {
261 line: 19,
262 column: 26
263 }
264 },
265 loc: {
266 start: {
267 line: 19,
268 column: 40
269 },
270 end: {
271 line: 43,
272 column: 1
273 }
274 },
275 line: 19
276 },
277 "1": {
278 name: "(anonymous_1)",
279 decl: {
280 start: {
281 line: 24,
282 column: 6
283 },
284 end: {
285 line: 24,
286 column: 7
287 }
288 },
289 loc: {
290 start: {
291 line: 24,
292 column: 20
293 },
294 end: {
295 line: 24,
296 column: 59
297 }
298 },
299 line: 24
300 },
301 "2": {
302 name: "(anonymous_2)",
303 decl: {
304 start: {
305 line: 25,
306 column: 6
307 },
308 end: {
309 line: 25,
310 column: 7
311 }
312 },
313 loc: {
314 start: {
315 line: 25,
316 column: 20
317 },
318 end: {
319 line: 25,
320 column: 40
321 }
322 },
323 line: 25
324 },
325 "3": {
326 name: "getConfigContent",
327 decl: {
328 start: {
329 line: 51,
330 column: 9
331 },
332 end: {
333 line: 51,
334 column: 25
335 }
336 },
337 loc: {
338 start: {
339 line: 51,
340 column: 54
341 },
342 end: {
343 line: 65,
344 column: 1
345 }
346 },
347 line: 51
348 },
349 "4": {
350 name: "readConfigFileContent",
351 decl: {
352 start: {
353 line: 73,
354 column: 9
355 },
356 end: {
357 line: 73,
358 column: 30
359 }
360 },
361 loc: {
362 start: {
363 line: 73,
364 column: 44
365 },
366 end: {
367 line: 82,
368 column: 1
369 }
370 },
371 line: 73
372 }
373 },
374 branchMap: {
375 "0": {
376 loc: {
377 start: {
378 line: 21,
379 column: 21
380 },
381 end: {
382 line: 21,
383 column: 75
384 }
385 },
386 type: "binary-expr",
387 locations: [{
388 start: {
389 line: 21,
390 column: 21
391 },
392 end: {
393 line: 21,
394 column: 45
395 }
396 }, {
397 start: {
398 line: 21,
399 column: 49
400 },
401 end: {
402 line: 21,
403 column: 75
404 }
405 }],
406 line: 21
407 },
408 "1": {
409 loc: {
410 start: {
411 line: 23,
412 column: 18
413 },
414 end: {
415 line: 25,
416 column: 40
417 }
418 },
419 type: "cond-expr",
420 locations: [{
421 start: {
422 line: 24,
423 column: 6
424 },
425 end: {
426 line: 24,
427 column: 59
428 }
429 }, {
430 start: {
431 line: 25,
432 column: 6
433 },
434 end: {
435 line: 25,
436 column: 40
437 }
438 }],
439 line: 23
440 },
441 "2": {
442 loc: {
443 start: {
444 line: 52,
445 column: 4
446 },
447 end: {
448 line: 54,
449 column: 5
450 }
451 },
452 type: "if",
453 locations: [{
454 start: {
455 line: 52,
456 column: 4
457 },
458 end: {
459 line: 54,
460 column: 5
461 }
462 }, {
463 start: {
464 line: 52,
465 column: 4
466 },
467 end: {
468 line: 54,
469 column: 5
470 }
471 }],
472 line: 52
473 },
474 "3": {
475 loc: {
476 start: {
477 line: 59,
478 column: 4
479 },
480 end: {
481 line: 61,
482 column: 5
483 }
484 },
485 type: "if",
486 locations: [{
487 start: {
488 line: 59,
489 column: 4
490 },
491 end: {
492 line: 61,
493 column: 5
494 }
495 }, {
496 start: {
497 line: 59,
498 column: 4
499 },
500 end: {
501 line: 61,
502 column: 5
503 }
504 }],
505 line: 59
506 },
507 "4": {
508 loc: {
509 start: {
510 line: 77,
511 column: 2
512 },
513 end: {
514 line: 79,
515 column: 3
516 }
517 },
518 type: "if",
519 locations: [{
520 start: {
521 line: 77,
522 column: 2
523 },
524 end: {
525 line: 79,
526 column: 3
527 }
528 }, {
529 start: {
530 line: 77,
531 column: 2
532 },
533 end: {
534 line: 79,
535 column: 3
536 }
537 }],
538 line: 77
539 }
540 },
541 s: {
542 "0": 0,
543 "1": 0,
544 "2": 0,
545 "3": 0,
546 "4": 0,
547 "5": 0,
548 "6": 0,
549 "7": 0,
550 "8": 0,
551 "9": 0,
552 "10": 0,
553 "11": 0,
554 "12": 0,
555 "13": 0,
556 "14": 0,
557 "15": 0,
558 "16": 0,
559 "17": 0,
560 "18": 0,
561 "19": 0,
562 "20": 0,
563 "21": 0,
564 "22": 0,
565 "23": 0
566 },
567 f: {
568 "0": 0,
569 "1": 0,
570 "2": 0,
571 "3": 0,
572 "4": 0
573 },
574 b: {
575 "0": [0, 0],
576 "1": [0, 0],
577 "2": [0, 0],
578 "3": [0, 0],
579 "4": [0, 0]
580 },
581 _coverageSchema: "43e27e138ebf9cfc5966b082cf9a028302ed4184",
582 hash: "dd54b9863cc28669094c54e487b6ac45b6fa0f1b"
583 };
584 var coverage = global[gcv] || (global[gcv] = {});
585
586 if (coverage[path] && coverage[path].hash === hash) {
587 return coverage[path];
588 }
589
590 return coverage[path] = coverageData;
591}();
592
593Object.defineProperty(exports, "__esModule", {
594 value: true
595});
596exports.default = void 0;
597
598var _fs = _interopRequireDefault(require("fs"));
599
600var _path = _interopRequireDefault(require("path"));
601
602var _stripJsonComments = _interopRequireDefault(require("strip-json-comments"));
603
604var _isUtf = _interopRequireDefault(require("is-utf8"));
605
606var _stripBom = _interopRequireDefault(require("strip-bom"));
607
608var _configLoader = require("../configLoader");
609
610function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
611
612var _default = getConfigContent;
613/**
614 * Read the content of a configuration file
615 * - if not js or json: strip any comments
616 * - if js or json: require it
617 * @param {String} configPath - full path to configuration file
618 * @return {Object}
619 */
620
621exports.default = _default;
622
623function readConfigContent(configPath) {
624 cov_1ia30hret7.f[0]++;
625 const parsedPath = (cov_1ia30hret7.s[0]++, _path.default.parse(configPath));
626 const isRcFile = (cov_1ia30hret7.s[1]++, (cov_1ia30hret7.b[0][0]++, parsedPath.ext !== '.js') && (cov_1ia30hret7.b[0][1]++, parsedPath.ext !== '.json'));
627 const jsonString = (cov_1ia30hret7.s[2]++, readConfigFileContent(configPath));
628 const parse = (cov_1ia30hret7.s[3]++, isRcFile ? (cov_1ia30hret7.b[1][0]++, contents => {
629 cov_1ia30hret7.f[1]++;
630 cov_1ia30hret7.s[4]++;
631 return JSON.parse((0, _stripJsonComments.default)(contents));
632 }) : (cov_1ia30hret7.b[1][1]++, contents => {
633 cov_1ia30hret7.f[2]++;
634 cov_1ia30hret7.s[5]++;
635 return JSON.parse(contents);
636 }));
637 cov_1ia30hret7.s[6]++;
638
639 try {
640 const parsed = (cov_1ia30hret7.s[7]++, parse(jsonString));
641 cov_1ia30hret7.s[8]++;
642 Object.defineProperty(parsed, 'configPath', {
643 value: configPath
644 });
645 cov_1ia30hret7.s[9]++;
646 return parsed;
647 } catch (error) {
648 cov_1ia30hret7.s[10]++;
649 error.message = [`Parsing JSON at ${configPath} for commitizen config failed:`, error.mesasge].join('\n');
650 cov_1ia30hret7.s[11]++;
651 throw error;
652 }
653}
654/**
655 * Get content of the configuration file
656 * @param {String} configPath - partial path to configuration file
657 * @param {String} directory - directory path which will be joined with config argument
658 * @return {Object}
659 */
660
661
662function getConfigContent(configPath, baseDirectory) {
663 cov_1ia30hret7.f[3]++;
664 cov_1ia30hret7.s[12]++;
665
666 if (!configPath) {
667 cov_1ia30hret7.b[2][0]++;
668 cov_1ia30hret7.s[13]++;
669 return;
670 } else {
671 cov_1ia30hret7.b[2][1]++;
672 }
673
674 const resolvedPath = (cov_1ia30hret7.s[14]++, _path.default.resolve(baseDirectory, configPath));
675 const configBasename = (cov_1ia30hret7.s[15]++, _path.default.basename(resolvedPath));
676 cov_1ia30hret7.s[16]++;
677
678 if (!_fs.default.existsSync(resolvedPath)) {
679 cov_1ia30hret7.b[3][0]++;
680 cov_1ia30hret7.s[17]++;
681 return (0, _configLoader.getNormalizedConfig)(resolvedPath);
682 } else {
683 cov_1ia30hret7.b[3][1]++;
684 }
685
686 const content = (cov_1ia30hret7.s[18]++, readConfigContent(resolvedPath));
687 cov_1ia30hret7.s[19]++;
688 return (0, _configLoader.getNormalizedConfig)(configBasename, content);
689}
690
691;
692/**
693 * Read proper content from config file.
694 * If the chartset of the config file is not utf-8, one error will be thrown.
695 * @param {String} configPath
696 * @return {String}
697 */
698
699function readConfigFileContent(configPath) {
700 cov_1ia30hret7.f[4]++;
701 let rawBufContent = (cov_1ia30hret7.s[20]++, _fs.default.readFileSync(configPath));
702 cov_1ia30hret7.s[21]++;
703
704 if (!(0, _isUtf.default)(rawBufContent)) {
705 cov_1ia30hret7.b[4][0]++;
706 cov_1ia30hret7.s[22]++;
707 throw new Error(`The config file at "${configPath}" contains invalid charset, expect utf8`);
708 } else {
709 cov_1ia30hret7.b[4][1]++;
710 }
711
712 cov_1ia30hret7.s[23]++;
713 return (0, _stripBom.default)(rawBufContent.toString("utf8"));
714}
\No newline at end of file