123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- /**
- * Generic console logger
- */
- export class Logger {
- /**
- * Missing build
- */
- static noExportMarker() {
- Logger.error('Unable to find export-maker.\nMake sure to build the project using `next build` command\n');
- }
- /**
- * Log missing config file
- */
- static noConfigFile() {
- 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');
- }
- /**
- * Generic error logger
- * @param text
- * @returns
- */
- static error(...text) {
- return console.error(`\x1b[31m`, `❌`, `[next-sitemap]`, ...text);
- }
- /**
- * Generic log
- * @param emoji
- * @param text
- */
- static log(emoji, ...text) {
- return console.log(emoji, `[next-sitemap]`, ...text);
- }
- static logList(title, list) {
- console.log(`-----------------------------------------------------\n`, title, `\n-----------------------------------------------------\n`);
- // Only show 5 entries on console
- if (list?.length > 7) {
- list = [...list.splice(0, 3), '...', ...list.splice(list.length - 2, 2)];
- }
- // log all sitemap list
- list?.forEach((x) => x === '...' ? console.log(` ${x}`) : console.log(` ○ ${x}`));
- console.log(`\n`);
- }
- /**
- * Log stats when the generation is completed
- * @param result
- * @returns
- */
- static generationCompleted(result) {
- // Initial stats
- Logger.log(`✅`, 'Generation completed');
- const indexCount = result.sitemapIndices.length;
- const sitemapCount = result.sitemaps.length;
- console.table({
- indexSitemaps: indexCount,
- sitemaps: sitemapCount,
- });
- // Log sitemap index list
- if (indexCount > 0) {
- Logger.logList('SITEMAP INDICES', result.sitemapIndices);
- }
- // Log sitemap list
- if (sitemapCount > 0) {
- Logger.logList('SITEMAPS', result.sitemaps);
- }
- }
- }
|