info.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. 'use strict';
  2. var browserslist = require('browserslist');
  3. function capitalize(str) {
  4. return str.slice(0, 1).toUpperCase() + str.slice(1);
  5. }
  6. var names = {
  7. ie: 'IE',
  8. ie_mob: 'IE Mobile',
  9. ios_saf: 'iOS',
  10. op_mini: 'Opera Mini',
  11. op_mob: 'Opera Mobile',
  12. and_chr: 'Chrome for Android',
  13. and_ff: 'Firefox for Android',
  14. and_uc: 'UC for Android'
  15. };
  16. var prefix = function prefix(name, prefixes) {
  17. var out = ' ' + name + ': ';
  18. out += prefixes.map(function (i) {
  19. return i.replace(/^-(.*)-$/g, '$1');
  20. }).join(', ');
  21. out += '\n';
  22. return out;
  23. };
  24. module.exports = function (prefixes) {
  25. if (prefixes.browsers.selected.length === 0) {
  26. return 'No browsers selected';
  27. }
  28. var versions = {};
  29. for (var _iterator = prefixes.browsers.selected, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
  30. var _ref;
  31. if (_isArray) {
  32. if (_i >= _iterator.length) break;
  33. _ref = _iterator[_i++];
  34. } else {
  35. _i = _iterator.next();
  36. if (_i.done) break;
  37. _ref = _i.value;
  38. }
  39. var browser = _ref;
  40. var _browser$split = browser.split(' '),
  41. name = _browser$split[0],
  42. version = _browser$split[1];
  43. name = names[name] || capitalize(name);
  44. if (versions[name]) {
  45. versions[name].push(version);
  46. } else {
  47. versions[name] = [version];
  48. }
  49. }
  50. var out = 'Browsers:\n';
  51. for (var _browser in versions) {
  52. var list = versions[_browser];
  53. list = list.sort(function (a, b) {
  54. return parseFloat(b) - parseFloat(a);
  55. });
  56. out += ' ' + _browser + ': ' + list.join(', ') + '\n';
  57. }
  58. var coverage = browserslist.coverage(prefixes.browsers.selected);
  59. var round = Math.round(coverage * 100) / 100.0;
  60. out += '\nThese browsers account for ' + round + '% of all users globally\n';
  61. var atrules = '';
  62. for (var name in prefixes.add) {
  63. var data = prefixes.add[name];
  64. if (name[0] === '@' && data.prefixes) {
  65. atrules += prefix(name, data.prefixes);
  66. }
  67. }
  68. if (atrules !== '') {
  69. out += '\nAt-Rules:\n' + atrules;
  70. }
  71. var selectors = '';
  72. for (var _iterator2 = prefixes.add.selectors, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
  73. var _ref2;
  74. if (_isArray2) {
  75. if (_i2 >= _iterator2.length) break;
  76. _ref2 = _iterator2[_i2++];
  77. } else {
  78. _i2 = _iterator2.next();
  79. if (_i2.done) break;
  80. _ref2 = _i2.value;
  81. }
  82. var selector = _ref2;
  83. if (selector.prefixes) {
  84. selectors += prefix(selector.name, selector.prefixes);
  85. }
  86. }
  87. if (selectors !== '') {
  88. out += '\nSelectors:\n' + selectors;
  89. }
  90. var values = '';
  91. var props = '';
  92. for (var _name in prefixes.add) {
  93. var _data = prefixes.add[_name];
  94. if (_name[0] !== '@' && _data.prefixes) {
  95. props += prefix(_name, _data.prefixes);
  96. }
  97. if (!_data.values) {
  98. continue;
  99. }
  100. for (var _iterator3 = _data.values, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) {
  101. var _ref3;
  102. if (_isArray3) {
  103. if (_i3 >= _iterator3.length) break;
  104. _ref3 = _iterator3[_i3++];
  105. } else {
  106. _i3 = _iterator3.next();
  107. if (_i3.done) break;
  108. _ref3 = _i3.value;
  109. }
  110. var value = _ref3;
  111. var string = prefix(value.name, value.prefixes);
  112. if (values.indexOf(string) === -1) {
  113. values += string;
  114. }
  115. }
  116. }
  117. if (props !== '') {
  118. out += '\nProperties:\n' + props;
  119. }
  120. if (values !== '') {
  121. out += '\nValues:\n' + values;
  122. }
  123. if (atrules === '' && selectors === '' && props === '' && values === '') {
  124. out += '\nAwesome! Your browsers don\'t require any vendor prefixes.' + '\nNow you can remove Autoprefixer from build steps.';
  125. }
  126. return out;
  127. };