Created
January 23, 2018 01:56
-
-
Save kaievns/97a446b2bed01263ab086f2749f49295 to your computer and use it in GitHub Desktop.
Finds unused react components in a 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 { execSync } = require('child_process'); | |
const directory = 'src'; | |
const findOut = execSync('find -L src').toString(); | |
const filenames = findOut.trim().split('\n') | |
.filter(name => name.endsWith('.js')) | |
.map(name => name.replace('.js', '').replace('src/', '').replace(/\/index$/, '')); | |
console.log('Found', filenames.length, 'files in', directory); | |
const missing = []; | |
for (const name of filenames) { | |
try { | |
execSync(`grep -Ril "'${name}'" ${directory}`); | |
} catch (e) { | |
try { | |
const localName = `/${name.split('/').pop()}`; | |
execSync(`grep -Ril "${localName}';" ${directory}`); | |
} catch (e) { | |
missing.push(name); | |
console.log('Cant find anything that uses', `'${name}'`); | |
} | |
} | |
} | |
console.log('total missing: ', missing.length); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment