rails-blocks-cli 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/rails_blocks/cli.rb +34 -24
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 78febd1a26563e29b3f204eba4637045f7b3d13f1ab71c24087ca3af18f6fcf7
|
|
4
|
+
data.tar.gz: '03350359aec7aaeb541df9fd8e8517d5db982a66830809223bbb713fc5b17119'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 450da6b723c24f6ad1b06e32509be34b414adc528963c3e7c951195d10869e0f00c82d4e75ebb4f18a546fc86361393bb7bd10378485baa93d40a69a6d8fb692
|
|
7
|
+
data.tar.gz: fc0de1f135151d6b9e9745b1c0842b116d54241d98a05a203d787b25dea6d0834d6461c5aa9145d0530865abf638159756f1dd906262d5db2bf7031d47ccc665
|
data/lib/rails_blocks/cli.rb
CHANGED
|
@@ -2,7 +2,6 @@ require "fileutils"
|
|
|
2
2
|
require "json"
|
|
3
3
|
require "net/http"
|
|
4
4
|
require "open3"
|
|
5
|
-
require "pathname"
|
|
6
5
|
require "tempfile"
|
|
7
6
|
require "uri"
|
|
8
7
|
require "zip"
|
|
@@ -120,11 +119,11 @@ module RailsBlocks
|
|
|
120
119
|
failures = []
|
|
121
120
|
|
|
122
121
|
selected_components.each do |component|
|
|
123
|
-
say_heading("Installing #{component['slug']}#{
|
|
122
|
+
say_heading("Installing #{component['slug']}#{' (pro)' if component['pro']} as #{implementation}")
|
|
124
123
|
install_component(component, implementation, dry_run: dry_run)
|
|
125
|
-
rescue StandardError =>
|
|
126
|
-
failures << [component["slug"],
|
|
127
|
-
warn "Failed to install #{component['slug']}: #{
|
|
124
|
+
rescue StandardError => e
|
|
125
|
+
failures << [component["slug"], e.message]
|
|
126
|
+
warn "Failed to install #{component['slug']}: #{e.message}"
|
|
128
127
|
end
|
|
129
128
|
|
|
130
129
|
puts "\nInstalled #{selected_components.size - failures.size} of #{selected_components.size} components."
|
|
@@ -172,11 +171,11 @@ module RailsBlocks
|
|
|
172
171
|
failures = []
|
|
173
172
|
|
|
174
173
|
selected_components.each do |component|
|
|
175
|
-
puts "\n#{mode_label(mode)} #{component['slug']}#{
|
|
174
|
+
puts "\n#{mode_label(mode)} #{component['slug']}#{' (pro)' if component['pro']} as #{package_implementation}..."
|
|
176
175
|
change_component_files(component, mode: mode)
|
|
177
|
-
rescue StandardError =>
|
|
178
|
-
failures << [component["slug"],
|
|
179
|
-
warn "Failed to #{mode} #{component['slug']}: #{
|
|
176
|
+
rescue StandardError => e
|
|
177
|
+
failures << [component["slug"], e.message]
|
|
178
|
+
warn "Failed to #{mode} #{component['slug']}: #{e.message}"
|
|
180
179
|
end
|
|
181
180
|
|
|
182
181
|
puts "\n#{mode_label(mode)} #{selected_components.size - failures.size} of #{selected_components.size} components."
|
|
@@ -284,8 +283,8 @@ module RailsBlocks
|
|
|
284
283
|
download(response["url"], auth: true)
|
|
285
284
|
end
|
|
286
285
|
|
|
287
|
-
def stimulus_package_data
|
|
288
|
-
type
|
|
286
|
+
def stimulus_package_data(type: nil)
|
|
287
|
+
type ||= component_filter == :pro ? "pro" : "free"
|
|
289
288
|
if type == "free"
|
|
290
289
|
stimulus_artifact = registry["stimulus_controllers"]
|
|
291
290
|
return download(stimulus_artifact["package_url"]) if stimulus_artifact&.dig("package_url")
|
|
@@ -298,7 +297,7 @@ module RailsBlocks
|
|
|
298
297
|
if component["stimulus_package_url"]
|
|
299
298
|
download(component["stimulus_package_url"])
|
|
300
299
|
else
|
|
301
|
-
stimulus_package_data
|
|
300
|
+
stimulus_package_data(type: component["pro"] ? "pro" : "free")
|
|
302
301
|
end
|
|
303
302
|
end
|
|
304
303
|
|
|
@@ -320,7 +319,7 @@ module RailsBlocks
|
|
|
320
319
|
|
|
321
320
|
destination = stimulus_destination(filename)
|
|
322
321
|
if destination.exist? && !argv.include?("--force")
|
|
323
|
-
puts "#{muted('Skip')} #{destination} #{muted('(already exists)')}"
|
|
322
|
+
puts "#{muted('Skip')} #{display_path(destination)} #{muted('(already exists)')}"
|
|
324
323
|
next
|
|
325
324
|
end
|
|
326
325
|
|
|
@@ -329,7 +328,7 @@ module RailsBlocks
|
|
|
329
328
|
end
|
|
330
329
|
|
|
331
330
|
def write_file(destination, content, dry_run:)
|
|
332
|
-
puts "#{dry_run ? muted('Would write') : success('Writing')} #{destination}"
|
|
331
|
+
puts "#{dry_run ? muted('Would write') : success('Writing')} #{display_path(destination)}"
|
|
333
332
|
return if dry_run
|
|
334
333
|
|
|
335
334
|
raise "#{destination} already exists. Use --force to overwrite it." if destination.exist? && !argv.include?("--force")
|
|
@@ -427,24 +426,28 @@ module RailsBlocks
|
|
|
427
426
|
old_content = destination.exist? ? File.binread(destination) : ""
|
|
428
427
|
if old_content == new_content
|
|
429
428
|
counts[:unchanged] += 1
|
|
430
|
-
puts "No changes #{destination}"
|
|
429
|
+
puts "No changes #{display_path(destination)}"
|
|
431
430
|
return
|
|
432
431
|
end
|
|
433
432
|
|
|
434
433
|
counts[:changed] += 1
|
|
435
|
-
puts unified_diff(old_content, new_content, destination.exist? ? destination
|
|
434
|
+
puts unified_diff(old_content, new_content, destination.exist? ? display_path(destination) : "/dev/null", display_path(destination))
|
|
436
435
|
end
|
|
437
436
|
|
|
438
437
|
def update_file(destination, new_content, counts)
|
|
439
438
|
old_content = destination.exist? ? File.binread(destination) : nil
|
|
440
439
|
if old_content == new_content
|
|
441
440
|
counts[:unchanged] += 1
|
|
442
|
-
puts "Unchanged #{destination}"
|
|
441
|
+
puts "Unchanged #{display_path(destination)}"
|
|
443
442
|
return
|
|
444
443
|
end
|
|
445
444
|
|
|
446
445
|
counts[:changed] += 1
|
|
447
|
-
puts "#{argv.include?('--dry-run')
|
|
446
|
+
puts "#{if argv.include?('--dry-run')
|
|
447
|
+
'Would update'
|
|
448
|
+
else
|
|
449
|
+
old_content.nil? ? 'Writing' : 'Updating'
|
|
450
|
+
end} #{display_path(destination)}"
|
|
448
451
|
return if argv.include?("--dry-run")
|
|
449
452
|
|
|
450
453
|
FileUtils.mkdir_p(destination.dirname)
|
|
@@ -477,6 +480,13 @@ module RailsBlocks
|
|
|
477
480
|
mode == :diff ? "Diffing" : "Updating"
|
|
478
481
|
end
|
|
479
482
|
|
|
483
|
+
def display_path(path)
|
|
484
|
+
pathname = Pathname.new(path)
|
|
485
|
+
pathname.relative_path_from(Pathname.pwd).to_s
|
|
486
|
+
rescue ArgumentError
|
|
487
|
+
pathname.to_s
|
|
488
|
+
end
|
|
489
|
+
|
|
480
490
|
def components
|
|
481
491
|
registry.fetch("components")
|
|
482
492
|
end
|
|
@@ -507,10 +517,10 @@ module RailsBlocks
|
|
|
507
517
|
|
|
508
518
|
def registry
|
|
509
519
|
@registry ||= JSON.parse(download(registry_url))
|
|
510
|
-
rescue DownloadError =>
|
|
511
|
-
abort "Could not load the Rails Blocks registry from #{registry_url}: #{
|
|
512
|
-
rescue JSON::ParserError =>
|
|
513
|
-
abort "Could not parse the Rails Blocks registry from #{registry_url}: #{
|
|
520
|
+
rescue DownloadError => e
|
|
521
|
+
abort "Could not load the Rails Blocks registry from #{registry_url}: #{e.message}"
|
|
522
|
+
rescue JSON::ParserError => e
|
|
523
|
+
abort "Could not parse the Rails Blocks registry from #{registry_url}: #{e.message}"
|
|
514
524
|
end
|
|
515
525
|
|
|
516
526
|
def download(url, auth: false, redirects: 3)
|
|
@@ -549,7 +559,7 @@ module RailsBlocks
|
|
|
549
559
|
end
|
|
550
560
|
|
|
551
561
|
def api_url_for(path)
|
|
552
|
-
return path if path.to_s.match?(
|
|
562
|
+
return path if path.to_s.match?(%r{\Ahttps?://})
|
|
553
563
|
|
|
554
564
|
URI.join(api_url, path).to_s
|
|
555
565
|
end
|
|
@@ -578,7 +588,7 @@ module RailsBlocks
|
|
|
578
588
|
puts bold("Choose an install format")
|
|
579
589
|
puts " 1. ERB partials #{muted('app/views/shared/<component>/')}"
|
|
580
590
|
puts " 2. ViewComponent #{muted('app/components/<component>/')}"
|
|
581
|
-
print "Select an option [1]: "
|
|
591
|
+
print "Select an option [1 by default]: "
|
|
582
592
|
|
|
583
593
|
case $stdin.gets&.strip
|
|
584
594
|
when "2", "view_component" then "view_component"
|