likadan 0.0.5 → 0.0.6

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: df8ec3d54bd3fc9f9fa37fac5efbd69c26b4b223
4
- data.tar.gz: aa754753cfc9fef241c026f7142a00598f540964
3
+ metadata.gz: 89d2d8d420a5b4ff0aa9ba929c814f70d1857c29
4
+ data.tar.gz: 834f1892de7b205fac29b293ef65c75c6e42c436
5
5
  SHA512:
6
- metadata.gz: dd7be6c3cd2b2d443949464a27f69b9b3347b5b47b33c32eb6cf7c5179412fb1ad7051d42f86d0335600faec8bd2b38ac61ecbcd2a5a2feb13c4e3d90949e880
7
- data.tar.gz: 0df70f6aa8be4e7b81ecf65c7e74e12923403cc983f58f8a3d6cc217c7890151bc44b27f77fad15290822dcdda7e35e32a4864a410a80cd8d4856bf2fcc0598f
6
+ metadata.gz: 7cfdaaace27c25794a2f5fd4a959e758c3ca4dd6985de80f54de4fd0e6913e2044d8c5005974aa0b16c69c25d9e1c50f7bc8a0754c71fc2488e69cb1d18dd9da
7
+ data.tar.gz: f9a2496c3456d48f313939cb1643215f9ac10f1a62799a077e00d0aba21fbb3eba2ca70c0d8fbee79ce78ea67cf9131f1ba3818a93d42825480676847873ed8c
data/bin/likadan CHANGED
@@ -1,6 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'likadan_utils'
4
+ require 'likadan_action'
5
+ require 'likadan_uploader'
6
+ require 'fileutils'
4
7
 
5
8
  action = ARGV[0] || 'run'
6
9
  case action
@@ -9,8 +12,6 @@ when 'run'
9
12
  begin
10
13
  require 'likadan_runner'
11
14
  ensure
12
- puts 'Press Enter to exit...'
13
- gets
14
15
  exit
15
16
  end
16
17
  end
@@ -20,11 +21,18 @@ when 'review'
20
21
  system 'open', LikadanUtils.construct_url('/review')
21
22
  require 'likadan_server'
22
23
 
24
+ when 'prune'
25
+ FileUtils.remove_entry_secure LikadanUtils.config['snapshots_folder']
26
+
23
27
  when 'approve', 'reject'
24
- require 'likadan_action'
25
28
  abort 'Missing example name' unless example_name = ARGV[1]
26
29
  abort 'Missing viewport width' unless width = ARGV[2]
27
30
  LikadanAction.new(example_name, width).send(action)
31
+
32
+ when 'upload_diffs'
33
+ LikadanUploader.new.upload_diffs.each do |url|
34
+ puts url
35
+ end
28
36
  else
29
37
  abort "Unknown action \"#{action}\""
30
38
  end
@@ -1,5 +1,5 @@
1
1
  require 'likadan_utils'
2
- require 'FileUtils'
2
+ require 'fileutils'
3
3
 
4
4
  class LikadanAction
5
5
  def initialize(example_name, width)
@@ -7,8 +7,9 @@ require 'diffux_core/snapshot_comparison_image/overlayed'
7
7
  require 'diffux_core/snapshot_comparison_image/after'
8
8
  require 'chunky_png'
9
9
  require 'likadan_utils'
10
+ require 'fileutils'
10
11
 
11
- driver = Selenium::WebDriver.for :firefox
12
+ driver = Selenium::WebDriver.for LikadanUtils.config['driver'].to_sym
12
13
  begin
13
14
  driver.navigate.to LikadanUtils.construct_url('/')
14
15
 
@@ -58,7 +59,7 @@ begin
58
59
  if img = comparison[:diff_image]
59
60
  diff_output = LikadanUtils.path_to(current['name'], width, 'diff.png')
60
61
  img.save(diff_output)
61
- puts "#{comparison[:diff_in_percent]}% (#{diff_output})"
62
+ puts "#{comparison[:diff_in_percent].round(1)}% (#{diff_output})"
62
63
  else
63
64
  File.delete(output_file)
64
65
  puts 'No diff.'
@@ -9,31 +9,13 @@ class LikadanServer < Sinatra::Base
9
9
  set :port, LikadanUtils.config['port']
10
10
  end
11
11
 
12
- def current_snapshots
13
- prepare_file = lambda do |file|
14
- width_dir = File.expand_path('..', file)
15
- name_dir = File.expand_path('..', width_dir)
16
- {
17
- name: File.basename(name_dir),
18
- width: File.basename(width_dir).sub('@', '').to_i,
19
- file: file,
20
- }
21
- end
22
- diff_files = Dir.glob("#{LikadanUtils.config['snapshots_folder']}/**/diff.png")
23
- baselines = Dir.glob("#{LikadanUtils.config['snapshots_folder']}/**/baseline.png")
24
- {
25
- diffs: diff_files.map(&prepare_file),
26
- baselines: baselines.map(&prepare_file)
27
- }
28
- end
29
-
30
12
  get '/' do
31
13
  @config = LikadanUtils.config
32
14
  erb :index
33
15
  end
34
16
 
35
17
  get '/review' do
36
- @snapshots = current_snapshots
18
+ @snapshots = LikadanUtils.current_snapshots
37
19
  erb :review
38
20
  end
39
21
 
@@ -0,0 +1,28 @@
1
+ require 'likadan_utils'
2
+ require 's3'
3
+ require 'securerandom'
4
+
5
+ class LikadanUploader
6
+ def initialize()
7
+ @s3_access_key_id = LikadanUtils.config['s3_access_key_id']
8
+ @s3_secret_access_key = LikadanUtils.config['s3_secret_access_key']
9
+ end
10
+
11
+ def upload_diffs
12
+ service = S3::Service.new(access_key_id: @s3_access_key_id,
13
+ secret_access_key: @s3_secret_access_key)
14
+ current_snapshots = LikadanUtils.current_snapshots
15
+ return [] if current_snapshots[:diffs].empty?
16
+
17
+ bucket = service.buckets.build(SecureRandom.hex)
18
+ bucket.save(location: :us)
19
+
20
+ current_snapshots[:diffs].map do |diff|
21
+ object = bucket.objects.build("#{diff[:name]}_#{diff[:width]}.png")
22
+ object.content = open(diff[:file])
23
+ object.content_type = 'image/png'
24
+ object.save
25
+ object.url
26
+ end
27
+ end
28
+ end
data/lib/likadan_utils.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'yaml'
2
+ require 'erb'
2
3
 
3
4
  class LikadanUtils
4
5
  def self.config
@@ -6,8 +7,10 @@ class LikadanUtils
6
7
  'snapshots_folder' => './snapshots',
7
8
  'source_files' => [],
8
9
  'stylesheets' => [],
9
- 'port' => 4567
10
- }.merge(YAML.load_file('.likadan.yaml'))
10
+ 'port' => 4567,
11
+ 'driver' => :firefox,
12
+ }.merge(YAML.load(ERB.new(File.read(
13
+ ENV['LIKADAN_CONFIG_FILE'] || '.likadan.yaml')).result))
11
14
  end
12
15
 
13
16
  def self.normalize_name(name)
@@ -33,4 +36,22 @@ class LikadanUtils
33
36
 
34
37
  return "http://localhost:#{config['port']}#{absolute_path}#{params_str}"
35
38
  end
39
+
40
+ def self.current_snapshots
41
+ prepare_file = lambda do |file|
42
+ width_dir = File.expand_path('..', file)
43
+ name_dir = File.expand_path('..', width_dir)
44
+ {
45
+ name: File.basename(name_dir),
46
+ width: File.basename(width_dir).sub('@', '').to_i,
47
+ file: file,
48
+ }
49
+ end
50
+ diff_files = Dir.glob("#{LikadanUtils.config['snapshots_folder']}/**/diff.png")
51
+ baselines = Dir.glob("#{LikadanUtils.config['snapshots_folder']}/**/baseline.png")
52
+ {
53
+ diffs: diff_files.map(&prepare_file),
54
+ baselines: baselines.map(&prepare_file)
55
+ }
56
+ end
36
57
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: likadan
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henric Trotzig
@@ -110,6 +110,26 @@ dependencies:
110
110
  - - ">="
111
111
  - !ruby/object:Gem::Version
112
112
  version: 1.4.5
113
+ - !ruby/object:Gem::Dependency
114
+ name: s3
115
+ requirement: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - "~>"
118
+ - !ruby/object:Gem::Version
119
+ version: '0.3'
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: 0.3.22
123
+ type: :runtime
124
+ prerelease: false
125
+ version_requirements: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - "~>"
128
+ - !ruby/object:Gem::Version
129
+ version: '0.3'
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: 0.3.22
113
133
  description: Likadan, a perceptual diff tool for JS components
114
134
  email: henric.trotzig@gmail.com
115
135
  executables:
@@ -121,6 +141,7 @@ files:
121
141
  - lib/likadan_action.rb
122
142
  - lib/likadan_runner.rb
123
143
  - lib/likadan_server.rb
144
+ - lib/likadan_uploader.rb
124
145
  - lib/likadan_utils.rb
125
146
  - lib/public/likadan-runner.js
126
147
  - lib/views/index.erb