rails-blocks-cli 0.1.3 → 0.1.5
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/README.md +1 -1
- data/lib/rails_blocks/cli.rb +40 -5
- metadata +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6c87aed14419d63248e9ef90191e488185d312908937f2b24893fc8b1d6c3bcc
|
|
4
|
+
data.tar.gz: f8ae64409d5cb609e397e463fdffbd4c3ce6f7028fb87e57bd54f4b4b4ed9f47
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5ec78cb9dd3561566105460a5aedc81a07c8a7ff4a3b22a3446a743eb457c3c7bb9b4fbabc9a73b1559d7e38f85e480e1adc37bf7bdfed32321985154ad71e51
|
|
7
|
+
data.tar.gz: 32ef4293378e1f9aee1a761d4d0ca3388d12267895be3ed218fa48394389a1a90fa1f1e294e53dd99528a851bac6183ad08807f650478fc03d4d1964f1c768ed
|
data/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Static-first installer for Rails Blocks components.
|
|
4
4
|
|
|
5
|
-
Free
|
|
5
|
+
Free components are installed from the public `Rails-Blocks/components` GitHub repo. Sign in only when you want account status or Pro component access.
|
|
6
6
|
|
|
7
7
|
## Example
|
|
8
8
|
|
data/lib/rails_blocks/cli.rb
CHANGED
|
@@ -8,10 +8,12 @@ require "zip"
|
|
|
8
8
|
|
|
9
9
|
module RailsBlocks
|
|
10
10
|
class CLI
|
|
11
|
-
DownloadError
|
|
11
|
+
class DownloadError < StandardError
|
|
12
|
+
end
|
|
12
13
|
|
|
13
14
|
DEFAULT_REGISTRY_URL = "https://raw.githubusercontent.com/Rails-Blocks/components/main/registry.json".freeze
|
|
14
15
|
DEFAULT_API_URL = "https://railsblocks.com".freeze
|
|
16
|
+
DEFAULT_PRO_URL = "https://railsblocks.com/pro".freeze
|
|
15
17
|
|
|
16
18
|
def initialize(argv)
|
|
17
19
|
@argv = argv.dup
|
|
@@ -109,6 +111,7 @@ module RailsBlocks
|
|
|
109
111
|
abort "Usage: rails-blocks install COMPONENT [--as erb_template|view_component|partial] [--path PATH] [--stimulus-path PATH] [--dry-run] [--force]" if slug.to_s.empty?
|
|
110
112
|
|
|
111
113
|
component = find_component(slug)
|
|
114
|
+
installation_prerequisite_notice
|
|
112
115
|
install_component(component, implementation, dry_run: dry_run)
|
|
113
116
|
end
|
|
114
117
|
|
|
@@ -116,6 +119,8 @@ module RailsBlocks
|
|
|
116
119
|
selected_components = components.select { |component| include_component?(component) }
|
|
117
120
|
abort "No components matched the selected filters." if selected_components.empty?
|
|
118
121
|
|
|
122
|
+
installation_prerequisite_notice
|
|
123
|
+
|
|
119
124
|
failures = []
|
|
120
125
|
|
|
121
126
|
selected_components.each do |component|
|
|
@@ -220,7 +225,7 @@ module RailsBlocks
|
|
|
220
225
|
end
|
|
221
226
|
|
|
222
227
|
def logout
|
|
223
|
-
save_config(config.
|
|
228
|
+
save_config(config.except("api_token"))
|
|
224
229
|
puts "Logged out."
|
|
225
230
|
end
|
|
226
231
|
|
|
@@ -361,6 +366,13 @@ module RailsBlocks
|
|
|
361
366
|
puts " Markdown: #{markdown_docs_url(component)}"
|
|
362
367
|
end
|
|
363
368
|
|
|
369
|
+
def installation_prerequisite_notice
|
|
370
|
+
return if ENV["RAILS_BLOCKS_HIDE_INSTALL_NOTICE"] == "1"
|
|
371
|
+
|
|
372
|
+
puts muted("Before installing components, make sure your app has completed the setup steps: https://railsblocks.com/docs/installation")
|
|
373
|
+
puts
|
|
374
|
+
end
|
|
375
|
+
|
|
364
376
|
def web_docs_url(component)
|
|
365
377
|
component["docs_url"] || "https://railsblocks.com/docs/#{component['slug'].tr('_', '-')}"
|
|
366
378
|
end
|
|
@@ -431,7 +443,7 @@ module RailsBlocks
|
|
|
431
443
|
end
|
|
432
444
|
|
|
433
445
|
counts[:changed] += 1
|
|
434
|
-
puts unified_diff(old_content, new_content, destination.exist? ? display_path(destination) :
|
|
446
|
+
puts unified_diff(old_content, new_content, destination.exist? ? display_path(destination) : File::NULL, display_path(destination))
|
|
435
447
|
end
|
|
436
448
|
|
|
437
449
|
def update_file(destination, new_content, counts)
|
|
@@ -533,7 +545,7 @@ module RailsBlocks
|
|
|
533
545
|
return download(URI.join(url, response["location"]).to_s, redirects: redirects - 1)
|
|
534
546
|
end
|
|
535
547
|
|
|
536
|
-
raise DownloadError,
|
|
548
|
+
raise DownloadError, api_error_message(response) unless response.is_a?(Net::HTTPSuccess)
|
|
537
549
|
|
|
538
550
|
response.body
|
|
539
551
|
end
|
|
@@ -553,11 +565,34 @@ module RailsBlocks
|
|
|
553
565
|
request["Authorization"] = "Bearer #{api_token}" if auth && api_token
|
|
554
566
|
request.body = JSON.generate(body) if body
|
|
555
567
|
response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https") { |http| http.request(request) }
|
|
556
|
-
abort(response
|
|
568
|
+
abort(api_error_message(response)) unless response.is_a?(Net::HTTPSuccess) || response.is_a?(Net::HTTPCreated)
|
|
557
569
|
|
|
558
570
|
JSON.parse(response.body)
|
|
559
571
|
end
|
|
560
572
|
|
|
573
|
+
def api_error_message(response)
|
|
574
|
+
parsed = JSON.parse(response.body)
|
|
575
|
+
message = parsed["message"].to_s.strip
|
|
576
|
+
|
|
577
|
+
case parsed["error"]
|
|
578
|
+
when "pro_required"
|
|
579
|
+
upgrade_url = parsed["upgrade_url"].to_s.strip
|
|
580
|
+
[
|
|
581
|
+
message.empty? ? "Rails Blocks Pro is required for this component." : message,
|
|
582
|
+
"Upgrade to Rails Blocks Pro: #{upgrade_url.empty? ? DEFAULT_PRO_URL : upgrade_url}"
|
|
583
|
+
].join("\n")
|
|
584
|
+
when "unauthorized"
|
|
585
|
+
[
|
|
586
|
+
message.empty? ? "Provide a valid Rails Blocks API token." : message,
|
|
587
|
+
"Run `rails-blocks login` if you already have Pro access, or upgrade at #{DEFAULT_PRO_URL}."
|
|
588
|
+
].join("\n")
|
|
589
|
+
else
|
|
590
|
+
message.empty? ? "#{response.code} #{response.message}" : message
|
|
591
|
+
end
|
|
592
|
+
rescue JSON::ParserError
|
|
593
|
+
"#{response.code} #{response.message}"
|
|
594
|
+
end
|
|
595
|
+
|
|
561
596
|
def api_url_for(path)
|
|
562
597
|
return path if path.to_s.match?(%r{\Ahttps?://})
|
|
563
598
|
|
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.
|
|
4
|
+
version: 0.1.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Rails Blocks
|
|
@@ -15,14 +15,14 @@ dependencies:
|
|
|
15
15
|
requirements:
|
|
16
16
|
- - "~>"
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: '
|
|
18
|
+
version: '3.4'
|
|
19
19
|
type: :runtime
|
|
20
20
|
prerelease: false
|
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
22
|
requirements:
|
|
23
23
|
- - "~>"
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
|
-
version: '
|
|
25
|
+
version: '3.4'
|
|
26
26
|
executables:
|
|
27
27
|
- rails-blocks
|
|
28
28
|
extensions: []
|
|
@@ -50,7 +50,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
50
50
|
- !ruby/object:Gem::Version
|
|
51
51
|
version: '0'
|
|
52
52
|
requirements: []
|
|
53
|
-
rubygems_version: 4.0.
|
|
53
|
+
rubygems_version: 4.0.23
|
|
54
54
|
specification_version: 4
|
|
55
55
|
summary: Install Rails Blocks components from the command line
|
|
56
56
|
test_files: []
|