Class: Glyphs::IconPruner

Inherits:
Object
  • Object
show all
Defined in:
lib/glyphs/icon_pruner.rb

Overview

Deletes synced SVG icons that no source references, keeping the union of: scanned references, the configured keep_icons allowlist (names or globs, flat or per-library), and the configured fallback_icons (always — a pruned fallback would make every future missing-icon 500).

Operates only on icons_root (app/assets/svg/icons), skips the bundled animated library, never deletes non-.svg files, and refuses to empty a library whose computed keep-set is empty (guards against a mis-scan wiping a whole library). Returns a PruneReport.

Constant Summary collapse

ANIMATED =
:animated

Instance Method Summary collapse

Constructor Details

#initialize(icons_root:, references:, keep_icons: [], fallback_icons: {}, dry_run: false) ⇒ IconPruner

Returns a new instance of IconPruner.



18
19
20
21
22
23
24
# File 'lib/glyphs/icon_pruner.rb', line 18

def initialize(icons_root:, references:, keep_icons: [], fallback_icons: {}, dry_run: false)
  @icons_root = icons_root
  @references = references
  @keep_icons = keep_icons
  @fallback_icons = fallback_icons
  @dry_run = dry_run
end

Instance Method Details

#callObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/glyphs/icon_pruner.rb', line 26

def call
  stats = []
  deleted_names = []

  grouped_files.each do |(library, variant), files|
    # Guard on library-specific evidence of use, NOT on the merged keep-set:
    # a flat keep_icons list is non-empty for every library, so keying the
    # guard off keep.empty? would let it wipe an entirely-unreferenced
    # library down to whatever the flat list happens to match.
    unless library_used?(library)
      warn "[Glyphs::IconPruner] refusing to prune #{library}/#{variant || '.'}" \
           "no references, fallback, or per-library keep_icons for #{library}"
      next
    end

    keep = keep_names_for(library, variant)
    stat = prune_group(library, variant, files, keep, deleted_names)
    stats << stat
  end

  PruneReport.new(stats:, deleted_names:, dry_run: @dry_run)
end