UNPKG

@mutasim77/loc-counter

Version:

A powerful lines of code counter with detailed statistics

107 lines (106 loc) 4.36 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.printProjectSummary = printProjectSummary; exports.printError = printError; exports.printProgress = printProgress; exports.printSuccess = printSuccess; const chalk_1 = __importDefault(require("chalk")); const cli_table3_1 = __importDefault(require("cli-table3")); function printProjectSummary(stats) { console.log('\n'); console.log(chalk_1.default.bold.cyan('📊 LOC-COUNTER SUMMARY')); console.log(chalk_1.default.gray('─'.repeat(50))); //* Print language statistics printLanguageStats(stats.languages); //* Print total statistics printTotalStats(stats.total, stats.files.length); //! TODO: Make it optional later // printFileBreakdown(stats.files); } function printLanguageStats(languages) { console.log('\n'); console.log(chalk_1.default.bold.cyan('📈 LANGUAGES BREAKDOWN')); const table = new cli_table3_1.default({ head: [ chalk_1.default.bold('Language'), chalk_1.default.bold('Files'), chalk_1.default.bold('Code Lines'), chalk_1.default.bold('Comment Lines'), chalk_1.default.bold('Blank Lines'), chalk_1.default.bold('Total Lines'), chalk_1.default.bold('Percentage') ], style: { head: [], border: [] } }); languages.forEach(lang => { table.push([ chalk_1.default.cyan(lang.language), lang.files.toString(), chalk_1.default.green(lang.code.toString()), chalk_1.default.yellow(lang.comment.toString()), chalk_1.default.gray(lang.blank.toString()), lang.total.toString(), chalk_1.default.magenta(`${lang.percentage.toFixed(2)}%`) ]); }); console.log(table.toString()); } function printTotalStats(totalStats, fileCount) { console.log('\n'); console.log(chalk_1.default.bold.cyan('📊 TOTAL STATISTICS')); const table = new cli_table3_1.default(); table.push({ 'Total Files': chalk_1.default.bold(fileCount.toString()) }, { 'Total Lines': chalk_1.default.bold(totalStats.total.toString()) }, { 'Code Lines': chalk_1.default.bold.green(totalStats.code.toString()) }, { 'Comment Lines': chalk_1.default.bold.yellow(totalStats.comment.toString()) }, { 'Blank Lines': chalk_1.default.bold.gray(totalStats.blank.toString()) }); console.log(table.toString()); const commentRatio = totalStats.comment / totalStats.code; console.log(`\n${chalk_1.default.bold('Code to Comment Ratio:')} ${chalk_1.default.green('1')} : ${chalk_1.default.yellow(commentRatio.toFixed(2))}`); } function printError(message) { console.error(chalk_1.default.red(`❌ Error: ${message}`)); } function printProgress(message) { console.log(chalk_1.default.blue(`⏳ ${message}`)); } function printSuccess(message) { console.log(chalk_1.default.green(`✅ ${message}`)); } function printFileBreakdown(files) { console.log('\n'); console.log(chalk_1.default.bold.cyan('📄 FILE BREAKDOWN')); const table = new cli_table3_1.default({ head: [ chalk_1.default.bold('File'), chalk_1.default.bold('Language'), chalk_1.default.bold('Code'), chalk_1.default.bold('Comment'), chalk_1.default.bold('Blank'), chalk_1.default.bold('Total') ], style: { head: [], border: [] }, colWidths: [50, 15, 10, 10, 10, 10] }); const sortedFiles = [...files].sort((a, b) => b.total - a.total); const topFiles = sortedFiles.slice(0, 20); topFiles.forEach(file => { table.push([ chalk_1.default.white(file.path), chalk_1.default.cyan(file.language), chalk_1.default.green(file.code.toString()), chalk_1.default.yellow(file.comment.toString()), chalk_1.default.gray(file.blank.toString()), file.total.toString() ]); }); console.log(table.toString()); if (files.length > 20) { console.log(`\n${chalk_1.default.gray(`... and ${files.length - 20} more files`)}`); } }