Class: LocoMotion::Icons::Vendorer
- Inherits:
-
Object
- Object
- LocoMotion::Icons::Vendorer
- Defined in:
- lib/loco_motion/icons/vendorer.rb
Overview
Copies a treeshaken set of icons from a fully-synced source tree into the
application's vendored app/assets/svg/icons, given the references found
by Scanner (plus any safelist).
It is pure file I/O — the caller is responsible for first populating
source with the full upstream libraries (e.g. via
Installer); keeping the network step out of here
makes the copy/prune logic deterministic and unit-testable.
Each referenced library directory under target is rebuilt from scratch,
so icons that are no longer referenced are pruned. Libraries that are not
referenced at all are left untouched.
Defined Under Namespace
Classes: Result
Instance Method Summary collapse
-
#initialize(source:, target:, default_variant:) ⇒ Vendorer
constructor
A new instance of Vendorer.
-
#vendor(references) ⇒ Result
Counts of vendored icons, the references whose source SVG was missing, and the libraries that were rebuilt.
Constructor Details
#initialize(source:, target:, default_variant:) ⇒ Vendorer
Returns a new instance of Vendorer.
34 35 36 37 38 |
# File 'lib/loco_motion/icons/vendorer.rb', line 34 def initialize(source:, target:, default_variant:) @source = source.to_s @target = target.to_s @default_variant = default_variant end |
Instance Method Details
#vendor(references) ⇒ Result
Returns Counts of vendored icons, the references whose source SVG was missing, and the libraries that were rebuilt.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/loco_motion/icons/vendorer.rb', line 46 def vendor(references) libraries = references.map { |ref| ref[:library] }.uniq.sort libraries.each { |library| ::FileUtils.rm_rf(::File.join(@target, library)) } vendored = 0 missing = [] references.each do |ref| if copy(ref) vendored += 1 else missing << ref end end Result.new(vendored: vendored, missing: missing, libraries: libraries) end |