voog-kit 0.2.2 → 0.2.3

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
  SHA1:
3
- metadata.gz: 6ca9d43de96a85cceacfc9ca445810fff9a51f9c
4
- data.tar.gz: 3c9c89d32194b02a8a6cb0eea78c409a102d3a2f
3
+ metadata.gz: 36f989cd5ef93ad83de52a35f6529bc233f186e1
4
+ data.tar.gz: 98924d5947e7ceca25172f763aed37e5de5cebce
5
5
  SHA512:
6
- metadata.gz: fa8c0fc65383f9d0a5bd47cd673ee097f3396de404c2e317322633a159ee4b05172cde28a91e055c3e1112baa8e742667e9b705b0e0ab9208cc23fa46a22f952
7
- data.tar.gz: bf8576c04f7c357633196fa44dd8431874140a01cfaa7729d5f9f7a014fc7b02db63062edc1d4fe816af4d3bfe63d1255f620fe6d172315c45e6adca30f03352
6
+ metadata.gz: 2a36764dfa04dc9d3df2ab23483a0928fb0c93891c15b3083f2a2f357f4684e5f23086423c43a849417574d0c7bb37f361025c548f3881f86c96948603faac8b
7
+ data.tar.gz: b1dadd5e5a7ea43b7a43f2c53245ad33488b44c1766724fa04ca07eaf74ea1b0ec4be369fbaa9277a502775fe9b3e1be262efd62830858b9db1a4b2c62b34740
data/bin/kit CHANGED
@@ -24,7 +24,8 @@ silent_args = [:silent, { default_value: false, negatable: false, desc: 'Hide al
24
24
  hostname_args = [:h, :host, :hostname, { desc: 'Provide a hostname', arg_name: :HOST }]
25
25
  api_token_args = [:t, :token, :api_token, { desc: 'Provide an API token', arg_name: :API_TOKEN }]
26
26
  site_args = [:s, :site, { arg_name: :SITE, default_value: nil, desc: 'Specify which site block to use when parsing the .voog file' }]
27
- overwrite_args = [:overwrite, { negatable: true, default_value: false, desc: 'Enable overwriting asset files that cannot be normally updated. '}]
27
+ overwrite_args = [:overwrite, { negatable: true, default_value: false, desc: 'Enable overwriting asset files that cannot be normally updated.' }]
28
+ cleanup_args = [:cleanup, { negatable: false, default_value: false, desc: 'Delete remote layout files that are not in local manifest.' }]
28
29
 
29
30
  flag *hostname_args
30
31
  flag *api_token_args
@@ -122,6 +123,7 @@ command :push do |c|
122
123
  c.switch *verbose_args
123
124
  c.switch *silent_args
124
125
  c.switch *overwrite_args
126
+ c.switch *cleanup_args
125
127
  c.flag *hostname_args
126
128
  c.flag *api_token_args
127
129
  c.flag *site_args
@@ -130,6 +132,21 @@ command :push do |c|
130
132
  end
131
133
  end
132
134
 
135
+ desc 'Removes a specific file and syncs it with the remote site'
136
+ long_desc 'This command removes a local file, removes it from the manifest and sends a deleted
137
+ request to remove it from the remote site as well.'
138
+ command :remove do |c|
139
+ c.switch *debug_args
140
+ c.switch *verbose_args
141
+ c.switch *silent_args
142
+ c.flag *hostname_args
143
+ c.flag *api_token_args
144
+ c.flag *site_args
145
+ c.action do |global_options, options, args|
146
+ @filemanager.remove_files args
147
+ end
148
+ end
149
+
133
150
  desc "Generates a manifest.json file from the site's layout and asset files."
134
151
  long_desc "This looks through the current directory's subdirectories and files
135
152
  within them to compile a 'manifest.json' file. This is used for keeping
@@ -187,6 +204,7 @@ pre do |global, command, options, args|
187
204
  silent = global.fetch(:silent, false) || options.fetch(:silent, false)
188
205
  verbose = global.fetch(:verbose, false) || options.fetch(:verbose, false)
189
206
  overwrite = global.fetch(:overwrite, false) || options.fetch(:overwrite, false)
207
+ cleanup = global.fetch(:cleanup, false) || options.fetch(:cleanup, false)
190
208
 
191
209
  @notifier = Voog::Dtk::Notifier.new($stderr, silent)
192
210
 
@@ -223,7 +241,8 @@ pre do |global, command, options, args|
223
241
  @filemanager = Voog::Dtk::FileManager.new(client, {
224
242
  silent: silent,
225
243
  verbose: verbose,
226
- overwrite: overwrite
244
+ overwrite: overwrite,
245
+ cleanup: cleanup
227
246
  })
228
247
  end
229
248
 
data/lib/voog/dtk.rb CHANGED
@@ -9,11 +9,11 @@ module Voog
9
9
 
10
10
  class << self
11
11
  def config_exists?(filename=CONFIG_FILENAME)
12
- filename && !filename.empty? && File.exists?(filename)
12
+ filename && !filename.empty? && File.exist?(filename)
13
13
  end
14
14
 
15
15
  def global_config_exists?(filename=CONFIG_FILENAME)
16
- filename && !filename.empty? && File.exists?([ENV['HOME'], filename].join('/'))
16
+ filename && !filename.empty? && File.exist?([ENV['HOME'], filename].join('/'))
17
17
  end
18
18
 
19
19
  def read_config(block = nil, file = CONFIG_FILENAME)
@@ -13,6 +13,7 @@ module Voog::Dtk
13
13
  @silent = opts.fetch(:silent, false)
14
14
  @verbose = opts.fetch(:verbose, false)
15
15
  @overwrite = opts.fetch(:overwrite, false)
16
+ @cleanup = opts.fetch(:cleanup, false)
16
17
  @notifier = Voog::Dtk::Notifier.new($stderr, @silent)
17
18
  end
18
19
 
@@ -85,16 +86,17 @@ module Voog::Dtk
85
86
  if %w(component layout).include? type
86
87
  @manifest['layouts'].delete_if do |layout|
87
88
  match = layout.fetch('file', nil) == file
88
- @notifier.info "Removed #{file} from manifest.json\n" if match
89
+ @notifier.info "Removed #{file} from manifest.json" if match
89
90
  match
90
91
  end
91
92
  elsif %w(image javascript asset stylesheet).include? type
92
93
  @manifest['assets'].delete_if do |asset|
93
94
  match = asset.fetch('file', nil) == file
94
- @notifier.info "Removed #{file} from manifest.json\n" if match
95
+ @notifier.info "Removed #{file} from manifest.json" if match
95
96
  match
96
97
  end
97
98
  end
99
+ @notifier.newline
98
100
  end
99
101
  write_manifest @manifest
100
102
  end
@@ -123,6 +125,10 @@ module Voog::Dtk
123
125
  @client.update_layout_asset(id, data: data)
124
126
  end
125
127
 
128
+ def delete_layout(id)
129
+ @client.delete_layout(id)
130
+ end
131
+
126
132
  def delete_layout_asset(id)
127
133
  @client.delete_layout_asset(id)
128
134
  end
@@ -488,6 +494,8 @@ module Voog::Dtk
488
494
  else
489
495
  @notifier.success 'OK!'
490
496
  end
497
+
498
+ return (missing_assets.count + missing_layouts.count == 0)
491
499
  end
492
500
 
493
501
  def fetch_boilerplate(dst='tmp')
@@ -714,6 +722,57 @@ module Voog::Dtk
714
722
  @client.create_layout_asset(data)
715
723
  end
716
724
 
725
+ def is_asset?(filename)
726
+ asset_folders = %w(assets images stylesheets javascripts)
727
+ return File.file?(filename) && asset_folders.include?(filename.split('/').first)
728
+ end
729
+
730
+ def is_layout?(filename)
731
+ layout_folders = %w(components layouts)
732
+ return File.file?(filename) && layout_folders.include?(filename.split('/').first)
733
+ end
734
+
735
+ def remove_files(names)
736
+ asset_ids = layout_asset_id_map
737
+ layout_ids = layout_id_map
738
+ names.each do |name|
739
+ if is_asset? name
740
+ remove_from_manifest(name)
741
+ remove_local_file(name)
742
+ id = asset_ids.fetch(name, nil)
743
+ if id && delete_layout_asset(id)
744
+ @notifier.info "Removed remote file #{name}." unless @silent
745
+ else
746
+ @notifier.error "Failed to remove remote file #{name}!" unless @silent
747
+ end
748
+ elsif is_layout? name
749
+ remove_from_manifest(name)
750
+ remove_local_file(name)
751
+ id = layout_ids.fetch(name, nil)
752
+ if id && delete_layout( id )
753
+ @notifier.info "Removed remote file #{name}." unless @silent
754
+ else
755
+ @notifier.error "Failed to remove remote file #{name}!" unless @silent
756
+ end
757
+ else
758
+ @notifier.error "Invalid filename: \"#{name}\""
759
+ end
760
+ @notifier.newline
761
+ end
762
+ end
763
+
764
+ def remove_local_file(file)
765
+ if File.exist?(file) && File.delete(file)
766
+ @notifier.info "Removed local file #{file}." unless @silent
767
+ @notifier.newline
768
+ return true
769
+ else
770
+ @notifier.error "Failed to remove file #{file}." unless @silent
771
+ @notifier.newline
772
+ return false
773
+ end
774
+ end
775
+
717
776
  def uploadable?(file)
718
777
  if file.is_a? String
719
778
  !(file =~ /^(component|layout|image|asset|javascript|stylesheet)s\/([^\s]+)/).nil?
@@ -1,5 +1,5 @@
1
1
  module Voog
2
2
  module Dtk
3
- VERSION = '0.2.2'
3
+ VERSION = '0.2.3'
4
4
  end
5
5
  end
@@ -7,7 +7,7 @@ describe Voog::Dtk::FileManager do
7
7
  before :all do
8
8
  Dir.mkdir 'TEST'
9
9
  Dir.chdir 'TEST'
10
- @filemanager = Voog::Dtk::FileManager.new(nil, {silent: false, verbose: true, overwrite: false})
10
+ @filemanager = Voog::Dtk::FileManager.new(nil, {silent: true, verbose: true, overwrite: false})
11
11
  @dir = Dir.new('.')
12
12
  end
13
13
 
@@ -179,7 +179,6 @@ describe Voog::Dtk::FileManager do
179
179
  expect(@filemanager.generate_manifest(layouts, layout_assets)).to be false
180
180
  end
181
181
  end
182
-
183
182
  end
184
183
 
185
184
  describe '#add_to_manifest' do
@@ -279,11 +278,79 @@ describe Voog::Dtk::FileManager do
279
278
  end
280
279
  it 'returns false if the file is not in the manifest' do
281
280
  filename = 'components/wrong_file.tpl'
282
- expect(@filemanager.in_manifest?(filename, @manifest)).to be_false
281
+ expect(@filemanager.in_manifest?(filename, @manifest)).to eq(false)
283
282
  end
284
283
  end
285
284
  end
286
285
 
286
+ describe '#is_asset?', focus: true do
287
+ before :all do
288
+ @filemanager.create_folders
289
+ @filemanager.create_asset get_layout_asset
290
+ end
291
+
292
+ context 'with a valid asset filename' do
293
+ it 'returns true' do
294
+ expect(@filemanager.is_asset? 'stylesheets/test.css').to eq(true)
295
+ end
296
+ end
297
+
298
+ context 'with an invalid asset filename' do
299
+ it' returns false' do
300
+ expect(@filemanager.is_asset? 'layouts/front_page.tpl').to eq(false)
301
+ end
302
+ end
303
+ end
304
+
305
+ describe '#is_layout?', focus: true do
306
+ before :all do
307
+ @filemanager.create_layout get_layout
308
+ end
309
+ context 'with a valid layout filename' do
310
+ it 'returns true' do
311
+ expect(@filemanager.is_layout? 'components/test.tpl').to eq(true)
312
+ end
313
+ end
314
+
315
+ context 'with an invalid layout filename' do
316
+ it' returns false' do
317
+ expect(@filemanager.is_layout? 'javascripts/main.min.js').to eq(false)
318
+ end
319
+ end
320
+ end
321
+
322
+ describe '#remove_local_file', focus: true do
323
+ before :each do
324
+ @filemanager.create_asset get_layout_asset
325
+ end
326
+
327
+ context 'with an existing file' do
328
+ it 'removes the file' do
329
+ old_asset_count = Dir['stylesheets/*'].count
330
+ @filemanager.remove_local_file 'stylesheets/test.css'
331
+ new_asset_count = Dir['stylesheets/*'].count
332
+ expect(old_asset_count - new_asset_count).to eq(1)
333
+ end
334
+ it 'returns true' do
335
+ expect(@filemanager.remove_local_file 'stylesheets/test.css').to eq(true)
336
+ end
337
+ end
338
+
339
+ context 'with an invalid filename' do
340
+ it 'doesn\'t remove anything' do
341
+ old_asset_count = Dir['stylesheets/*'].count
342
+ @filemanager.remove_local_file 'stylesheets/style.css'
343
+ new_asset_count = Dir['stylesheets/*'].count
344
+ expect(old_asset_count - new_asset_count).to eq(0)
345
+ end
346
+
347
+ it 'returns false' do
348
+ expect(@filemanager.remove_local_file 'stylesheets/style.css').to eq(false)
349
+ end
350
+
351
+ end
352
+ end
353
+
287
354
  describe '#remove_from_manifest' do
288
355
  before :all do
289
356
  @filemanager.generate_manifest(get_layouts, get_layout_assets)
@@ -329,19 +396,19 @@ describe Voog::Dtk::FileManager do
329
396
  Dir.delete('temp')
330
397
  end
331
398
  it 'returns false' do
332
- expect(@filemanager.check).to be_false
399
+ expect(@filemanager.check).to eq(false)
333
400
  end
334
401
  end
335
402
 
336
403
  context 'with empty manifest.json and no files' do
337
- it 'returns false' do
404
+ it 'returns true' do
338
405
  File.open('manifest.json', 'w+') do |file|
339
406
  file << {
340
407
  'layouts' => [],
341
408
  'assets' => []
342
409
  }.to_json
343
410
  end
344
- expect(@filemanager.check).to be_false
411
+ expect(@filemanager.check).to eq(true)
345
412
  end
346
413
  end
347
414
 
@@ -359,7 +426,7 @@ describe Voog::Dtk::FileManager do
359
426
  'assets' => []
360
427
  }.to_json
361
428
  end
362
- expect(@filemanager.check).to be_false
429
+ expect(@filemanager.check).to eq(false)
363
430
  end
364
431
  end
365
432
  end
@@ -386,7 +453,7 @@ describe Voog::Dtk::FileManager do
386
453
  end
387
454
 
388
455
  it 'returns false' do
389
- expect(@filemanager.generate_local_manifest).to be_false
456
+ expect(@filemanager.generate_local_manifest).to eq(false)
390
457
  end
391
458
 
392
459
  it 'doesn\'t generate a manifest.json file' do
@@ -409,7 +476,7 @@ describe Voog::Dtk::FileManager do
409
476
 
410
477
  it 'generates a manifest file' do
411
478
  @filemanager.generate_local_manifest
412
- expect(File.exists? 'manifest.json').to be_true
479
+ expect(File.exists? 'manifest.json').to eq(true)
413
480
  @manifest = @filemanager.read_manifest
414
481
  end
415
482
 
@@ -420,7 +487,7 @@ describe Voog::Dtk::FileManager do
420
487
  end
421
488
 
422
489
  it 'returns true' do
423
- expect(@filemanager.generate_local_manifest).to be_true
490
+ expect(@filemanager.generate_local_manifest).to eq(true)
424
491
  end
425
492
  end
426
493
 
@@ -447,7 +514,7 @@ describe Voog::Dtk::FileManager do
447
514
  @filemanager.generate_local_manifest
448
515
  @manifest = @filemanager.read_manifest
449
516
  layout = @manifest['layouts'].first
450
- expect(layout['component']).to be_false
517
+ expect(layout['component']).to eq(false)
451
518
  expect(layout['content_type']).to eq('page')
452
519
  expect(layout['file']).to eq('layouts/front_page.tpl')
453
520
  expect(layout['layout_name']).to eq('page_default')
@@ -455,7 +522,7 @@ describe Voog::Dtk::FileManager do
455
522
  end
456
523
 
457
524
  it 'returns true' do
458
- expect(@filemanager.generate_local_manifest).to be_true
525
+ expect(@filemanager.generate_local_manifest).to eq(true)
459
526
  end
460
527
  end
461
528
  end
@@ -487,11 +554,11 @@ describe Voog::Dtk::FileManager do
487
554
  it 'removes the \'tmp\' directory' do
488
555
  @filemanager.fetch_boilerplate
489
556
  @files = Dir['*']
490
- expect(@files.include? 'tmp').to be_false
557
+ expect(@files.include? 'tmp').to eq(false)
491
558
  end
492
559
 
493
560
  it 'returns true' do
494
- expect(@filemanager.fetch_boilerplate).to be_true
561
+ expect(@filemanager.fetch_boilerplate).to eq(true)
495
562
  end
496
563
  end
497
564
 
@@ -521,7 +588,7 @@ describe Voog::Dtk::FileManager do
521
588
  end
522
589
 
523
590
  it 'returns true' do
524
- expect(@return_value).to be_true
591
+ expect(@return_value).to eq(true)
525
592
  end
526
593
  end
527
594
  end
data/spec/spec_helper.rb CHANGED
@@ -3,7 +3,7 @@ require_relative '../lib/voog/dtk/filemanager.rb'
3
3
  require_relative '../lib/voog/dtk/notifier.rb'
4
4
 
5
5
  RSpec.configure do |c|
6
- # filter_run is short-form alias for filter_run_including
6
+ c.filter_run focus: true
7
7
  end
8
8
 
9
9
  FIXTURE_PATH = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures'))
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: voog-kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mikk Pristavka
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-09-03 00:00:00.000000000 Z
12
+ date: 2014-09-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler