1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', {
|
4 | value: true
|
5 | });
|
6 | exports.default = trimAndFormatPath;
|
7 | function path() {
|
8 | const data = _interopRequireWildcard(require('path'));
|
9 | path = function () {
|
10 | return data;
|
11 | };
|
12 | return data;
|
13 | }
|
14 | function _chalk() {
|
15 | const data = _interopRequireDefault(require('chalk'));
|
16 | _chalk = function () {
|
17 | return data;
|
18 | };
|
19 | return data;
|
20 | }
|
21 | function _slash() {
|
22 | const data = _interopRequireDefault(require('slash'));
|
23 | _slash = function () {
|
24 | return data;
|
25 | };
|
26 | return data;
|
27 | }
|
28 | var _relativePath = _interopRequireDefault(require('./relativePath'));
|
29 | function _interopRequireDefault(obj) {
|
30 | return obj && obj.__esModule ? obj : {default: obj};
|
31 | }
|
32 | function _getRequireWildcardCache(nodeInterop) {
|
33 | if (typeof WeakMap !== 'function') return null;
|
34 | var cacheBabelInterop = new WeakMap();
|
35 | var cacheNodeInterop = new WeakMap();
|
36 | return (_getRequireWildcardCache = function (nodeInterop) {
|
37 | return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
38 | })(nodeInterop);
|
39 | }
|
40 | function _interopRequireWildcard(obj, nodeInterop) {
|
41 | if (!nodeInterop && obj && obj.__esModule) {
|
42 | return obj;
|
43 | }
|
44 | if (obj === null || (typeof obj !== 'object' && typeof obj !== 'function')) {
|
45 | return {default: obj};
|
46 | }
|
47 | var cache = _getRequireWildcardCache(nodeInterop);
|
48 | if (cache && cache.has(obj)) {
|
49 | return cache.get(obj);
|
50 | }
|
51 | var newObj = {};
|
52 | var hasPropertyDescriptor =
|
53 | Object.defineProperty && Object.getOwnPropertyDescriptor;
|
54 | for (var key in obj) {
|
55 | if (key !== 'default' && Object.prototype.hasOwnProperty.call(obj, key)) {
|
56 | var desc = hasPropertyDescriptor
|
57 | ? Object.getOwnPropertyDescriptor(obj, key)
|
58 | : null;
|
59 | if (desc && (desc.get || desc.set)) {
|
60 | Object.defineProperty(newObj, key, desc);
|
61 | } else {
|
62 | newObj[key] = obj[key];
|
63 | }
|
64 | }
|
65 | }
|
66 | newObj.default = obj;
|
67 | if (cache) {
|
68 | cache.set(obj, newObj);
|
69 | }
|
70 | return newObj;
|
71 | }
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 | function trimAndFormatPath(pad, config, testPath, columns) {
|
80 | const maxLength = columns - pad;
|
81 | const relative = (0, _relativePath.default)(config, testPath);
|
82 | const {basename} = relative;
|
83 | let {dirname} = relative;
|
84 |
|
85 |
|
86 | if ((dirname + path().sep + basename).length <= maxLength) {
|
87 | return (0, _slash().default)(
|
88 | _chalk().default.dim(dirname + path().sep) +
|
89 | _chalk().default.bold(basename)
|
90 | );
|
91 | }
|
92 |
|
93 |
|
94 | const basenameLength = basename.length;
|
95 | if (basenameLength + 4 < maxLength) {
|
96 | const dirnameLength = maxLength - 4 - basenameLength;
|
97 | dirname = `...${dirname.slice(
|
98 | dirname.length - dirnameLength,
|
99 | dirname.length
|
100 | )}`;
|
101 | return (0, _slash().default)(
|
102 | _chalk().default.dim(dirname + path().sep) +
|
103 | _chalk().default.bold(basename)
|
104 | );
|
105 | }
|
106 | if (basenameLength + 4 === maxLength) {
|
107 | return (0, _slash().default)(
|
108 | _chalk().default.dim(`...${path().sep}`) + _chalk().default.bold(basename)
|
109 | );
|
110 | }
|
111 |
|
112 |
|
113 | return (0, _slash().default)(
|
114 | _chalk().default.bold(
|
115 | `...${basename.slice(basename.length - maxLength - 4, basename.length)}`
|
116 | )
|
117 | );
|
118 | }
|