bootic_cli 0.5.0 → 0.5.1

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
- SHA256:
3
- metadata.gz: 55a78add4d79c5db970e4ad5df3b038fd6db6702c674cb60092c9d9f93bcf533
4
- data.tar.gz: 120a782606574c1dd7d94b25112e033cb348fd6fb2889201bbfe1bf28cf55fde
2
+ SHA1:
3
+ metadata.gz: 6d23940a740e8d8427e4eccf0f5bb872a19d9470
4
+ data.tar.gz: fb069df631666e1f2771f5d3fc4455a4c8b1dc0a
5
5
  SHA512:
6
- metadata.gz: 2a5a02b98f284912ce408de4cdcd141907e56f5b3e0b1741fbd60a42f3e32a0118e7635a82e9de57955f92ef1880ca7149d31c2c8d9b8b95c7f921382cedf5c1
7
- data.tar.gz: 94ff56bc77d419c27886aef885ebcbaa93eed49d63b7eca8aa8a325c834ac6c3f05c99ab9811c481ed2e5b55e06dfea3c6072d76436027d3cce4745a8e9c6c5f
6
+ metadata.gz: 5a65fbc81c21cefc4fdbbcd74002970541db887fccdcded111f0fa607246ea1e8293b4758c821c674b2e9db2b919cba85cf68d856eebf3bd2d5cf5a726df8846
7
+ data.tar.gz: fa6bed44f947a7197a490f8407682cf7f47a1a3a0dc695aa17c5cee69549a786479c5b49773c575ebb912cdc933c32eac3541006e40fd59623a6b7d768fc4484
@@ -48,6 +48,15 @@ module BooticCli
48
48
  end
49
49
 
50
50
  class APITheme
51
+
52
+ class EntityErrors < StandardError
53
+ attr_reader :errors
54
+ def initialize(errors)
55
+ @errors = errors
56
+ super "Entity has errors: #{errors.map(&:field)}"
57
+ end
58
+ end
59
+
51
60
  def initialize(theme)
52
61
  @theme = theme
53
62
  end
@@ -115,13 +124,6 @@ module BooticCli
115
124
  private
116
125
  attr_reader :theme
117
126
 
118
- class EntityErrors < StandardError
119
- attr_reader :errors
120
- def initialize(errors)
121
- @errors = errors
122
- super "Entity has errors: #{errors.map(&:field)}"
123
- end
124
- end
125
127
 
126
128
  def check_errors!(entity)
127
129
  if entity.has?(:errors)
@@ -95,12 +95,12 @@ module BooticCli
95
95
  # first, update existing templates in each side
96
96
  notice 'Updating local templates...'
97
97
  maybe_update(diff.updated_in_target.templates, 'remote', 'local') do |t|
98
- local_theme.add_template t.file_name, t.body
98
+ local_theme.add_template(t.file_name, t.body)
99
99
  end
100
100
 
101
101
  notice 'Updating remote templates...'
102
102
  maybe_update(diff.updated_in_source.templates, 'local', 'remote') do |t|
103
- remote_theme.add_template t.file_name, t.body
103
+ remote_theme.add_template(t.file_name, t.body)
104
104
  end
105
105
 
106
106
  # now, download missing files on local end
@@ -166,19 +166,19 @@ module BooticCli
166
166
  listener = watcher.to(dir) do |modified, added, removed|
167
167
  if modified.any?
168
168
  modified.each do |path|
169
- upsert_file remote_theme, path
169
+ upsert_file(remote_theme, path)
170
170
  end
171
171
  end
172
172
 
173
173
  if added.any?
174
174
  added.each do |path|
175
- upsert_file remote_theme, path
175
+ upsert_file(remote_theme, path)
176
176
  end
177
177
  end
178
178
 
179
179
  if removed.any?
180
180
  removed.each do |path|
181
- delete_file remote_theme, path
181
+ delete_file(remote_theme, path)
182
182
  end
183
183
  end
184
184
 
@@ -267,8 +267,10 @@ module BooticCli
267
267
 
268
268
  def copy_templates(from, to, opts = {})
269
269
  from.templates.each do |t|
270
- to.add_template t.file_name, t.body
271
- puts "Copied #{highlight(t.file_name)}"
270
+ handle_file_errors(:template, t) do
271
+ to.add_template(t.file_name, t.body)
272
+ puts "Copied #{highlight(t.file_name)}"
273
+ end
272
274
  end
273
275
  end
274
276
 
@@ -290,8 +292,11 @@ module BooticCli
290
292
 
291
293
  files.each do |a|
292
294
  pool.schedule do
293
- to.add_asset a.file_name, a.file
294
- puts "Copied asset #{highlight(a.file_name)} (#{a.file_size} bytes)"
295
+ handle_file_errors(:asset, a) do
296
+ to.add_asset(a.file_name, a.file)
297
+ size_str = a.file_size.to_i > 0 ? " (#{a.file_size} bytes)" : ''
298
+ puts "Copied asset #{highlight(a.file_name)}#{size_str}"
299
+ end
295
300
  end
296
301
  end
297
302
 
@@ -300,13 +305,15 @@ module BooticCli
300
305
 
301
306
  def upsert_file(theme, path)
302
307
  item, type = FSTheme.resolve_file(path)
303
- case type
304
- when :template
305
- theme.add_template item.file_name, item.body
306
- when :asset
307
- theme.add_asset item.file_name, item.file
308
+ handle_file_errors(type, item) do
309
+ case type
310
+ when :template
311
+ theme.add_template(item.file_name, item.body)
312
+ when :asset
313
+ theme.add_asset(item.file_name, item.file)
314
+ end
308
315
  end
309
- puts "Uploaded #{type}: #{item.file_name}"
316
+ puts "Uploaded #{type}: #{highlight(item.file_name)}"
310
317
  end
311
318
 
312
319
  def delete_file(theme, path)
@@ -314,11 +321,42 @@ module BooticCli
314
321
  file_name = File.basename(path)
315
322
  case type
316
323
  when :template
317
- theme.remove_template file_name
324
+ theme.remove_template(file_name)
318
325
  when :asset
319
- theme.remove_asset file_name
326
+ theme.remove_asset(file_name)
327
+ end
328
+ puts "Deleted remote #{type}: #{highlight(file_name)}"
329
+ end
330
+
331
+ def handle_file_errors(type, file, &block)
332
+ begin
333
+ yield
334
+ rescue APITheme::EntityErrors => e
335
+ fields = e.errors.map(&:field)
336
+
337
+ error_msg = if fields.include?("file_content_type") or fields.include?("content_type")
338
+ "is an unsupported file type for #{type}s."
339
+ elsif fields.include?("file_file_size") # big asset
340
+ size_str = file.file_size.to_i > 0 ? "(#{file.file_size} KB) " : ''
341
+ "#{size_str}is heavier than the maximum allowed for assets (1 MB)"
342
+ elsif fields.include?("body") # big template
343
+ str = file.file_name[/\.(html|liquid)$/] ? "Try splitting it into smaller chunks" : "Try saving it as an asset instead"
344
+ str += ", since templates can hold up to 64 KB of data."
345
+ else
346
+ "has invalid #{fields.join(', ')}"
347
+ end
348
+
349
+ prompt.say("#{file.file_name} #{error_msg}. Skipping...", :red)
350
+ # abort
351
+
352
+ rescue JSON::GeneratorError => e
353
+ prompt.say("#{file.file_name} looks like a binary file, not a template. Skipping...", :red)
354
+ # abort
355
+
356
+ rescue BooticClient::ServerError => e
357
+ prompt.say("Couldn't save #{file.file_name}. Please try again in a few minutes.", :red)
358
+ abort
320
359
  end
321
- puts "Deleted remote #{type}: #{file_name}"
322
360
  end
323
361
  end
324
362
  end
@@ -1,3 +1,3 @@
1
1
  module BooticCli
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootic_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ismael Celis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-25 00:00:00.000000000 Z
11
+ date: 2018-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -199,7 +199,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
199
199
  version: '0'
200
200
  requirements: []
201
201
  rubyforge_project:
202
- rubygems_version: 2.7.3
202
+ rubygems_version: 2.5.1
203
203
  signing_key:
204
204
  specification_version: 4
205
205
  summary: Bootic command-line client.