feat: modularize flattener tool into separate components with improved project root detection (#417)

This commit is contained in:
manjaroblack
2025-08-09 15:33:23 -05:00
committed by GitHub
parent 5d7d7c9015
commit 0fdbca73fc
15 changed files with 13465 additions and 13176 deletions

30
tools/flattener/stats.js Normal file
View File

@@ -0,0 +1,30 @@
function calculateStatistics(aggregatedContent, xmlFileSize) {
const { textFiles, binaryFiles, errors } = aggregatedContent;
const totalTextSize = textFiles.reduce((sum, file) => sum + file.size, 0);
const totalBinarySize = binaryFiles.reduce((sum, file) => sum + file.size, 0);
const totalSize = totalTextSize + totalBinarySize;
const totalLines = textFiles.reduce((sum, file) => sum + file.lines, 0);
const estimatedTokens = Math.ceil(xmlFileSize / 4);
const formatSize = (bytes) => {
if (bytes < 1024) return `${bytes} B`;
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
};
return {
totalFiles: textFiles.length + binaryFiles.length,
textFiles: textFiles.length,
binaryFiles: binaryFiles.length,
errorFiles: errors.length,
totalSize: formatSize(totalSize),
xmlSize: formatSize(xmlFileSize),
totalLines,
estimatedTokens: estimatedTokens.toLocaleString(),
};
}
module.exports = { calculateStatistics };