logger.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. "use strict";
  2. var __read = (this && this.__read) || function (o, n) {
  3. var m = typeof Symbol === "function" && o[Symbol.iterator];
  4. if (!m) return o;
  5. var i = m.call(o), r, ar = [], e;
  6. try {
  7. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
  8. }
  9. catch (error) { e = { error: error }; }
  10. finally {
  11. try {
  12. if (r && !r.done && (m = i["return"])) m.call(i);
  13. }
  14. finally { if (e) throw e.error; }
  15. }
  16. return ar;
  17. };
  18. var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
  19. if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
  20. if (ar || !(i in from)) {
  21. if (!ar) ar = Array.prototype.slice.call(from, 0, i);
  22. ar[i] = from[i];
  23. }
  24. }
  25. return to.concat(ar || Array.prototype.slice.call(from));
  26. };
  27. exports.__esModule = true;
  28. exports.Logger = void 0;
  29. /**
  30. * Generic console logger
  31. */
  32. var Logger = /** @class */ (function () {
  33. function Logger() {
  34. }
  35. /**
  36. * Missing build
  37. */
  38. Logger.noExportMarker = function () {
  39. Logger.error('Unable to find export-maker.\nMake sure to build the project using `next build` command\n');
  40. };
  41. /**
  42. * Log missing config file
  43. */
  44. Logger.noConfigFile = function () {
  45. Logger.error('Unable to find next-sitemap.config.js or custom config file.\n\nIMPORTANT: Default config file has been renamed to `next-sitemap.config.js`\n\nIf you are using custom config file, make sure to invoke `next-sitemap --config <custom-config-file>.js`\n');
  46. };
  47. /**
  48. * Generic error logger
  49. * @param text
  50. * @returns
  51. */
  52. Logger.error = function () {
  53. var text = [];
  54. for (var _i = 0; _i < arguments.length; _i++) {
  55. text[_i] = arguments[_i];
  56. }
  57. return console.error.apply(console, __spreadArray(["\u001B[31m", "\u274C", "[next-sitemap]"], __read(text), false));
  58. };
  59. /**
  60. * Generic log
  61. * @param emoji
  62. * @param text
  63. */
  64. Logger.log = function (emoji) {
  65. var text = [];
  66. for (var _i = 1; _i < arguments.length; _i++) {
  67. text[_i - 1] = arguments[_i];
  68. }
  69. return console.log.apply(console, __spreadArray([emoji, "[next-sitemap]"], __read(text), false));
  70. };
  71. Logger.logList = function (title, list) {
  72. console.log("-----------------------------------------------------\n", title, "\n-----------------------------------------------------\n");
  73. // Only show 5 entries on console
  74. if ((list === null || list === void 0 ? void 0 : list.length) > 7) {
  75. list = __spreadArray(__spreadArray(__spreadArray([], __read(list.splice(0, 3)), false), ['...'], false), __read(list.splice(list.length - 2, 2)), false);
  76. }
  77. // log all sitemap list
  78. list === null || list === void 0 ? void 0 : list.forEach(function (x) {
  79. return x === '...' ? console.log(" ".concat(x)) : console.log(" \u25CB ".concat(x));
  80. });
  81. console.log("\n");
  82. };
  83. /**
  84. * Log stats when the generation is completed
  85. * @param result
  86. * @returns
  87. */
  88. Logger.generationCompleted = function (result) {
  89. // Initial stats
  90. Logger.log("\u2705", 'Generation completed');
  91. var indexCount = result.sitemapIndices.length;
  92. var sitemapCount = result.sitemaps.length;
  93. console.table({
  94. indexSitemaps: indexCount,
  95. sitemaps: sitemapCount
  96. });
  97. // Log sitemap index list
  98. if (indexCount > 0) {
  99. Logger.logList('SITEMAP INDICES', result.sitemapIndices);
  100. }
  101. // Log sitemap list
  102. if (sitemapCount > 0) {
  103. Logger.logList('SITEMAPS', result.sitemaps);
  104. }
  105. };
  106. return Logger;
  107. }());
  108. exports.Logger = Logger;