From af7883b4fc136a9e95e4705d9c8fc4166ee086d0 Mon Sep 17 00:00:00 2001 From: Ali Hamdi Ali Fadel Date: Sun, 1 Sep 2024 10:39:04 +0000 Subject: [PATCH] Simplify generators main running loop --- generators/bootstrap.rb | 10 +--------- generators/flag.rb | 10 +--------- generators/helper.rb | 12 ++++++++++++ generators/hero.rb | 10 +--------- generators/lucide.rb | 10 +--------- 5 files changed, 16 insertions(+), 36 deletions(-) diff --git a/generators/bootstrap.rb b/generators/bootstrap.rb index 77b3301d9..c39a749be 100644 --- a/generators/bootstrap.rb +++ b/generators/bootstrap.rb @@ -39,15 +39,7 @@ def view_template }.freeze def main - clone_repo(REPO_URL, REPO_NAME) - prepare_phlex_icons_pack_directory(ICONS_PACK_PATH) - - print 'āŒ› Creating icon components...' - icon_file_paths.tqdm.each { create_icon_component(_1) } - puts "\ršŸŽ‰ Icon components created successfully!" - - run_rubocop(ICONS_PACK_PATH) - delete_repo(REPO_NAME) + run_generator { icon_file_paths.tqdm.each { create_icon_component(_1) } } end def icon_file_paths diff --git a/generators/flag.rb b/generators/flag.rb index 0baa7316f..db87be604 100644 --- a/generators/flag.rb +++ b/generators/flag.rb @@ -29,15 +29,7 @@ def rectangle TEMPLATE def main - clone_repo(REPO_URL, REPO_NAME) - prepare_phlex_icons_pack_directory(ICONS_PACK_PATH) - - print 'āŒ› Creating icon components...' - icon_file_names.tqdm.each { create_icon_component(_1) } - puts "\ršŸŽ‰ Icon components created successfully!" - - run_rubocop(ICONS_PACK_PATH) - delete_repo(REPO_NAME) + run_generator { icon_file_names.tqdm.each { create_icon_component(_1) } } end def icon_file_names diff --git a/generators/helper.rb b/generators/helper.rb index bfe7ad79a..88074ebf0 100644 --- a/generators/helper.rb +++ b/generators/helper.rb @@ -13,6 +13,18 @@ Metrics/MethodLength ].join(',') +def run_generator(&block) + clone_repo(REPO_URL, REPO_NAME) + prepare_phlex_icons_pack_directory(ICONS_PACK_PATH) + + print 'āŒ› Creating icon components...' + yield block + puts "\ršŸŽ‰ Icon components created successfully!" + + run_rubocop(ICONS_PACK_PATH) + delete_repo(REPO_NAME) +end + def clone_repo(repo_url, repo_name) print "āŒ› Cloning '#{repo_name}' repo..." diff --git a/generators/hero.rb b/generators/hero.rb index 19877e3c5..2283bf2f0 100644 --- a/generators/hero.rb +++ b/generators/hero.rb @@ -29,15 +29,7 @@ def outline TEMPLATE def main - clone_repo(REPO_URL, REPO_NAME) - prepare_phlex_icons_pack_directory(ICONS_PACK_PATH) - - print 'āŒ› Creating icon components...' - icon_file_names.tqdm.each { create_icon_component(_1) } - puts "\ršŸŽ‰ Icon components created successfully!" - - run_rubocop(ICONS_PACK_PATH) - delete_repo(REPO_NAME) + run_generator { icon_file_names.tqdm.each { create_icon_component(_1) } } end def icon_file_names diff --git a/generators/lucide.rb b/generators/lucide.rb index 63f1b3ad7..342cb3311 100644 --- a/generators/lucide.rb +++ b/generators/lucide.rb @@ -25,15 +25,7 @@ def view_template TEMPLATE def main - clone_repo(REPO_URL, REPO_NAME) - prepare_phlex_icons_pack_directory(ICONS_PACK_PATH) - - print 'āŒ› Creating icon components...' - icon_file_paths.tqdm.each { create_icon_component(_1) } - puts "\ršŸŽ‰ Icon components created successfully!" - - run_rubocop(ICONS_PACK_PATH) - delete_repo(REPO_NAME) + run_generator { icon_file_paths.tqdm.each { create_icon_component(_1) } } end def icon_file_paths