Created
September 9, 2020 08:27
-
-
Save kanthvallampati/b685b9d4c5c2fd257b01738b0150092e to your computer and use it in GitHub Desktop.
Get the code files in your angular application
This file contains 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 { join } = require('path'); | |
const dir = './src/app'; | |
const excludeExtns = [ | |
'.html', | |
'.scss', | |
'.css', | |
'.sass', | |
'.spec.ts', | |
'.test.ts', | |
'.module.ts', | |
'.enum.ts', | |
'.constants.ts' | |
] | |
getTotalFiles = () => { | |
let list = getFilesOfDir(dir); | |
console.log('Total files - ', list.length); | |
console.log(list); | |
} | |
getFilesOfDir = (dir, allFiles = []) => { | |
const files = fs.readdirSync(dir).map(f => join(dir, f)); | |
files.forEach(f => { | |
if (fs.statSync(f).isDirectory()) { | |
getFilesOfDir(f, allFiles); | |
} else if (isPreciseFile(f)) { | |
allFiles.push(f); | |
} | |
}); | |
return allFiles; | |
} | |
isPreciseFile = (file) => { | |
for (const i of excludeExtns) { | |
if (file.includes(i)) { | |
return false; | |
} | |
} | |
return true; | |
} | |
getTotalFiles(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment