css-deadweigth
Version:
CLI tool to detect unused CSS in your project
39 lines (32 loc) โข 1.14 kB
JavaScript
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}`));
}
}