bootic_cli 0.7.1 → 0.8.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.
- checksums.yaml +4 -4
- data/lib/bootic_cli/commands/themes.rb +1 -1
- data/lib/bootic_cli/themes/api_theme.rb +25 -5
- data/lib/bootic_cli/themes/fs_theme.rb +19 -7
- data/lib/bootic_cli/themes/workflows.rb +25 -16
- data/lib/bootic_cli/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 78aa25989c89e07072dc2cdac0502d391ed1b403
|
4
|
+
data.tar.gz: 9421b7000cf397519a6c68ec2da26078d3522bee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dad570ef8547281df61d8f6630abb3aaa5c0ab422b68a2b7daa92efc3ac09e64a7b3850c88f8a5d5ba8090b10de2ee3a09f4a781b01e28632a2719587403d884
|
7
|
+
data.tar.gz: 568c143b7d446d88153f786e48a31253caaa471ba3a355b7af71ce6a33922ecb0b0066c8b685e4a724b20ed94e5155636bc6955f95812ad901465644d6706caa
|
@@ -10,7 +10,7 @@ module BooticCli
|
|
10
10
|
|
11
11
|
def ==(other)
|
12
12
|
# puts "Comparing with time #{self.updated_on} vs #{other.updated_on}"
|
13
|
-
self.updated_on == other.updated_on
|
13
|
+
self.updated_on.to_i == other.updated_on.to_i
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
@@ -116,17 +116,25 @@ module BooticCli
|
|
116
116
|
end
|
117
117
|
|
118
118
|
def add_template(file_name, body)
|
119
|
-
|
119
|
+
params = {
|
120
120
|
file_name: file_name,
|
121
121
|
body: body
|
122
|
-
|
122
|
+
}
|
123
|
+
|
124
|
+
if ts = get_updated_on(file_name)
|
125
|
+
params.merge!(last_updated_on: ts.to_i)
|
126
|
+
end
|
127
|
+
|
128
|
+
check_errors!(theme.create_template(params)).tap do |entity|
|
129
|
+
template_updated(file_name, entity)
|
130
|
+
end
|
123
131
|
end
|
124
132
|
|
125
133
|
def remove_template(file_name)
|
126
134
|
tpl = theme.templates.find { |t| t.file_name == file_name }
|
127
135
|
if tpl && tpl.can?(:delete_template)
|
128
136
|
res = tpl.delete_template
|
129
|
-
|
137
|
+
res.status.to_i < 300
|
130
138
|
else
|
131
139
|
puts "Cannot delete #{file_name}"
|
132
140
|
end
|
@@ -143,7 +151,7 @@ module BooticCli
|
|
143
151
|
asset = theme.assets.find { |t| t.file_name == file_name }
|
144
152
|
if asset and asset.can?(:delete_theme_asset)
|
145
153
|
res = asset.delete_theme_asset
|
146
|
-
|
154
|
+
res.status.to_i < 300
|
147
155
|
else
|
148
156
|
puts "Cannot delete asset: #{file_name}"
|
149
157
|
end
|
@@ -152,6 +160,18 @@ module BooticCli
|
|
152
160
|
private
|
153
161
|
attr_reader :theme
|
154
162
|
|
163
|
+
def get_updated_on(file_name)
|
164
|
+
if tpl = templates.find { |t| t.file_name == file_name }
|
165
|
+
tpl.updated_on
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
def template_updated(file_name, new_template)
|
170
|
+
if index = templates.index { |t| t.file_name == file_name }
|
171
|
+
templates[index] = ItemWithTime.new(new_template)
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
155
175
|
def check_errors!(entity)
|
156
176
|
if entity.has?(:errors)
|
157
177
|
raise EntityErrors.new(entity.errors)
|
@@ -8,7 +8,7 @@ module BooticCli
|
|
8
8
|
|
9
9
|
Template = Struct.new(:file_name, :body, :updated_on) do
|
10
10
|
def ==(other)
|
11
|
-
self.updated_on == other.updated_on
|
11
|
+
self.updated_on.to_i == other.updated_on.to_i
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
@@ -20,32 +20,39 @@ module BooticCli
|
|
20
20
|
def ==(other)
|
21
21
|
if other.digest.to_s == '' # api theme asset without a digest set
|
22
22
|
# puts "Other has no digest, so comparing dates: #{self.updated_on} vs #{other.updated_on}"
|
23
|
-
return self.updated_on == other.updated_on
|
23
|
+
return self.updated_on.to_i == other.updated_on.to_i
|
24
24
|
end
|
25
25
|
|
26
26
|
# file sizes may differ as they are served by CDN (that shrinks them)
|
27
|
+
# puts "Comparing digests:\n#{digest}\n#{other.digest}"
|
27
28
|
self.digest == other.digest # self.file_size == other.file_size
|
28
29
|
end
|
29
30
|
end
|
30
31
|
|
31
32
|
ASSETS_DIR = 'assets'.freeze
|
32
|
-
TEMPLATE_PATTERNS = ['
|
33
|
+
TEMPLATE_PATTERNS = ['sections/*.html', '*.html', '*.css', '*.js', 'theme.yml', 'settings.json'].freeze
|
33
34
|
ASSET_PATTERNS = [File.join(ASSETS_DIR, '*')].freeze
|
34
35
|
|
36
|
+
def self.resolve_path(path, dir)
|
37
|
+
File.expand_path(path).sub(File.expand_path(dir) + '/', '')
|
38
|
+
end
|
39
|
+
|
35
40
|
# helper to resolve the right type (Template or Asset) from a local path
|
36
41
|
# this is not part of the generic Theme interface
|
37
42
|
def self.resolve_type(path)
|
38
43
|
path =~ /assets\// ? :asset : :template
|
39
44
|
end
|
40
45
|
|
41
|
-
def self.resolve_file(path)
|
46
|
+
def self.resolve_file(path, workdir)
|
42
47
|
file = File.new(path)
|
43
48
|
type = resolve_type(path)
|
44
|
-
file_name = File.basename(path)
|
45
49
|
|
50
|
+
# initialize a new asset or template as it might be a new file
|
46
51
|
item = if path =~ /assets\//
|
52
|
+
file_name = File.basename(path)
|
47
53
|
ThemeAsset.new(file_name, file, file.mtime.utc)
|
48
54
|
else
|
55
|
+
file_name = resolve_path(path, workdir)
|
49
56
|
Template.new(file_name, file.read, file.mtime.utc)
|
50
57
|
end
|
51
58
|
|
@@ -86,7 +93,7 @@ module BooticCli
|
|
86
93
|
def templates
|
87
94
|
@templates ||= (
|
88
95
|
paths_for(TEMPLATE_PATTERNS).sort.map do |path|
|
89
|
-
name =
|
96
|
+
name = self.class.resolve_path(path, dir)
|
90
97
|
file = File.new(path)
|
91
98
|
Template.new(name, file.read, file.mtime.utc)
|
92
99
|
end
|
@@ -113,6 +120,9 @@ module BooticCli
|
|
113
120
|
body = body.gsub(/\r\n?/, "\n")
|
114
121
|
end
|
115
122
|
|
123
|
+
dir = File.dirname(path)
|
124
|
+
FileUtils.mkdir_p(dir) unless File.exist?(dir)
|
125
|
+
|
116
126
|
File.open(path, 'w') do |io|
|
117
127
|
io.write(body)
|
118
128
|
end
|
@@ -154,7 +164,9 @@ module BooticCli
|
|
154
164
|
end
|
155
165
|
|
156
166
|
def paths_for(patterns)
|
157
|
-
patterns.reduce([])
|
167
|
+
patterns.reduce([]) do |m, pattern|
|
168
|
+
m + Dir[File.join(dir, pattern)]
|
169
|
+
end
|
158
170
|
end
|
159
171
|
|
160
172
|
def setup
|
@@ -189,21 +189,22 @@ module BooticCli
|
|
189
189
|
|
190
190
|
def watch(dir, remote_theme, watcher: Listen)
|
191
191
|
listener = watcher.to(dir) do |modified, added, removed|
|
192
|
+
|
192
193
|
if modified.any?
|
193
194
|
modified.each do |path|
|
194
|
-
upsert_file(remote_theme, path)
|
195
|
+
upsert_file(remote_theme, path, dir)
|
195
196
|
end
|
196
197
|
end
|
197
198
|
|
198
199
|
if added.any?
|
199
200
|
added.each do |path|
|
200
|
-
upsert_file(remote_theme, path)
|
201
|
+
upsert_file(remote_theme, path, dir)
|
201
202
|
end
|
202
203
|
end
|
203
204
|
|
204
205
|
if removed.any?
|
205
206
|
removed.each do |path|
|
206
|
-
delete_file(remote_theme, path)
|
207
|
+
delete_file(remote_theme, path, dir)
|
207
208
|
end
|
208
209
|
end
|
209
210
|
|
@@ -321,10 +322,11 @@ module BooticCli
|
|
321
322
|
pool.start
|
322
323
|
end
|
323
324
|
|
324
|
-
def upsert_file(theme, path)
|
325
|
+
def upsert_file(theme, path, dir)
|
325
326
|
return if File.basename(path)[0] == '.' # filter out .lock and .state
|
326
|
-
|
327
|
-
|
327
|
+
|
328
|
+
item, type = FSTheme.resolve_file(path, dir)
|
329
|
+
success = handle_file_errors(type, item) do
|
328
330
|
case type
|
329
331
|
when :template
|
330
332
|
theme.add_template(item.file_name, item.body)
|
@@ -332,35 +334,42 @@ module BooticCli
|
|
332
334
|
theme.add_asset(item.file_name, item.file)
|
333
335
|
end
|
334
336
|
end
|
335
|
-
puts "Uploaded #{type}: #{highlight(item.file_name)}"
|
337
|
+
puts "Uploaded #{type}: #{highlight(item.file_name)}" if success
|
336
338
|
end
|
337
339
|
|
338
|
-
def delete_file(theme, path)
|
340
|
+
def delete_file(theme, path, dir)
|
339
341
|
type = FSTheme.resolve_type(path)
|
340
|
-
|
341
|
-
case type
|
342
|
+
success = case type
|
342
343
|
when :template
|
344
|
+
file_name = FSTheme.resolve_path(path, dir)
|
343
345
|
theme.remove_template(file_name)
|
344
346
|
when :asset
|
347
|
+
file_name = File.basename(path)
|
345
348
|
theme.remove_asset(file_name)
|
346
349
|
else
|
347
350
|
raise "Invalid type: #{type}"
|
348
351
|
end
|
349
|
-
puts "Deleted remote #{type}: #{highlight(file_name)}"
|
352
|
+
puts "Deleted remote #{type}: #{highlight(file_name)}" if success
|
350
353
|
end
|
351
354
|
|
352
355
|
def handle_file_errors(type, file, &block)
|
353
356
|
begin
|
354
357
|
yield
|
358
|
+
true
|
355
359
|
rescue APITheme::EntityErrors => e
|
356
360
|
fields = e.errors.map(&:field)
|
357
361
|
|
358
|
-
|
362
|
+
if fields.include?('$.updated_on') || fields.include?('updated_on')
|
363
|
+
prompt.say("#{file.file_name} timestamp #{e.errors.first.messages.first}", :red)
|
364
|
+
abort
|
365
|
+
end
|
366
|
+
|
367
|
+
error_msg = if fields.include?('file_content_type') or fields.include?('content_type')
|
359
368
|
"is an unsupported file type for #{type}s."
|
360
|
-
elsif fields.include?(
|
369
|
+
elsif fields.include?('file_file_size') # big asset
|
361
370
|
size_str = file.file_size.to_i > 0 ? "(#{file.file_size} KB) " : ''
|
362
371
|
"#{size_str}is heavier than the maximum allowed for assets (1 MB)"
|
363
|
-
elsif fields.include?(
|
372
|
+
elsif fields.include?('body') # big template
|
364
373
|
str = file.file_name[/\.(html|liquid)$/] ? "Try splitting it into smaller chunks" : "Try saving it as an asset instead"
|
365
374
|
str += ", since templates can hold up to 64 KB of data."
|
366
375
|
else
|
@@ -368,11 +377,11 @@ module BooticCli
|
|
368
377
|
end
|
369
378
|
|
370
379
|
prompt.say("#{file.file_name} #{error_msg}. Skipping...", :red)
|
371
|
-
# abort
|
380
|
+
false # abort
|
372
381
|
|
373
382
|
rescue JSON::GeneratorError => e
|
374
383
|
prompt.say("#{file.file_name} looks like a binary file, not a template. Skipping...", :red)
|
375
|
-
# abort
|
384
|
+
false # just continue, don't abort
|
376
385
|
|
377
386
|
rescue Net::OpenTimeout, Net::ReadTimeout => e
|
378
387
|
prompt.say("I'm having trouble connecting to the server. Please try again in a minute.", :red)
|
data/lib/bootic_cli/version.rb
CHANGED
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.
|
4
|
+
version: 0.8.2
|
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: 2020-
|
12
|
+
date: 2020-05-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thor
|