Created
January 24, 2024 09:28
-
-
Save armamini/c700da5adfb7f05cdae0d05202e18d36 to your computer and use it in GitHub Desktop.
Count your TS project Lines
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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