Class: Jets::Builders::Tidy
- Inherits:
-
Object
- Object
- Jets::Builders::Tidy
- Defined in:
- lib/jets/builders/tidy.rb
Instance Method Summary collapse
-
#always_removals ⇒ Object
These directories will be removed regardless of dir level.
- #cleanup! ⇒ Object
- #get_removals(file) ⇒ Object
-
#initialize(project_root, noop: false) ⇒ Tidy
constructor
A new instance of Tidy.
-
#jetskeep ⇒ Object
We clean out ignored files pretty aggressively.
- #removals ⇒ Object
-
#remove_gem_cache ⇒ Object
Reason do not remove the cache folder generally is because some gems have actual cache folders that they used.
- #rm_rf(path) ⇒ Object
- #say(message) ⇒ Object
-
#tidy_bundled ⇒ Object
folders to remove in the vendor/bundle folder regardless of the level of the folder.
Constructor Details
#initialize(project_root, noop: false) ⇒ Tidy
Returns a new instance of Tidy.
3 4 5 6 |
# File 'lib/jets/builders/tidy.rb', line 3 def initialize(project_root, noop: false) @project_root = project_root @noop = noop end |
Instance Method Details
#always_removals ⇒ Object
These directories will be removed regardless of dir level
81 82 83 |
# File 'lib/jets/builders/tidy.rb', line 81 def always_removals %w[.git spec tmp] end |
#cleanup! ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/jets/builders/tidy.rb', line 8 def cleanup! removals.each do |removal| removal = removal.sub(%r{^/},'') # remove leading slash path = "#{@project_root}/#{removal}" rm_rf(path) end tidy_bundled end |
#get_removals(file) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/jets/builders/tidy.rb', line 30 def get_removals(file) path = file return [] unless File.exist?(path) removal = File.read(path).split("\n") removal.map {|i| i.strip}.reject {|i| i =~ /^#/ || i.empty?} # IE: ["/handlers", "/bundled*", "/vendor/jets] end |
#jetskeep ⇒ Object
We clean out ignored files pretty aggressively. So provide a way for users to keep files from being cleaned out.
41 42 43 44 45 46 47 48 49 |
# File 'lib/jets/builders/tidy.rb', line 41 def jetskeep defaults = %w[.bundle bundled pack handlers public/assets] path = "#{@project_root}/.jetskeep" return defaults unless File.exist?(path) keep = IO.readlines(path) keep = keep.map {|i| i.strip}.reject { |i| i =~ /^#/ || i.empty? } (defaults + keep).uniq end |
#removals ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/jets/builders/tidy.rb', line 18 def removals removals = always_removals removals += get_removals("#{@project_root}/.gitignore") removals += get_removals("#{@project_root}/.dockerignore") removals = removals.reject do |p| jetskeep.find do |keep| p.include?(keep) end end removals.uniq end |
#remove_gem_cache ⇒ Object
Reason do not remove the cache folder generally is because some gems have actual cache folders that they used.
66 67 68 69 70 |
# File 'lib/jets/builders/tidy.rb', line 66 def remove_gem_cache ruby_minor_version = Jets::RUBY_VERSION.split('.')[0..1].join('.') + '.0' cache_path = "#{@project_root}/vendor/bundle/ruby/#{ruby_minor_version}/cache" FileUtils.rm_rf(cache_path) end |
#rm_rf(path) ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/jets/builders/tidy.rb', line 72 def rm_rf(path) exists = File.exist?("#{path}/.gitkeep") || File.exist?("#{path}/.keep") return if exists # say " rm -rf #{path}".colorize(:yellow) # uncomment to debug system("rm -rf #{path}") unless @noop end |
#say(message) ⇒ Object
85 86 87 88 |
# File 'lib/jets/builders/tidy.rb', line 85 def say() = "NOOP #{}" if @noop puts end |
#tidy_bundled ⇒ Object
folders to remove in the vendor/bundle folder regardless of the level of the folder
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/jets/builders/tidy.rb', line 52 def tidy_bundled Dir.glob("#{@project_root}/vendor/bundle/**/*").each do |path| next unless File.directory?(path) dir = File.basename(path) next unless always_removals.include?(dir) rm_rf(path) end remove_gem_cache end |