From 93a35d7822089fdf67408ef38d824f0066f1878a Mon Sep 17 00:00:00 2001 From: eelco Date: Wed, 18 Dec 2024 12:08:43 +0100 Subject: [PATCH] Option-less sync Sync all previously installed libraries by running `rails g rails_icons:sync`. Sync ony specific libraries by running `rails g rails_icons:sync --libraries=heroicons` --- README.md | 8 +++----- lib/generators/rails_icons/sync_generator.rb | 16 ++++++++++++++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 6a446a3..46d1d48 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,6 @@ Need to use an icon from another library? 2. add the (SVG) icons to the created directory **app/assets/svg/icons/simple_icons**; Every custom icon can now be used with the same interface as first-party icon libraries. - ```ruby icon "apple", library: "simple_icons", class: "text-black" ``` @@ -101,13 +100,12 @@ icon "apple", library: "simple_icons", class: "text-black" ## Sync icons -If a library gets updated, sync the icons to your app by running - +To sync all installed libraries, run ```bash -rails generate rails_icons:sync --libraries=LIBRARY_NAME +rails generate rails_icons:sync ``` -**Example** +To sync only a specific library, run ```bash rails generate rails_icons:sync --libraries=heroicons diff --git a/lib/generators/rails_icons/sync_generator.rb b/lib/generators/rails_icons/sync_generator.rb index 3a26f26..1f6e30f 100644 --- a/lib/generators/rails_icons/sync_generator.rb +++ b/lib/generators/rails_icons/sync_generator.rb @@ -11,9 +11,21 @@ class SyncGenerator < Rails::Generators::Base source_root File.expand_path("templates", __dir__) def sync_icons - raise "[Rails Icons] Not a valid library" if options[:libraries].empty? + raise "[Rails Icons] Not a valid library" if libraries.empty? - options[:libraries].each { Sync::Engine.new(_1).sync } + libraries.each { Sync::Engine.new(_1).sync } + end + + private + + def libraries + options[:libraries].presence || synced_libraries + end + + def synced_libraries + RailsIcons.libraries.keys.map(&:to_s).select do |library| + Dir.exist?(File.join(RailsIcons.configuration.destination_path, library.to_s)) + end end end end