Created
April 6, 2020 08:32
-
-
Save ramzes13/ecd132f13d54a35e4389c69fc64817b7 to your computer and use it in GitHub Desktop.
check for non used files in nodejs project
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 { 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