Skip to content

Instantly share code, notes, and snippets.

@armamini
Created January 24, 2024 09:28
Show Gist options
  • Select an option

  • Save armamini/c700da5adfb7f05cdae0d05202e18d36 to your computer and use it in GitHub Desktop.

Select an option

Save armamini/c700da5adfb7f05cdae0d05202e18d36 to your computer and use it in GitHub Desktop.
Count your TS project Lines
const fs = require('fs');
const path = require('path');
function countLinesInFile(file) {
const content = fs.readFileSync(file, 'utf8');
return content.split('\n').length;
}
function countLinesInDirectory(dir) {
let totalLines = 0;
const files = fs.readdirSync(dir);
files.forEach(file => {
const filePath = path.join(dir, file);
const stats = fs.statSync(filePath);
if (stats.isDirectory()) {
totalLines += countLinesInDirectory(filePath);
} else if (filePath.endsWith('.ts')) {
totalLines += countLinesInFile(filePath);
}
});
return totalLines;
}
const projectDirectory = './klidina-backend';
const totalLines = countLinesInDirectory(projectDirectory);
console.log(`Total lines of TypeScript code: ${totalLines}`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment