Skip to content

Instantly share code, notes, and snippets.

@kanthvallampati
Created September 9, 2020 08:27
Show Gist options
  • Save kanthvallampati/b685b9d4c5c2fd257b01738b0150092e to your computer and use it in GitHub Desktop.
Save kanthvallampati/b685b9d4c5c2fd257b01738b0150092e to your computer and use it in GitHub Desktop.
Get the code files in your angular application
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