class ViteRuby::Commands
def clean(keep_up_to: 2, age_in_seconds: 3600)
To force only 1 backup to be kept: clean(1, 0)
Examples:
NOTE: By default keeps the last version, or 2 if created in the past hour.
age_in_seconds - Amount of time to look back in order to preserve them.
keep_up_to - Max amount of backups to preserve.
Public: Cleanup old assets in the output directory.
def clean(keep_up_to: 2, age_in_seconds: 3600) return false unless may_clean? versions .each_with_index .drop_while { |(mtime, _), index| max_age = [0, Time.now - Time.at(mtime)].max max_age < age_in_seconds || index < keep_up_to } .each do |(_, files), _| clean_files(files) end true end