rails-blocks-cli 0.1.4 → 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 +30 -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
|
|
@@ -223,7 +225,7 @@ module RailsBlocks
|
|
|
223
225
|
end
|
|
224
226
|
|
|
225
227
|
def logout
|
|
226
|
-
save_config(config.
|
|
228
|
+
save_config(config.except("api_token"))
|
|
227
229
|
puts "Logged out."
|
|
228
230
|
end
|
|
229
231
|
|
|
@@ -441,7 +443,7 @@ module RailsBlocks
|
|
|
441
443
|
end
|
|
442
444
|
|
|
443
445
|
counts[:changed] += 1
|
|
444
|
-
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))
|
|
445
447
|
end
|
|
446
448
|
|
|
447
449
|
def update_file(destination, new_content, counts)
|
|
@@ -543,7 +545,7 @@ module RailsBlocks
|
|
|
543
545
|
return download(URI.join(url, response["location"]).to_s, redirects: redirects - 1)
|
|
544
546
|
end
|
|
545
547
|
|
|
546
|
-
raise DownloadError,
|
|
548
|
+
raise DownloadError, api_error_message(response) unless response.is_a?(Net::HTTPSuccess)
|
|
547
549
|
|
|
548
550
|
response.body
|
|
549
551
|
end
|
|
@@ -563,11 +565,34 @@ module RailsBlocks
|
|
|
563
565
|
request["Authorization"] = "Bearer #{api_token}" if auth && api_token
|
|
564
566
|
request.body = JSON.generate(body) if body
|
|
565
567
|
response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https") { |http| http.request(request) }
|
|
566
|
-
abort(response
|
|
568
|
+
abort(api_error_message(response)) unless response.is_a?(Net::HTTPSuccess) || response.is_a?(Net::HTTPCreated)
|
|
567
569
|
|
|
568
570
|
JSON.parse(response.body)
|
|
569
571
|
end
|
|
570
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
|
+
|
|
571
596
|
def api_url_for(path)
|
|
572
597
|
return path if path.to_s.match?(%r{\Ahttps?://})
|
|
573
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: []
|