lib/jets/builders/tidy.rb in jets-1.4.5 vs lib/jets/builders/tidy.rb in jets-1.4.6

- old
+ new

@@ -1,7 +1,9 @@ class Jets::Builders class Tidy + include Util + def initialize(project_root, noop: false) @project_root = project_root @noop = noop end @@ -10,13 +12,27 @@ removal = removal.sub(%r{^/},'') # remove leading slash path = "#{@project_root}/#{removal}" rm_rf(path) end - tidy_bundled + clean_vendor_gems + clean_webpack_assets end + # Clean out unnecessary src and compiled packs because Jets serves them out of s3. + # This keeps the code size down to help keep it in size limit so we can use the + # live Lambda console editor. + def clean_webpack_assets + FileUtils.rm_rf("#{@project_root}/app/javascript/src") + + return unless File.exist?("#{@project_root}/public/packs") # this class works for rack subfolder too + FileUtils.mv("#{@project_root}/public/packs/manifest.json", "#{stage_area}/manifest.json") + FileUtils.rm_rf("#{@project_root}/public/packs") + FileUtils.mkdir_p("#{@project_root}/public/packs") + FileUtils.mv("#{stage_area}/manifest.json", "#{@project_root}/public/packs/manifest.json") + end + def removals removals = always_removals removals += get_removals("#{@project_root}/.gitignore") removals += get_removals("#{@project_root}/.dockerignore") removals = removals.reject do |p| @@ -37,20 +53,20 @@ end # We clean out ignored files pretty aggressively. So provide # a way for users to keep files from being cleaned out. def jetskeep - defaults = %w[.bundle pack handlers public/assets] + always = %w[.bundle packs] path = "#{@project_root}/.jetskeep" - return defaults unless File.exist?(path) + return always unless File.exist?(path) keep = IO.readlines(path) keep = keep.map {|i| i.strip}.reject { |i| i =~ /^#/ || i.empty? } - (defaults + keep).uniq + (always + keep).uniq end # folders to remove in the vendor/gems folder regardless of the level of the folder - def tidy_bundled + def clean_vendor_gems Dir.glob("#{@project_root}/vendor/gems/**/*").each do |path| next unless File.directory?(path) dir = File.basename(path) next unless always_removals.include?(dir) \ No newline at end of file