bootic_cli 0.9.5 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4e9689455a4845de27825aa295f27f84c1e45035bbb350413f85f171a26e4bd0
4
- data.tar.gz: ce296652260b9f18af912d636272b6df039be1207584c2b6d619ecfd3cfb1331
3
+ metadata.gz: 3a7b319613aa209c0359fc9294484bf2f16047915d22aa13a73f8d92a9d041ae
4
+ data.tar.gz: 14d331e257c7e8b24fab5fb22876903d0c994a41850c8f83de7a8dead272a6f9
5
5
  SHA512:
6
- metadata.gz: e3b44f183224b102820bc1f8a4f200d43d277fb385e973d5a792144cda1cc16ea852209c084d364436226dd72a7b377f444e4c9e6aecf70dcf9abe8618367756
7
- data.tar.gz: 855814910c7e021eee1386a2fc1fea56384fd8dad25eead5d4438be5824ff0a9afaecd51c8d3c7ae439d049e17c43eabfd1fc3a49ca5a6527f11d1ce40dcd760
6
+ metadata.gz: 883fd8251b629bb62e777f8dca9ec9215eaa526f00eeafd03fe488afcc032f2e5ebb88d9bf1e0627958652784ce8cb66c6f3736ae41d2bb62489d80149910d73
7
+ data.tar.gz: 50588400d165a7f6b0cd49b6ac4fc53fce4cab3b286ab4333a009472e06fd6e85841d04700b24dbc1a951f64d4fbcb043692942fc6f6a30346c85b77cb5c242c
@@ -184,12 +184,8 @@ module BooticCli
184
184
 
185
185
  # prompt.say("Publishing means all your public theme's templates and assets will be replaced and lost.")
186
186
  if prompt.yes_or_no?("Would you like to make a local copy of your current public theme before publishing?", diff.any?) # default to true if changes exist
187
- backup_path = File.join(local_theme.path, "public-theme-backup-#{Time.now.to_i}")
188
- backup_theme = theme_selector.select_local_theme(backup_path, local_theme.subdomain)
189
-
190
- prompt.say("Gotcha. Backing up your public theme into #{prompt.highlight(backup_theme.path)}")
191
- workflows.pull(backup_theme, public_theme)
192
- prompt.say "Done! Existing public theme was saved to #{prompt.highlight(File.basename(backup_theme.path))}", :cyan
187
+ path = File.join(local_theme.path, "backups", "public-theme-backup-#{Time.now.to_i}")
188
+ create_backup_from(public_theme, local_theme, path)
193
189
  end
194
190
 
195
191
  workflows.publish(local_theme, remote_theme)
@@ -197,6 +193,16 @@ module BooticCli
197
193
  end
198
194
  end
199
195
 
196
+ desc 'backup', 'Create a backup copy of the current remote theme'
197
+ option :dev, banner: '<true|false>', type: :boolean, aliases: '-d', desc: 'Clones development theme instead of the public one (default)'
198
+ def backup(path = nil)
199
+ within_theme do
200
+ local_theme, remote_theme = theme_selector.select_theme_pair(default_subdomain, current_dir, options['dev'].nil?)
201
+ path ||= File.join(local_theme.path, "backups", "#{remote_theme.public? ? 'public' : 'dev'}-theme-backup-#{Time.now.to_i}")
202
+ create_backup_from(remote_theme, local_theme, path)
203
+ end
204
+ end
205
+
200
206
  # desc 'open', 'Open theme preview URL in a browser'
201
207
  # option :public, banner: '<true|false>', type: :boolean, aliases: '-p', desc: 'Opens public theme URL'
202
208
  # def open
@@ -303,6 +309,13 @@ module BooticCli
303
309
  @theme_selector ||= BooticCli::Themes::ThemeSelector.new(root, prompt: prompt)
304
310
  end
305
311
 
312
+ def create_backup_from(theme, local_theme, backup_path)
313
+ backup_theme = theme_selector.select_local_theme(backup_path, local_theme.subdomain)
314
+ prompt.say("Gotcha. Backing up your #{theme.public? ? 'public' : 'dev'} theme into #{prompt.highlight(backup_theme.path)}")
315
+ workflows.pull(backup_theme, theme)
316
+ prompt.say "Done! Existing #{theme.public? ? 'public' : 'dev'} theme was saved to #{prompt.highlight(File.basename(backup_theme.path))}", :cyan
317
+ end
318
+
306
319
  class Prompt
307
320
  def initialize(shell = Thor::Shell::Color.new)
308
321
  @shell = shell
@@ -1,5 +1,5 @@
1
1
  require 'time'
2
- require 'net/http'
2
+ require 'bootic_cli/utils'
3
3
 
4
4
  module BooticCli
5
5
  module Themes
@@ -15,13 +15,8 @@ module BooticCli
15
15
  end
16
16
 
17
17
  class APIAsset < ItemWithTime
18
- REQUEST_OPTS = {
19
- open_timeout: 5,
20
- read_timeout: 5
21
- }
22
-
23
18
  def file
24
- @file ||= StringIO.new(fetch_data)
19
+ @file ||= BooticCli::Utils.fetch_http_file(rels[:file].href)
25
20
  end
26
21
 
27
22
  def ==(other)
@@ -34,27 +29,6 @@ module BooticCli
34
29
  # puts "Comparing APIAsset vs other digest:\n#{digest}\n#{other.digest}"
35
30
  self.digest == other.digest # && self.file_size == other.file_size
36
31
  end
37
-
38
- def fetch_data(attempt = 1, skip_verify = false)
39
- uri = URI.parse(rels[:file].href)
40
- opts = REQUEST_OPTS.merge({
41
- verify_mode: skip_verify ? OpenSSL::SSL::VERIFY_NONE : OpenSSL::SSL::VERIFY_PEER,
42
- use_ssl: uri.port == 443
43
- })
44
-
45
- Net::HTTP.start(uri.host, uri.port, opts) do |http|
46
- resp = http.get(uri.path)
47
- raise "Invalid response: #{resp.code}" unless resp.code.to_i == 200
48
- resp.body
49
- end
50
- rescue Net::OpenTimeout, Net::ReadTimeout => e
51
- raise if attempt > 3 # max attempts
52
- # puts "#{e.class} for #{File.basename(uri.path)}! Retrying request..."
53
- fetch_data(attempt + 1)
54
- rescue OpenSSL::SSL::SSLError => e
55
- # retry but skipping verification
56
- fetch_data(attempt + 1, true)
57
- end
58
32
  end
59
33
 
60
34
  class APITheme
@@ -30,12 +30,16 @@ module BooticCli
30
30
  end
31
31
 
32
32
  ASSETS_DIR = 'assets'.freeze
33
- TEMPLATE_PATTERNS = ['sections/*.html', '*.html', '*.css', '*.js', '*.json', '*.yml'].freeze
33
+ TEMPLATE_PATTERNS = [
34
+ '*.html', '*.css', '*.js', '*.json', '*.yml',
35
+ 'sections/*.html', 'partials/*.html', 'data/*.json', 'data/*.yml'
36
+ ].freeze
34
37
  ASSET_PATTERNS = [File.join(ASSETS_DIR, '*')].freeze
35
38
 
36
39
  ASSET_PATH_REGEX = /^assets\/[^\/]+$/.freeze
37
40
  TEMPLATE_PATH_REGEX = /^[^\/]+\.(html|css|scss|js|json|yml)$/.freeze
38
- SECTION_PATH_REGEX = /^sections\/[^\/]+.html$/.freeze
41
+ SECTION_PATH_REGEX = /^(sections|partials)\/[^\/]+\.html$/.freeze
42
+ DATA_PATH_REGEX = /^data\/[^\/]+\.(json|yml)$/.freeze
39
43
 
40
44
  def self.resolve_path(path, dir)
41
45
  File.expand_path(path).sub(File.expand_path(dir) + '/', '')
@@ -48,7 +52,7 @@ module BooticCli
48
52
 
49
53
  if relative_path[ASSET_PATH_REGEX]
50
54
  :asset
51
- elsif relative_path[TEMPLATE_PATH_REGEX] || relative_path[SECTION_PATH_REGEX]
55
+ elsif relative_path[TEMPLATE_PATH_REGEX] || relative_path[SECTION_PATH_REGEX] || relative_path[DATA_PATH_REGEX]
52
56
  :template
53
57
  end
54
58
  end
@@ -104,7 +108,7 @@ module BooticCli
104
108
 
105
109
  def templates
106
110
  @templates ||= (
107
- paths_for(TEMPLATE_PATTERNS).sort.map do |path|
111
+ paths_for(TEMPLATE_PATTERNS).map do |path|
108
112
  name = self.class.resolve_path(path, dir)
109
113
  file = File.new(path)
110
114
  Template.new(name, file.read, file.mtime.utc)
@@ -64,7 +64,7 @@ module BooticCli
64
64
  end
65
65
 
66
66
  if root.has?(:all_shops)
67
- root.all_shops(subdomains: subdomain).first
67
+ root.all_shops(subdomains: subdomain).find { |s| s.subdomain == subdomain }
68
68
  else
69
69
  root.shops.find { |s| s.subdomain == subdomain }
70
70
  end
@@ -0,0 +1,33 @@
1
+ require 'net/http'
2
+
3
+ module BooticCli
4
+ module Utils
5
+ REQUEST_OPTS = {
6
+ open_timeout: 5,
7
+ read_timeout: 5
8
+ }.freeze
9
+
10
+ MAX_FETCH_ATTEMPTS = 3
11
+
12
+ def self.fetch_http_file(href, attempt: 1, skip_verify: false)
13
+ uri = URI.parse(href)
14
+ opts = REQUEST_OPTS.merge({
15
+ verify_mode: skip_verify ? OpenSSL::SSL::VERIFY_NONE : OpenSSL::SSL::VERIFY_PEER,
16
+ use_ssl: uri.port == 443
17
+ })
18
+
19
+ Net::HTTP.start(uri.host, uri.port, opts) do |http|
20
+ resp = http.get(uri.path)
21
+ raise "Invalid response: #{resp.code}" unless resp.code.to_i == 200
22
+ StringIO.new(resp.body)
23
+ end
24
+ rescue Net::OpenTimeout, Net::ReadTimeout => e
25
+ raise if attempt > MAX_FETCH_ATTEMPTS # max attempts
26
+ # puts "#{e.class} for #{File.basename(uri.path)}! Retrying request..."
27
+ fetch_http_file(href, attempt: attempt + 1)
28
+ rescue OpenSSL::SSL::SSLError => e
29
+ # retry but skipping verification
30
+ fetch_http_file(href, attempt: attempt + 1, skip_verify: true)
31
+ end
32
+ end
33
+ end
@@ -1,3 +1,3 @@
1
1
  module BooticCli
2
- VERSION = '0.9.5'
2
+ VERSION = '1.0.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootic_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.5
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ismael Celis
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-06-03 00:00:00.000000000 Z
12
+ date: 2024-07-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
@@ -160,6 +160,7 @@ files:
160
160
  - lib/bootic_cli/themes/theme_selector.rb
161
161
  - lib/bootic_cli/themes/updated_theme.rb
162
162
  - lib/bootic_cli/themes/workflows.rb
163
+ - lib/bootic_cli/utils.rb
163
164
  - lib/bootic_cli/version.rb
164
165
  - lib/bootic_cli/worker_pool.rb
165
166
  - libexec/inspector
@@ -186,7 +187,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
186
187
  - !ruby/object:Gem::Version
187
188
  version: '0'
188
189
  requirements: []
189
- rubygems_version: 3.4.6
190
+ rubyforge_project:
191
+ rubygems_version: 2.7.3
190
192
  signing_key:
191
193
  specification_version: 4
192
194
  summary: Bootic command-line client.