Skip to content

Instantly share code, notes, and snippets.

@ramzes13
Created April 6, 2020 08:32
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ramzes13/ecd132f13d54a35e4389c69fc64817b7 to your computer and use it in GitHub Desktop.
check for non used files in nodejs project
const { resolve } = require('path');
const { readdirSync, lstatSync } = require('fs');
async function getFiles(dir) {
const dirents = readdirSync(dir, { withFileTypes: true });
const files = await Promise.all(dirents.map(dirent => {
const res = resolve(dir, dirent);
return lstatSync(res).isDirectory() ? getFiles(res) : res;
}));
return Array.prototype.concat(...files);
}
setTimeout(async() => {
const files = await getFiles(__dirname);
const notLoaded = [];
files.forEach(file => !require.cache[file] ? notLoaded.push(file): '');
console.log(notLoaded);
}, 5000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment