maximus 0.1.2 → 0.1.3
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/README.md +99 -12
- data/lib/maximus/cli.rb +39 -20
- data/lib/maximus/config/maximus-example.yml +129 -0
- data/lib/maximus/config/maximus.yml +2 -0
- data/lib/maximus/config.rb +329 -0
- data/lib/maximus/git_control.rb +29 -47
- data/lib/maximus/helper.rb +10 -23
- data/lib/maximus/lint.rb +47 -26
- data/lib/maximus/lints/brakeman.rb +5 -2
- data/lib/maximus/lints/jshint.rb +7 -2
- data/lib/maximus/lints/railsbp.rb +5 -2
- data/lib/maximus/lints/rubocop.rb +5 -2
- data/lib/maximus/lints/scsslint.rb +4 -2
- data/lib/maximus/statistic.rb +23 -23
- data/lib/maximus/statistics/phantomas.rb +12 -7
- data/lib/maximus/statistics/stylestats.rb +20 -21
- data/lib/maximus/statistics/wraith.rb +34 -60
- data/lib/maximus/version.rb +1 -1
- data/lib/maximus.rb +1 -1
- data/maximus.gemspec +6 -6
- data/roadmap.md +2 -1
- metadata +25 -30
- data/lib/maximus/config/.jshintignore +0 -2
- data/lib/maximus/config/jshint.json +0 -9
- data/lib/maximus/config/phantomas.json +0 -4
- data/lib/maximus/config/phantomas_urls.yaml +0 -1
- data/lib/maximus/config/scsslint.yml +0 -58
- data/lib/maximus/config/stylestats.json +0 -30
- data/lib/maximus/config/wraith.yaml +0 -56
- data/lib/maximus/constants.rb +0 -5
data/lib/maximus/lint.rb
CHANGED
@@ -2,6 +2,7 @@ require 'json'
|
|
2
2
|
|
3
3
|
module Maximus
|
4
4
|
# @since 0.1.0
|
5
|
+
# @attr_accessor output [Hash] result of a lint parsed by Lint#refine
|
5
6
|
class Lint
|
6
7
|
attr_accessor :output
|
7
8
|
|
@@ -11,7 +12,7 @@ module Maximus
|
|
11
12
|
#
|
12
13
|
# All defined lints require a "result" method
|
13
14
|
# @example the result method in the child class
|
14
|
-
# def result
|
15
|
+
# def result
|
15
16
|
# @task = __method__.to_s
|
16
17
|
# @path ||= 'path/or/**/glob/to/files''
|
17
18
|
# lint_data = JSON.parse(`some-command-line-linter`)
|
@@ -19,21 +20,24 @@ module Maximus
|
|
19
20
|
# refine data_from_output
|
20
21
|
# end
|
21
22
|
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
# @
|
25
|
-
# @option
|
26
|
-
#
|
27
|
-
# @
|
23
|
+
# Inherits settings from {Config#initialize}
|
24
|
+
#
|
25
|
+
# @param opts [Hash] ({}) options passed directly to the lint
|
26
|
+
# @option git_files [Hash] filename: file location
|
27
|
+
# @see GitControl#lints_and_stats
|
28
|
+
# @option file_paths [Array, String] lint only specific files or directories
|
29
|
+
# Accepts globs too
|
30
|
+
# which is used to define paths from the URL
|
31
|
+
# @option opts [Config object] :config custom Maximus::Config object
|
32
|
+
# @return [void] this method is used to set up instance variables
|
28
33
|
def initialize(opts = {})
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
@path = opts[:
|
36
|
-
@opts = opts
|
34
|
+
|
35
|
+
# Only run the config once
|
36
|
+
@@config ||= opts[:config] || Maximus::Config.new(opts)
|
37
|
+
@settings ||= @@config.settings
|
38
|
+
|
39
|
+
@git_files = opts[:git_files]
|
40
|
+
@path = opts[:file_paths] || @settings[:file_paths]
|
37
41
|
@output = {}
|
38
42
|
end
|
39
43
|
|
@@ -44,11 +48,15 @@ module Maximus
|
|
44
48
|
def refine(data)
|
45
49
|
# Prevent abortive empty JSON.parse error
|
46
50
|
data = '{}' if data.blank?
|
51
|
+
return puts "Error from #{@task}: #{data}" if data.is_a?(String) && data.include?('No such')
|
52
|
+
|
47
53
|
data = data.is_a?(String) ? JSON.parse(data) : data
|
48
|
-
|
49
|
-
|
54
|
+
|
55
|
+
@output[:relevant_lints] = relevant_lints( data, @git_files ) unless @git_files.blank?
|
56
|
+
unless @settings[:commit].blank?
|
50
57
|
data = @output[:relevant_lints]
|
51
58
|
end
|
59
|
+
|
52
60
|
lint_warnings = []
|
53
61
|
lint_errors = []
|
54
62
|
lint_conventions = []
|
@@ -81,15 +89,16 @@ module Maximus
|
|
81
89
|
@output[:lint_conventions] = lint_conventions
|
82
90
|
@output[:lint_refactors] = lint_refactors
|
83
91
|
lint_count = (lint_errors.length + lint_warnings.length + lint_conventions.length + lint_refactors.length)
|
84
|
-
if @@is_dev
|
92
|
+
if @@config.is_dev?
|
85
93
|
puts lint_dev_format(data) unless data.blank?
|
86
94
|
puts lint_summarize
|
87
95
|
lint_ceiling lint_count
|
88
96
|
else
|
89
|
-
@@log.info lint_summarize
|
97
|
+
@@config.log.info lint_summarize
|
90
98
|
# Because this should be returned in the format it was received
|
91
99
|
@output[:raw_data] = data.to_json
|
92
100
|
end
|
101
|
+
@@config.destroy_temp(@task)
|
93
102
|
@output
|
94
103
|
end
|
95
104
|
|
@@ -102,12 +111,14 @@ module Maximus
|
|
102
111
|
# @param delimiter [String] comma or space separated
|
103
112
|
# @param remove [String] remove from all file names
|
104
113
|
# @return all_files [Array<string>] list of file names
|
105
|
-
def files_inspected(ext, delimiter = ',', remove = @
|
114
|
+
def files_inspected(ext, delimiter = ',', remove = @settings[:root_dir])
|
106
115
|
@path.is_a?(Array) ? @path.split(delimiter) : file_list(@path, ext, remove)
|
107
116
|
end
|
108
117
|
|
109
118
|
# Compare lint output with lines changed in commit
|
110
119
|
#
|
120
|
+
# @param lint [Hash] output lint data
|
121
|
+
# @param files [Hash<String: String>] filename: filepath
|
111
122
|
# @return [Array] lints that match the lines in commit
|
112
123
|
def relevant_lints(lint, files)
|
113
124
|
all_files = {}
|
@@ -118,13 +129,13 @@ module Maximus
|
|
118
129
|
lint_file = lint[file[:filename].to_s]
|
119
130
|
|
120
131
|
expanded = lines_added_to_range(file)
|
121
|
-
revert_name = file[:filename].gsub("#{@
|
132
|
+
revert_name = file[:filename].gsub("#{@settings[:root_dir]}/", '')
|
122
133
|
unless lint_file.blank?
|
123
134
|
all_files[revert_name] = []
|
124
135
|
|
125
136
|
# @todo originally I tried .map and delete_if, but this works,
|
126
|
-
#
|
127
|
-
#
|
137
|
+
# and the other method didn't cover all bases.
|
138
|
+
# Gotta be a better way to write this though
|
128
139
|
lint_file.each do |l|
|
129
140
|
if expanded.include?(l['line'].to_i)
|
130
141
|
all_files[revert_name] << l
|
@@ -135,13 +146,23 @@ module Maximus
|
|
135
146
|
end
|
136
147
|
else
|
137
148
|
# Optionally store the filename with a blank array
|
138
|
-
# all_files[file[:filename].to_s.gsub("#{@
|
149
|
+
# @example all_files[file[:filename].to_s.gsub("#{@settings[:root_dir]}/", '')] = []
|
139
150
|
end
|
140
151
|
end
|
141
152
|
@output[:files_linted] = all_files.keys
|
142
153
|
all_files
|
143
154
|
end
|
144
155
|
|
156
|
+
# Look for a config defined from Config#initialize
|
157
|
+
#
|
158
|
+
# @since 0.1.2
|
159
|
+
# @param search_for [String]
|
160
|
+
# @return [String, Boolean] path to temp file
|
161
|
+
def temp_config(search_for)
|
162
|
+
return false if @settings.nil?
|
163
|
+
@settings[search_for.to_sym].blank? ? false : @settings[search_for.to_sym]
|
164
|
+
end
|
165
|
+
|
145
166
|
|
146
167
|
private
|
147
168
|
|
@@ -149,7 +170,7 @@ module Maximus
|
|
149
170
|
#
|
150
171
|
# @return [String] console message to display
|
151
172
|
def lint_summarize
|
152
|
-
puts "\n" if @@is_dev
|
173
|
+
puts "\n" if @@config.is_dev?
|
153
174
|
|
154
175
|
puts "#{'Warning'.color(:red)}: #{@output[:lint_errors].length} errors found in #{@task.to_s}" if @output[:lint_errors].length > 0
|
155
176
|
|
@@ -193,7 +214,7 @@ module Maximus
|
|
193
214
|
pretty_output = ''
|
194
215
|
errors.each do |filename, error_list|
|
195
216
|
pretty_output += "\n"
|
196
|
-
filename = filename.gsub("#{@
|
217
|
+
filename = filename.gsub("#{@settings[:root_dir]}/", '')
|
197
218
|
pretty_output += filename.color(:cyan).underline
|
198
219
|
pretty_output += "\n"
|
199
220
|
error_list.each do |message|
|
@@ -7,10 +7,13 @@ module Maximus
|
|
7
7
|
# @see Lint#initialize
|
8
8
|
def result
|
9
9
|
|
10
|
-
return unless
|
10
|
+
return unless is_rails?
|
11
11
|
|
12
12
|
@task = 'brakeman'
|
13
|
-
|
13
|
+
|
14
|
+
return unless temp_config(@task)
|
15
|
+
|
16
|
+
@path = @settings[:root_dir] if @path.blank?
|
14
17
|
|
15
18
|
return unless path_exists(@path)
|
16
19
|
|
data/lib/maximus/lints/jshint.rb
CHANGED
@@ -7,13 +7,18 @@ module Maximus
|
|
7
7
|
# @see Lint#initialize
|
8
8
|
def result
|
9
9
|
@task = 'jshint'
|
10
|
-
|
10
|
+
|
11
|
+
return unless temp_config(@task)
|
12
|
+
|
13
|
+
@path = is_rails? ? "#{@settings[:root_dir]}/app/assets" : "#{@settings[:root_dir]}source/assets" if @path.blank?
|
11
14
|
|
12
15
|
return unless path_exists(@path)
|
13
16
|
|
14
17
|
node_module_exists(@task)
|
15
18
|
|
16
|
-
|
19
|
+
jshint_cli = "jshint #{@path} --config=#{temp_config(@task)} --reporter=#{reporter_path('jshint.js')}"
|
20
|
+
jshint_cli += " --exclude-path=#{temp_config(@settings[:jshintignore])}" if @settings.has_key?(:jshintignore)
|
21
|
+
jshint = `#{jshint_cli}`
|
17
22
|
|
18
23
|
@output[:files_inspected] ||= files_inspected('js')
|
19
24
|
refine jshint
|
@@ -7,10 +7,13 @@ module Maximus
|
|
7
7
|
# @see Lint#initialize
|
8
8
|
def result
|
9
9
|
|
10
|
-
return unless
|
10
|
+
return unless is_rails?
|
11
11
|
|
12
12
|
@task = 'railsbp'
|
13
|
-
|
13
|
+
|
14
|
+
return unless temp_config(@task)
|
15
|
+
|
16
|
+
@path = @settings[:root_dir] if @path.blank?
|
14
17
|
|
15
18
|
return unless path_exists(@path)
|
16
19
|
|
@@ -7,11 +7,14 @@ module Maximus
|
|
7
7
|
# @see Lint#initialize
|
8
8
|
def result
|
9
9
|
@task = 'rubocop'
|
10
|
-
|
10
|
+
|
11
|
+
return unless temp_config(@task)
|
12
|
+
|
13
|
+
@path = is_rails? ? "#{@settings[:root_dir]}/app" : "#{@settings[:root_dir]}/*.rb" if @path.blank?
|
11
14
|
|
12
15
|
return unless path_exists(@path)
|
13
16
|
|
14
|
-
rubo = `rubocop #{@path} --require #{reporter_path('rubocop')} --config #{
|
17
|
+
rubo = `rubocop #{@path} --require #{reporter_path('rubocop')} --config #{temp_config(@task)} --format RuboCop::Formatter::MaximusRuboFormatter #{'-R' if is_rails?}`
|
15
18
|
|
16
19
|
@output[:files_inspected] ||= files_inspected('rb', ' ')
|
17
20
|
refine rubo
|
@@ -7,11 +7,13 @@ module Maximus
|
|
7
7
|
# @see Lint#initialize
|
8
8
|
def result
|
9
9
|
@task = 'scsslint'
|
10
|
-
|
10
|
+
|
11
|
+
return unless temp_config(@task)
|
12
|
+
@path = is_rails? ? "#{@settings[:root_dir]}/app/assets/stylesheets" : "#{@settings[:root_dir]}/source/assets/stylesheets" if @path.blank?
|
11
13
|
|
12
14
|
return unless path_exists(@path)
|
13
15
|
|
14
|
-
scss = `scss-lint #{@path} -c #{
|
16
|
+
scss = `scss-lint #{@path} -c #{temp_config(@task)} --format=JSON`
|
15
17
|
@output[:files_inspected] ||= files_inspected('scss')
|
16
18
|
refine scss
|
17
19
|
end
|
data/lib/maximus/statistic.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
module Maximus
|
2
2
|
# @since 0.1.0
|
3
|
+
# @attr_accessor output [Hash] result of a lint parsed by Lint#refine
|
3
4
|
class Statistic
|
4
5
|
attr_accessor :output
|
5
6
|
|
@@ -9,36 +10,31 @@ module Maximus
|
|
9
10
|
#
|
10
11
|
# All defined statistics require a "result" method
|
11
12
|
# @example the result method in the child class
|
12
|
-
# def result
|
13
|
+
# def result
|
13
14
|
# @path ||= 'path/or/**/glob/to/files''
|
14
15
|
# stat_data = JSON.parse(`some-command-line-stat-runner`)
|
15
16
|
# @output
|
16
17
|
# end
|
17
18
|
#
|
18
|
-
#
|
19
|
-
# @
|
20
|
-
# @option
|
21
|
-
#
|
22
|
-
#
|
23
|
-
# @option opts [
|
24
|
-
#
|
25
|
-
# @return output [Hash] combined and refined data from statistic
|
19
|
+
# Inherits settings from {Config#initialize}
|
20
|
+
# @param opts [Hash] ({}) options passed directly to statistic
|
21
|
+
# @option file_paths [Array, String] stat only specific files or directories
|
22
|
+
# Accepts globs too
|
23
|
+
# which is used to define paths from the URL (see Statistics#initialize)
|
24
|
+
# @option opts [Config object] :config custom Maximus::Config object
|
25
|
+
# @return [void] this method is used to set up instance variables
|
26
26
|
def initialize(opts = {})
|
27
|
-
opts[:is_dev] ||= false
|
28
|
-
opts[:root_dir] ||= root_dir
|
29
|
-
opts[:port] ||= ''
|
30
|
-
opts[:base_url] ||= 'http://localhost:3000'
|
31
27
|
|
32
|
-
@@
|
33
|
-
|
34
|
-
|
35
|
-
@path = opts[:
|
36
|
-
@opts = opts
|
28
|
+
@@config ||= opts[:config] || Maximus::Config.new(opts)
|
29
|
+
@settings ||= @@config.settings
|
30
|
+
|
31
|
+
@path = opts[:file_paths] || @settings[:file_paths]
|
37
32
|
|
38
33
|
@output = {}
|
34
|
+
|
39
35
|
# This is different from lints
|
40
|
-
#
|
41
|
-
#
|
36
|
+
# A new stat is run per file or URL, so they should be stored in a child
|
37
|
+
# A lint just has one execution, so it's data can be stored directly in @output
|
42
38
|
@output[:statistics] = {}
|
43
39
|
end
|
44
40
|
|
@@ -46,12 +42,16 @@ module Maximus
|
|
46
42
|
protected
|
47
43
|
|
48
44
|
# Organize stat output on the @output variable
|
45
|
+
# Adds @output[:statistics][:filepath] with all statistic data
|
46
|
+
# Ignores if is_dev or if stats_cli is blank
|
49
47
|
#
|
50
|
-
#
|
51
|
-
|
48
|
+
# @param stats_cli [String] JSON data from a lint result
|
49
|
+
# @param file_path [String] key value to organize stats output
|
50
|
+
# @return [Hash] organized stats data
|
51
|
+
def refine(stats_cli, file_path)
|
52
52
|
|
53
53
|
# Stop right there unless you mean business
|
54
|
-
return puts stats_cli if @@is_dev
|
54
|
+
return puts stats_cli if @@config.is_dev?
|
55
55
|
|
56
56
|
# JSON.parse will throw an abortive error if it's given an empty string
|
57
57
|
return false if stats_cli.blank?
|
@@ -7,15 +7,20 @@ module Maximus
|
|
7
7
|
# @see Statistic#initialize
|
8
8
|
def result
|
9
9
|
|
10
|
+
return if @settings[:phantomas].blank?
|
11
|
+
|
10
12
|
node_module_exists('phantomjs', 'brew install')
|
11
13
|
node_module_exists('phantomas')
|
12
14
|
|
13
|
-
@path
|
15
|
+
@path = @settings[:paths] if @path.blank?
|
16
|
+
@domain = @@config.domain
|
17
|
+
|
14
18
|
# Phantomas doesn't actually skip the skip-modules defined in the config BUT here's to hoping for future support
|
15
|
-
phantomas_cli = "phantomas --config=#{
|
16
|
-
phantomas_cli += @@is_dev ? '--colors' : '--reporter=json:no-skip'
|
17
|
-
phantomas_cli += " --proxy=#{@
|
19
|
+
phantomas_cli = "phantomas --config=#{@settings[:phantomas]} "
|
20
|
+
phantomas_cli += @@config.is_dev? ? '--colors' : '--reporter=json:no-skip'
|
21
|
+
phantomas_cli += " --proxy=#{@domain}"
|
18
22
|
@path.is_a?(Hash) ? @path.each { |label, url| phantomas_by_url(url, phantomas_cli) } : phantomas_by_url(@path, phantomas_cli)
|
23
|
+
@@config.destroy_temp('phantomas')
|
19
24
|
@output
|
20
25
|
end
|
21
26
|
|
@@ -26,9 +31,9 @@ module Maximus
|
|
26
31
|
# Adds @output[:statistics][:filepath] with all statistic data
|
27
32
|
# @return [void] goes to refine statistics
|
28
33
|
def phantomas_by_url(url, phantomas_cli)
|
29
|
-
puts "Phantomas on #{@
|
30
|
-
phantomas = `#{phantomas_cli} #{@
|
31
|
-
|
34
|
+
puts "Phantomas on #{@domain + url}".color(:green)
|
35
|
+
phantomas = `#{phantomas_cli} #{@domain + url}`
|
36
|
+
refine(phantomas, url)
|
32
37
|
end
|
33
38
|
|
34
39
|
end
|
@@ -3,39 +3,38 @@ module Maximus
|
|
3
3
|
class Stylestats < Maximus::Statistic
|
4
4
|
|
5
5
|
# @path array preferrably absolute paths, but relative should work
|
6
|
-
#
|
7
|
-
#
|
8
|
-
# @example stylestat one file
|
9
|
-
# Maximus::Stylestats.new({path: ['/absolute/to/public/assets/application.css']}).result
|
6
|
+
# If stylestatting one file, pass that as an array
|
10
7
|
#
|
11
8
|
# @see Statistic#initialize
|
12
9
|
def result
|
13
10
|
|
11
|
+
return if @settings[:stylestats].blank?
|
12
|
+
|
14
13
|
node_module_exists('stylestats')
|
15
|
-
@path
|
14
|
+
@path = is_rails? ? "#{@settings[:root_dir]}/public/assets/**/*.css" : "#{@settings[:root_dir]}/**/*.css" if @path.blank?
|
16
15
|
|
17
16
|
css_files = @path.is_a?(Array) ? @path : find_css_files
|
18
17
|
|
19
18
|
css_files.each do |file|
|
20
19
|
|
21
20
|
# For Rails, we only want the name of the compiled asset, because we know it'll live in public/assets.
|
22
|
-
#
|
23
|
-
pretty_name =
|
21
|
+
# If this isn't Rails, sure, give me the full path because the directory structure is likely unique
|
22
|
+
pretty_name = is_rails? ? file.split('/').pop.gsub(/(-{1}[a-z0-9]{32}*\.{1}){1}/, '.') : file
|
24
23
|
|
25
24
|
puts "#{'stylestats'.color(:green)}: #{pretty_name}\n\n"
|
26
25
|
|
27
26
|
# include JSON formatter unless we're in dev
|
28
|
-
stylestats = `stylestats #{file} --config=#{
|
29
|
-
|
30
|
-
|
27
|
+
stylestats = `stylestats #{file} --config=#{@settings[:stylestats]} #{'--type=json' unless @@config.is_dev?}`
|
28
|
+
puts stylestats
|
29
|
+
refine(stylestats, pretty_name)
|
31
30
|
|
32
31
|
File.delete(file)
|
33
32
|
end
|
34
33
|
|
35
|
-
if
|
34
|
+
if is_rails?
|
36
35
|
# @todo I'd rather Rake::Task but it's not working in different directories
|
37
|
-
Dir.chdir(@
|
38
|
-
if @@is_dev
|
36
|
+
Dir.chdir(@settings[:root_dir]) do
|
37
|
+
if @@config.is_dev?
|
39
38
|
# @todo review that this may not be best practice, but it's really noisy in the console
|
40
39
|
quietly { `rake assets:clobber` }
|
41
40
|
else
|
@@ -43,7 +42,7 @@ module Maximus
|
|
43
42
|
end
|
44
43
|
end
|
45
44
|
end
|
46
|
-
|
45
|
+
@@config.destroy_temp('stylestats')
|
47
46
|
@output
|
48
47
|
|
49
48
|
end
|
@@ -52,23 +51,23 @@ module Maximus
|
|
52
51
|
private
|
53
52
|
|
54
53
|
# Find all CSS files or compile.
|
54
|
+
#
|
55
55
|
# Uses sprockets if Rails; Sass engine otherwise.
|
56
56
|
# Compass is supported
|
57
|
-
#
|
58
57
|
# @return [Array] CSS files
|
59
58
|
def find_css_files
|
60
59
|
searched_files = []
|
61
60
|
|
62
|
-
if
|
61
|
+
if is_rails?
|
63
62
|
# Only load tasks if we're not running a rake task
|
64
|
-
Rails.application.load_tasks unless @@is_dev
|
63
|
+
Rails.application.load_tasks unless @@config.is_dev?
|
65
64
|
|
66
65
|
puts "\n"
|
67
66
|
puts 'Compiling assets for stylestats...'.color(:blue)
|
68
67
|
|
69
68
|
# @todo I'd rather Rake::Task but it's not working in different directories
|
70
|
-
Dir.chdir(@
|
71
|
-
if @@is_dev
|
69
|
+
Dir.chdir(@settings[:root_dir]) do
|
70
|
+
if @@config.is_dev?
|
72
71
|
# @todo review that this may not be best practice, but it's really noisy in the console
|
73
72
|
quietly { `rake assets:precompile` }
|
74
73
|
else
|
@@ -82,7 +81,7 @@ module Maximus
|
|
82
81
|
|
83
82
|
else
|
84
83
|
|
85
|
-
# Load Compass paths if
|
84
|
+
# Load Compass paths if the gem exists
|
86
85
|
if Gem::Specification::find_all_by_name('compass').any?
|
87
86
|
require 'compass'
|
88
87
|
Compass.sass_engine_options[:load_paths].each do |path|
|
@@ -91,7 +90,7 @@ module Maximus
|
|
91
90
|
end
|
92
91
|
|
93
92
|
# Shouldn't need to load paths anymore, but in case this doesn't work
|
94
|
-
#
|
93
|
+
# as it should, try the func below
|
95
94
|
# Dir.glob(@path).select { |d| File.directory? d}.each do |directory|
|
96
95
|
# Sass.load_paths << directory
|
97
96
|
# end
|
@@ -9,84 +9,58 @@ module Maximus
|
|
9
9
|
# @see Statistic#initialize
|
10
10
|
def result
|
11
11
|
|
12
|
+
return if @settings[:wraith].blank?
|
13
|
+
|
12
14
|
node_module_exists('phantomjs', 'brew install')
|
13
|
-
@root_config = "#{@opts[:root_dir]}/config/wraith"
|
14
|
-
wraith_exists = File.directory?(@root_config)
|
15
|
-
@wraith_config_file = "#{@opts[:root_dir]}/config/wraith.yaml"
|
16
15
|
|
17
16
|
puts 'Starting visual regression tests with wraith...'.color(:blue)
|
18
17
|
|
19
|
-
#
|
20
|
-
#
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
# @todo this doesn't work very well. It puts the new shots in the history folder,
|
34
|
-
# even with absolute paths. Could be a bug in wraith
|
35
|
-
YAML.load_file(@wraith_config_file)['paths'].each do |label, url|
|
36
|
-
edit_yaml(@wraith_config_file) do |file|
|
37
|
-
unless File.directory?("#{@opts[:root_dir]}/maximus_wraith_history/#{label}")
|
38
|
-
puts `wraith history #{@wraith_config_file}`
|
39
|
-
break
|
40
|
-
end
|
41
|
-
end
|
18
|
+
# Run history or latest depending on the existence of a history directory as defined
|
19
|
+
# in each wraith config file.
|
20
|
+
#
|
21
|
+
# @todo this doesn't work very well. It puts the new shots in the history folder,
|
22
|
+
# even with absolute paths. Could be a bug in wraith
|
23
|
+
#
|
24
|
+
# @yieldparam browser [String] headless browser name
|
25
|
+
# @yieldparam configpath [String] path to temp config file (see Config#wraith_setup)
|
26
|
+
@settings[:wraith].each do |browser, configpath|
|
27
|
+
wraith_yaml = YAML.load_file(configpath)
|
28
|
+
if File.directory?("#{@settings[:root_dir]}/#{wraith_yaml['history_dir']}")
|
29
|
+
puts `wraith latest #{configpath}`
|
30
|
+
else
|
31
|
+
puts `wraith history #{configpath}`
|
42
32
|
end
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
33
|
+
File.write('said.yml', wraith_yaml.to_yaml)
|
34
|
+
File.delete(configpath)
|
35
|
+
wraith_parse browser
|
47
36
|
end
|
48
|
-
|
37
|
+
|
49
38
|
end
|
50
39
|
|
51
40
|
|
52
41
|
private
|
53
42
|
|
54
43
|
# Get a diff percentage of all changes by label and screensize
|
55
|
-
#
|
56
|
-
#
|
57
|
-
# @
|
58
|
-
|
59
|
-
|
60
|
-
Dir.glob("#{@
|
44
|
+
#
|
45
|
+
# @example {:statistics=>{:/=>{:percent_changed=>[{1024=>0.0}, {767=>0.0}, {1024=>0.0}, {767=>0.0}, {1024=>0.0}, {767=>0.0}, {1024=>0.0}, {767=>0.0}] } }}
|
46
|
+
# @param browser [String] headless browser used to generate the gallery
|
47
|
+
# @return [Hash] { path: { percent_changed: [{ size: percent_diff }] } }
|
48
|
+
def wraith_parse(browser)
|
49
|
+
Dir.glob("#{@settings[:root_dir]}/maximus_wraith_#{browser}/**/*.txt").select { |f| File.file? f }.each do |file|
|
61
50
|
file_object = File.open(file, 'rb')
|
62
51
|
orig_label = File.dirname(file).split('/').last
|
63
|
-
label = paths[orig_label]
|
64
|
-
@output[:statistics][
|
65
|
-
@output[:statistics][
|
66
|
-
@output[:statistics][
|
67
|
-
|
52
|
+
label = @settings[:paths][orig_label]
|
53
|
+
@output[:statistics][browser.to_sym] ||= {}
|
54
|
+
@output[:statistics][browser.to_sym][label.to_sym] ||= {}
|
55
|
+
browser_output = @output[:statistics][browser.to_sym][label.to_sym]
|
56
|
+
browser_output ||= {}
|
57
|
+
browser_output[:name] = orig_label
|
58
|
+
browser_output[:percent_changed] ||= []
|
59
|
+
browser_output[:percent_changed] << { File.basename(file).split('_')[0].to_i => file_object.read.to_f }
|
68
60
|
file_object.close
|
69
61
|
end
|
70
62
|
@output
|
71
63
|
end
|
72
64
|
|
73
|
-
# Update the root domain (docker ports and addresses may change)
|
74
|
-
# and set paths as defined in @path
|
75
|
-
#
|
76
|
-
# @return [void] but updates instance variables
|
77
|
-
def wraith_yaml_reset(wraith_config_file = @wraith_config_file)
|
78
|
-
edit_yaml(wraith_config_file) do |file|
|
79
|
-
unless @@is_dev
|
80
|
-
file['snap_file'] = "#{@root_config}/snap.js"
|
81
|
-
file['directory'] = "#{@opts[:root_dir]}/maximus_wraith"
|
82
|
-
file['history_dir'] = "#{@opts[:root_dir]}/maximus_wraith_history"
|
83
|
-
end
|
84
|
-
# .to_s is for consistency in the yaml, but could likely be removed without causing an error
|
85
|
-
fresh_domain = @opts[:port].blank? ? @opts[:base_url].to_s : "#{@opts[:base_url]}:#{@opts[:port]}"
|
86
|
-
file['domains']['main'] = fresh_domain
|
87
|
-
@path.each { |label, url| file['paths'][label] = url } if @path.is_a?(Hash)
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
65
|
end
|
92
66
|
end
|
data/lib/maximus/version.rb
CHANGED
data/lib/maximus.rb
CHANGED
data/maximus.gemspec
CHANGED
@@ -19,12 +19,12 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_runtime_dependency "git", ">= 1.2.8"
|
22
|
-
spec.add_runtime_dependency "scss-lint", "
|
23
|
-
spec.add_runtime_dependency "rainbow", "
|
24
|
-
spec.add_runtime_dependency "rubocop"
|
25
|
-
spec.add_runtime_dependency "rails_best_practices"
|
26
|
-
spec.add_runtime_dependency "brakeman"
|
27
|
-
spec.add_runtime_dependency "wraith"
|
22
|
+
spec.add_runtime_dependency "scss-lint", "~> 0.31.0"
|
23
|
+
spec.add_runtime_dependency "rainbow", "2.0.0"
|
24
|
+
spec.add_runtime_dependency "rubocop", "~> 0.23"
|
25
|
+
spec.add_runtime_dependency "rails_best_practices", "~> 1.15"
|
26
|
+
spec.add_runtime_dependency "brakeman", "~> 2.6"
|
27
|
+
spec.add_runtime_dependency "wraith", "~> 2.1.0"
|
28
28
|
spec.add_runtime_dependency "activesupport"
|
29
29
|
spec.add_runtime_dependency "thor"
|
30
30
|
spec.add_development_dependency "bundler", "~> 1.6"
|
data/roadmap.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Roadmap
|
2
2
|
|
3
|
-
* Check for a maximus.yml config file (for base_url, config_url, etc.) and load config globally when starting, or something similar - calling is_dev happens too often
|
4
3
|
* Check for custom lint or stat hooks in a lib/maximus folder
|
4
|
+
* Add custom lint path and script execution support to maximus.yml config file
|
5
5
|
* Use PhantomJS 2.0 with webfont support
|
6
6
|
* Resolve/review TODOs
|
7
7
|
* Tests and specs
|
@@ -13,3 +13,4 @@
|
|
13
13
|
* Add W3 validator (maybe)
|
14
14
|
* Regex path names on phantomas and wraith to defend against injection and bad characters
|
15
15
|
* include lines_added in this GitControll#diff output
|
16
|
+
* Test for < ruby 2.0 or require 2.0 < in gemspec
|