Created
December 4, 2017 16:50
-
-
Save daisy1754/7297ef559e556b9404beb321a098698f to your computer and use it in GitHub Desktop.
Script to find unused JS/JSX file
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
| start_time = Time.now | |
| files = Dir.glob("./**/*.{js,jsx}").reject do |path| | |
| path.include?("node_modules") || path.include?("khan-linter") || path.include?("tests") | |
| end | |
| files_to_delete = files.select do |f| | |
| basename = File.basename(f) | |
| result = `grep --exclude-dir={node_modules,khan-linter,\.git} --exclude=#{basename} -rlw '.' -e #{basename.split(".")[0]}` | |
| result.empty? | |
| end | |
| p "#{files.length} js/jsx files are checked. #{files_to_delete.length} potentially unused files found:" | |
| files_to_delete.each do |f| | |
| p f | |
| `git rm #{f}` | |
| end | |
| p "Execution took #{Time.now - start_time} seconds" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment