执行过npm install命令的vue-element-admin源码
康凯
2022-05-20 aa4c235a8ca67ea8b731f90c951a465e92c0a865
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
"use strict";
 
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
 
var _chalk = _interopRequireDefault(require("chalk"));
 
var _ansiEscapes = _interopRequireDefault(require("ansi-escapes"));
 
var _stringLength = _interopRequireDefault(require("string-length"));
 
var _jestWatcher = require("jest-watcher");
 
var _utils = require("../lib/utils");
 
var _pattern_mode_helpers = require("../lib/pattern_mode_helpers");
 
var _scroll2 = _interopRequireDefault(require("../lib/scroll"));
 
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
 
class FileNamePatternPrompt extends _jestWatcher.PatternPrompt {
  constructor(pipe, prompt) {
    super(pipe, prompt);
    this._entityName = 'filenames';
    this._searchSources = [];
  }
 
  _onChange(pattern, options) {
    super._onChange(pattern, options);
 
    this._printTypeahead(pattern, options);
  }
 
  _printTypeahead(pattern, options) {
    const matchedTests = this._getMatchedTests(pattern);
 
    const total = matchedTests.length;
    const pipe = this._pipe;
    const prompt = this._prompt;
    (0, _jestWatcher.printPatternCaret)(pattern, pipe);
    pipe.write(_ansiEscapes.default.cursorLeft);
 
    if (pattern) {
      (0, _pattern_mode_helpers.printPatternMatches)(total, 'file', pipe);
      const prefix = `  ${_chalk.default.dim('\u203A')} `;
      const padding = (0, _stringLength.default)(prefix) + 2;
      const width = (0, _utils.getTerminalWidth)(pipe);
 
      const _scroll = (0, _scroll2.default)(total, options),
            start = _scroll.start,
            end = _scroll.end,
            index = _scroll.index;
 
      prompt.setPromptLength(total);
      matchedTests.slice(start, end).map(({
        path,
        context
      }) => {
        const filePath = (0, _utils.trimAndFormatPath)(padding, context.config, path, width);
        return (0, _utils.highlight)(path, filePath, pattern, context.config.rootDir);
      }).map((item, i) => (0, _pattern_mode_helpers.formatTypeaheadSelection)(item, i, index, prompt)).forEach(item => (0, _pattern_mode_helpers.printTypeaheadItem)(item, pipe));
 
      if (total > end) {
        (0, _pattern_mode_helpers.printMore)('file', pipe, total - end);
      }
    } else {
      (0, _pattern_mode_helpers.printStartTyping)('filename', pipe);
    }
 
    (0, _jestWatcher.printRestoredPatternCaret)(pattern, this._currentUsageRows, pipe);
  }
 
  _getMatchedTests(pattern) {
    let regex;
 
    try {
      regex = new RegExp(pattern, 'i');
    } catch (e) {
      return [];
    }
 
    return this._searchSources.reduce((tests, {
      testPaths,
      config
    }) => {
      return tests.concat(testPaths.filter(testPath => regex.test(testPath)).map(path => ({
        path,
        context: {
          config
        }
      })));
    }, []);
  }
 
  updateSearchSources(searchSources) {
    this._searchSources = searchSources;
  }
 
}
 
exports.default = FileNamePatternPrompt;