1 | "use strict";
|
---|
2 |
|
---|
3 | function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } it = o[Symbol.iterator](); return it.next.bind(it); }
|
---|
4 |
|
---|
5 | function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
---|
6 |
|
---|
7 | function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
---|
8 |
|
---|
9 | var browserslist = require('browserslist');
|
---|
10 |
|
---|
11 | function capitalize(str) {
|
---|
12 | return str.slice(0, 1).toUpperCase() + str.slice(1);
|
---|
13 | }
|
---|
14 |
|
---|
15 | var NAMES = {
|
---|
16 | ie: 'IE',
|
---|
17 | ie_mob: 'IE Mobile',
|
---|
18 | ios_saf: 'iOS',
|
---|
19 | op_mini: 'Opera Mini',
|
---|
20 | op_mob: 'Opera Mobile',
|
---|
21 | and_chr: 'Chrome for Android',
|
---|
22 | and_ff: 'Firefox for Android',
|
---|
23 | and_uc: 'UC for Android'
|
---|
24 | };
|
---|
25 |
|
---|
26 | function prefix(name, prefixes, note) {
|
---|
27 | var out = " " + name;
|
---|
28 | if (note) out += ' *';
|
---|
29 | out += ': ';
|
---|
30 | out += prefixes.map(function (i) {
|
---|
31 | return i.replace(/^-(.*)-$/g, '$1');
|
---|
32 | }).join(', ');
|
---|
33 | out += '\n';
|
---|
34 | return out;
|
---|
35 | }
|
---|
36 |
|
---|
37 | module.exports = function (prefixes) {
|
---|
38 | if (prefixes.browsers.selected.length === 0) {
|
---|
39 | return 'No browsers selected';
|
---|
40 | }
|
---|
41 |
|
---|
42 | var versions = {};
|
---|
43 |
|
---|
44 | for (var _iterator = _createForOfIteratorHelperLoose(prefixes.browsers.selected), _step; !(_step = _iterator()).done;) {
|
---|
45 | var _browser = _step.value;
|
---|
46 |
|
---|
47 | var parts = _browser.split(' ');
|
---|
48 |
|
---|
49 | var _name2 = parts[0];
|
---|
50 | var version = parts[1];
|
---|
51 | _name2 = NAMES[_name2] || capitalize(_name2);
|
---|
52 |
|
---|
53 | if (versions[_name2]) {
|
---|
54 | versions[_name2].push(version);
|
---|
55 | } else {
|
---|
56 | versions[_name2] = [version];
|
---|
57 | }
|
---|
58 | }
|
---|
59 |
|
---|
60 | var out = 'Browsers:\n';
|
---|
61 |
|
---|
62 | for (var browser in versions) {
|
---|
63 | var list = versions[browser];
|
---|
64 | list = list.sort(function (a, b) {
|
---|
65 | return parseFloat(b) - parseFloat(a);
|
---|
66 | });
|
---|
67 | out += " " + browser + ": " + list.join(', ') + "\n";
|
---|
68 | }
|
---|
69 |
|
---|
70 | var coverage = browserslist.coverage(prefixes.browsers.selected);
|
---|
71 | var round = Math.round(coverage * 100) / 100.0;
|
---|
72 | out += "\nThese browsers account for " + round + "% of all users globally\n";
|
---|
73 | var atrules = [];
|
---|
74 |
|
---|
75 | for (var name in prefixes.add) {
|
---|
76 | var data = prefixes.add[name];
|
---|
77 |
|
---|
78 | if (name[0] === '@' && data.prefixes) {
|
---|
79 | atrules.push(prefix(name, data.prefixes));
|
---|
80 | }
|
---|
81 | }
|
---|
82 |
|
---|
83 | if (atrules.length > 0) {
|
---|
84 | out += "\nAt-Rules:\n" + atrules.sort().join('');
|
---|
85 | }
|
---|
86 |
|
---|
87 | var selectors = [];
|
---|
88 |
|
---|
89 | for (var _iterator2 = _createForOfIteratorHelperLoose(prefixes.add.selectors), _step2; !(_step2 = _iterator2()).done;) {
|
---|
90 | var selector = _step2.value;
|
---|
91 |
|
---|
92 | if (selector.prefixes) {
|
---|
93 | selectors.push(prefix(selector.name, selector.prefixes));
|
---|
94 | }
|
---|
95 | }
|
---|
96 |
|
---|
97 | if (selectors.length > 0) {
|
---|
98 | out += "\nSelectors:\n" + selectors.sort().join('');
|
---|
99 | }
|
---|
100 |
|
---|
101 | var values = [];
|
---|
102 | var props = [];
|
---|
103 | var hadGrid = false;
|
---|
104 |
|
---|
105 | for (var _name in prefixes.add) {
|
---|
106 | var _data = prefixes.add[_name];
|
---|
107 |
|
---|
108 | if (_name[0] !== '@' && _data.prefixes) {
|
---|
109 | var grid = _name.indexOf('grid-') === 0;
|
---|
110 | if (grid) hadGrid = true;
|
---|
111 | props.push(prefix(_name, _data.prefixes, grid));
|
---|
112 | }
|
---|
113 |
|
---|
114 | if (!Array.isArray(_data.values)) {
|
---|
115 | continue;
|
---|
116 | }
|
---|
117 |
|
---|
118 | for (var _iterator3 = _createForOfIteratorHelperLoose(_data.values), _step3; !(_step3 = _iterator3()).done;) {
|
---|
119 | var value = _step3.value;
|
---|
120 |
|
---|
121 | var _grid = value.name.includes('grid');
|
---|
122 |
|
---|
123 | if (_grid) hadGrid = true;
|
---|
124 | var string = prefix(value.name, value.prefixes, _grid);
|
---|
125 |
|
---|
126 | if (!values.includes(string)) {
|
---|
127 | values.push(string);
|
---|
128 | }
|
---|
129 | }
|
---|
130 | }
|
---|
131 |
|
---|
132 | if (props.length > 0) {
|
---|
133 | out += "\nProperties:\n" + props.sort().join('');
|
---|
134 | }
|
---|
135 |
|
---|
136 | if (values.length > 0) {
|
---|
137 | out += "\nValues:\n" + values.sort().join('');
|
---|
138 | }
|
---|
139 |
|
---|
140 | if (hadGrid) {
|
---|
141 | out += '\n* - Prefixes will be added only on grid: true option.\n';
|
---|
142 | }
|
---|
143 |
|
---|
144 | if (!atrules.length && !selectors.length && !props.length && !values.length) {
|
---|
145 | out += '\nAwesome! Your browsers don\'t require any vendor prefixes.' + '\nNow you can remove Autoprefixer from build steps.';
|
---|
146 | }
|
---|
147 |
|
---|
148 | return out;
|
---|
149 | }; |
---|