UNPKG

css-deadweigth

Version:

CLI tool to detect unused CSS in your project

39 lines (32 loc) โ€ข 1.14 kB
import Table from 'cli-table3'; import chalk from 'chalk'; import fs from 'fs/promises'; export function printUnusedSelectors(unused, totalSelectors, usedSelectors) { if (unused.length === 0) { console.log(chalk.greenBright('๐ŸŽ‰ No unused CSS selectors found!')); return; } console.log(chalk.red.bold(`๐Ÿงน Unused CSS Selectors (${unused.length}):`)); const table = new Table({ head: ['Selector'], style: { head: ['cyan'] } }); unused.forEach(sel => table.push([sel])); console.log(table.toString()); console.log(chalk.yellow(`\nTotal selectors scanned: ${totalSelectors}`)); console.log(chalk.yellow(`Used selectors: ${usedSelectors}`)); } export async function saveReport(unused, totalSelectors, usedSelectors, filename) { const reportData = { unused, totalSelectors, usedSelectors, timestamp: new Date().toISOString() }; try { await fs.writeFile(filename, JSON.stringify(reportData, null, 2), 'utf-8'); console.log(chalk.blue(`โœ… Report saved to ${filename}`)); } catch (err) { console.error(chalk.red(`โŒ Failed to save report: ${err.message}`)); } }