rails-blocks-cli 0.1.1 → 0.1.2

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rails_blocks/cli.rb +31 -21
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c4f132c448c8e065b701c21e0e5b777d24fea8ab32c32870f51c84d4a68626cc
4
- data.tar.gz: 4e703d0337c0a8504773d803afef6b83b6cf6a62ec9dca8a2d048fcd4175bec0
3
+ metadata.gz: 63dd443055d6116deb6a9945e9aa025d6cee699603ac48278dc56d541c567e58
4
+ data.tar.gz: f8f4993d4a4b63083b8644040e02bf35653cefcbb04ce9f03d319ef3820dacde
5
5
  SHA512:
6
- metadata.gz: e616247429678b871ce785aa979b2b5922deaaa153b94f0fefeec5261fa8791318a8938ae67c11a602db1a48f884e794334f3df25dac0a82c2be8fa667ab671a
7
- data.tar.gz: d8271aef17019e1244f64fb098bdfbd35ce975f16f5b989143a5ba2df72f4946c121a8dd4e9da48a267bc45c78cb3999e83411f385b9302ee330775b3051ef77
6
+ metadata.gz: ae54a971c219716f16a227a27185078bc00dd33e94a6eb5d858a4e665e653b9ea921485cb3b334e36610d324fa300d8eb691bb50eb89a53d1b0fa18327b53fd6
7
+ data.tar.gz: 397f72909bbd30ad2e94991e59c34a25ac4e3d3f409062a3dbac3044af7bfb7ada4f22f54c0e6bab7236b446744d09c633bda996def8cecfa07c4d39ccba17af
@@ -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']}#{component['pro'] ? ' (pro)' : ''} as #{implementation}")
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 => error
126
- failures << [component["slug"], error.message]
127
- warn "Failed to install #{component['slug']}: #{error.message}"
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']}#{component['pro'] ? ' (pro)' : ''} as #{package_implementation}..."
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 => error
178
- failures << [component["slug"], error.message]
179
- warn "Failed to #{mode} #{component['slug']}: #{error.message}"
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."
@@ -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.to_s : "/dev/null", destination.to_s)
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') ? 'Would update' : old_content.nil? ? 'Writing' : 'Updating'} #{destination}"
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 => error
511
- abort "Could not load the Rails Blocks registry from #{registry_url}: #{error.message}"
512
- rescue JSON::ParserError => error
513
- abort "Could not parse the Rails Blocks registry from #{registry_url}: #{error.message}"
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?(/\Ahttps?:\/\//)
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"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-blocks-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rails Blocks