UNPKG

1.94 kBJavaScriptView Raw
1'use strict';
2
3var stripAnsi = require('strip-ansi');
4var path = require('path');
5var cliSpinner = require('cli-spinners').dots10;
6
7var removeVariance = function removeVariance(input) {
8 if (input && input.message) {
9 input.message = removeVariance(input.message);
10 }
11 if ('' + input !== input) {
12 for (var k in input) {
13 input[k] = removeVariance(input[k]);
14 }
15 return input;
16 }
17
18 var map = {
19 SCROLEX_ROOT: path.resolve(path.join(__dirname, '..')),
20 PWD: process.cwd(),
21 HOME: process.env.HOME,
22 USER: process.env.USER
23 };
24
25 for (var key in map) {
26 var val = map[key];
27 while (input.indexOf(val) !== -1) {
28 input = input.replace(val, '#{' + key + '}');
29 }
30 }
31
32 input = stripAnsi(input);
33
34 input = input.replace(/^.*Already up-to-date.*\n/gm, '');
35 input = input.replace(/^.*Building fresh packages.*\n/gm, '');
36 input = input.replace(/^.*Fetching package.*\n/gm, '');
37 input = input.replace(/^.*fsevents.*Excluding it from installation.*\n/gm, '');
38 input = input.replace(/^.*fsevents.*incompatible with this module.*\n/gm, '');
39 input = input.replace(/^.*Linking dependencies.*\n/gm, '');
40 input = input.replace(/^.*peer dependency "es6-promise.*\n/gm, '');
41 input = input.replace(/^.*Resolving packages.*\n/gm, '');
42 input = input.replace(/^.*There appears to be trouble with your network connection.*\n/gm, '');
43 input = input.replace(/Done in \d+\.\d+s/g, 'Done in X.Xs');
44 input = input.replace(/\d+ms/g, 'XXms');
45 input = input.replace(/yarn install v\d+\.\d+\.\d+/g, 'yarn install vX.X.X');
46
47 // @todo: Remove this hack when scrolex no longer adds trailing spinner frames:
48 cliSpinner.frames.forEach(function (frame) {
49 while (input.indexOf(frame) !== -1) {
50 // console.log({input, frame})
51 input = input.replace(frame, '---spinnerframe---');
52 }
53 });
54
55 return input;
56};
57
58module.exports = removeVariance;
59//# sourceMappingURL=removeVariance.js.map
\No newline at end of file