class Webpacker::Commands
Public Class Methods
new(webpacker)
click to toggle source
# File lib/webpacker/commands.rb, line 4 def initialize(webpacker) @webpacker = webpacker end
Public Instance Methods
bootstrap()
click to toggle source
# File lib/webpacker/commands.rb, line 47 def bootstrap manifest.refresh end
clean(count = 2, age = 3600)
click to toggle source
Cleanup old assets in the compile directory. By default it will keep the latest version, 2 backups created within the past hour.
Examples
To force only 1 backup to be kept, set count=1 and age=0. To only keep files created within the last 10 minutes, set count=0 and age=600.
# File lib/webpacker/commands.rb, line 18 def clean(count = 2, age = 3600) if config.public_output_path.exist? && config.manifest_path.exist? packs .map do |paths| paths.map { |path| [Time.now - File.mtime(path), path] } .sort .reject.with_index do |(file_age, _), index| file_age < age || index < count end .map { |_, path| path } end .flatten .compact .each do |file| if File.file?(file) File.delete(file) logger.info "Removed #{file}" end end end true end
clobber()
click to toggle source
# File lib/webpacker/commands.rb, line 42 def clobber config.public_output_path.rmtree if config.public_output_path.exist? config.cache_path.rmtree if config.cache_path.exist? end
compile()
click to toggle source
# File lib/webpacker/commands.rb, line 51 def compile compiler.compile.tap do |success| manifest.refresh if success end end
Private Instance Methods
current_version()
click to toggle source
# File lib/webpacker/commands.rb, line 69 def current_version packs = manifest.refresh.values.map do |value| value = value["src"] if value.is_a?(Hash) next unless value.is_a?(String) File.join(config.root_path, "public", "#{value}*") end.compact Dir.glob(packs).uniq end
packs()
click to toggle source
# File lib/webpacker/commands.rb, line 58 def packs all_files = Dir.glob("#{config.public_output_path}/**/*") manifest_config = Dir.glob("#{config.manifest_path}*") packs = all_files - manifest_config - current_version packs.reject { |file| File.directory?(file) }.group_by do |path| base, _, ext = File.basename(path).scan(/(.*)(-[\da-f]+)(\.\w+)/).flatten "#{File.dirname(path)}/#{base}#{ext}" end.values end