sumodev 0.8.2 → 0.9.0
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/sumodev/commands/hooks.rb +326 -0
- data/lib/sumodev/version.rb +1 -1
- data/lib/sumodev.rb +2 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb24a085590f4899c56883f060568e4912f323b8
|
4
|
+
data.tar.gz: d3a39b2e7bba8537d7f91c12974d968a094bd042
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 813b45fb04576aa3eae3b1eaecabfcfc36229c5d5f005dfd88e11cc50a41ba31ec43848a0eb5de35bb18f0d7f8d69246f899e6f0a712214b25197d08d313e5e2
|
7
|
+
data.tar.gz: 76eae506592d22db3066d9f0ae71c29f3602ddff29926a8f808915d5d48e60810b1076153a5d41bd186e870a259ca96c2aeaef79c06b59d4aac54e5b13514ebe
|
@@ -0,0 +1,326 @@
|
|
1
|
+
require 'sumodev/command'
|
2
|
+
|
3
|
+
class Sumodev::Commands::Hooks < Sumodev::Command
|
4
|
+
namespace :hooks
|
5
|
+
|
6
|
+
no_commands do
|
7
|
+
def find_files_by_extension(files, extension)
|
8
|
+
files.select{ |i| i[/\.#{extension}$/] }
|
9
|
+
end
|
10
|
+
|
11
|
+
# Build a hash that we will use for errors or warnings.
|
12
|
+
def build_error_or_warning(type, line, message)
|
13
|
+
{
|
14
|
+
:type => type,
|
15
|
+
:line => line,
|
16
|
+
:message => message
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
def output_before_check(message)
|
21
|
+
# this has to end with a space so our next output is appended
|
22
|
+
say("--> #{message} ")
|
23
|
+
end
|
24
|
+
|
25
|
+
def check_files(files, methods)
|
26
|
+
errors_and_warnings = []
|
27
|
+
|
28
|
+
methods.each do |method|
|
29
|
+
has_warnings = false
|
30
|
+
has_errors = false
|
31
|
+
output_before_check(method[:human_readable_message])
|
32
|
+
|
33
|
+
files.each do |file|
|
34
|
+
case method[:command].class.to_s
|
35
|
+
when "String"
|
36
|
+
# if the command is a string we will run it on the CLI
|
37
|
+
command = "#{method[:command]}" % {:file => file}
|
38
|
+
IO.popen(command) do |f|
|
39
|
+
f.read.split("\n").each do |line|
|
40
|
+
error_or_warning = method[:line_handler].call(line)
|
41
|
+
unless error_or_warning.nil?
|
42
|
+
if 'error' == error_or_warning[:type]
|
43
|
+
has_errors = true
|
44
|
+
elsif 'warning' == error_or_warning[:type]
|
45
|
+
has_warnings = true
|
46
|
+
end
|
47
|
+
error_or_warning[:file] = file
|
48
|
+
errors_and_warnings << error_or_warning
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
when "Proc"
|
53
|
+
# a method is provided so call it.
|
54
|
+
error_or_warning = method[:command].call(file)
|
55
|
+
else
|
56
|
+
raise "Unknown type"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
output_result_after_check(
|
61
|
+
method[:human_readable_message],
|
62
|
+
has_errors,
|
63
|
+
has_warnings
|
64
|
+
)
|
65
|
+
end
|
66
|
+
|
67
|
+
errors_and_warnings
|
68
|
+
end
|
69
|
+
|
70
|
+
def check_css_files(files)
|
71
|
+
methods = [
|
72
|
+
{
|
73
|
+
:human_readable_message => "Checking for CSS-lint errors",
|
74
|
+
:command => "csslint --format=compact %{file}",
|
75
|
+
:line_handler => lambda { |line|
|
76
|
+
if line.include? "Warning - "
|
77
|
+
return build_error_or_warning(
|
78
|
+
'warning',
|
79
|
+
line.scan(/line\ ([0-9*])/i)[0][0],
|
80
|
+
line.scan(/Warning - (.*)/)[0][0]
|
81
|
+
)
|
82
|
+
end
|
83
|
+
if line.include? "Error - "
|
84
|
+
return build_error_or_warning(
|
85
|
+
'error',
|
86
|
+
line.scan(/line\ ([0-9*])/i)[0][0],
|
87
|
+
line.scan(/Error - (.*)/)[0][0]
|
88
|
+
)
|
89
|
+
end
|
90
|
+
}
|
91
|
+
}
|
92
|
+
]
|
93
|
+
|
94
|
+
check_files(files, methods)
|
95
|
+
end
|
96
|
+
|
97
|
+
def check_scss_files(files)
|
98
|
+
methods = [
|
99
|
+
{
|
100
|
+
:human_readable_message => "Checking SCSS lint errors",
|
101
|
+
:command => "scss-lint %{file}",
|
102
|
+
:line_handler => lambda { |line|
|
103
|
+
if line.include? "[W] "
|
104
|
+
return build_error_or_warning(
|
105
|
+
'warning',
|
106
|
+
line.scan(/\:([0-9*])/i)[0][0],
|
107
|
+
line.scan(/\[W\] (.*)/)[0][0]
|
108
|
+
)
|
109
|
+
end
|
110
|
+
if line.include? "[E] "
|
111
|
+
return build_error_or_warning(
|
112
|
+
'error',
|
113
|
+
line.scan(/\:([0-9*])/i)[0][0],
|
114
|
+
line.scan(/\[E\] (.*)/)[0][0]
|
115
|
+
)
|
116
|
+
end
|
117
|
+
}
|
118
|
+
}
|
119
|
+
]
|
120
|
+
|
121
|
+
check_files(files, methods)
|
122
|
+
end
|
123
|
+
|
124
|
+
def check_coffee_files(files)
|
125
|
+
methods = [
|
126
|
+
{
|
127
|
+
:human_readable_message => "Checking for keywords in Coffee-files",
|
128
|
+
:command => "egrep -no 'console\.' %{file}",
|
129
|
+
:line_handler => lambda { |line|
|
130
|
+
return build_error_or_warning(
|
131
|
+
'warning',
|
132
|
+
line.scan(/([0-9]*):/)[0][0],
|
133
|
+
"Keyword found: " + line.scan(/[0-9]*:(.*)/)[0][0]
|
134
|
+
)
|
135
|
+
}
|
136
|
+
}
|
137
|
+
]
|
138
|
+
|
139
|
+
check_files(files, methods)
|
140
|
+
end
|
141
|
+
|
142
|
+
def check_js_files(files)
|
143
|
+
methods = [
|
144
|
+
{
|
145
|
+
:human_readable_message => "Checking for js errors",
|
146
|
+
:command => "esvalidate --format=junit %{file}",
|
147
|
+
:line_handler => lambda { |line|
|
148
|
+
if line.include? "<warning "
|
149
|
+
return build_error_or_warning(
|
150
|
+
'warning',
|
151
|
+
line.scan(/Line ([0-9]*):/)[0][0],
|
152
|
+
line.scan(/>Line.*: (.*)\(/)[0][0]
|
153
|
+
)
|
154
|
+
end
|
155
|
+
if line.include? "<error "
|
156
|
+
return build_error_or_warning(
|
157
|
+
'error',
|
158
|
+
line.scan(/Line ([0-9]*):/)[0][0],
|
159
|
+
line.scan(/>Line.*: (.*)\(/)[0][0]
|
160
|
+
)
|
161
|
+
end
|
162
|
+
}
|
163
|
+
},
|
164
|
+
{
|
165
|
+
:human_readable_message => "Checking for keywords in JS-files",
|
166
|
+
:command => "egrep -no 'console\.' %{file}",
|
167
|
+
:line_handler => lambda { |line|
|
168
|
+
return build_error_or_warning(
|
169
|
+
'warning',
|
170
|
+
line.scan(/([0-9]*):/)[0][0],
|
171
|
+
"Keyword found: " + line.scan(/[0-9]*:(.*)/)[0][0]
|
172
|
+
)
|
173
|
+
}
|
174
|
+
}
|
175
|
+
]
|
176
|
+
|
177
|
+
check_files(files, methods)
|
178
|
+
end
|
179
|
+
|
180
|
+
def check_php_files(files)
|
181
|
+
methods = [
|
182
|
+
{
|
183
|
+
:human_readable_message => "Checking for PHP syntax errors",
|
184
|
+
:command => "php -l %{file} 2>&1",
|
185
|
+
:line_handler => lambda { |line|
|
186
|
+
if line.include? "PHP Parse error: "
|
187
|
+
return build_error_or_warning(
|
188
|
+
'error',
|
189
|
+
line.scan(/line ([0-9]*)$/)[0][0],
|
190
|
+
line.scan(/: (.*) in/)[0][0]
|
191
|
+
)
|
192
|
+
end
|
193
|
+
}
|
194
|
+
},
|
195
|
+
{
|
196
|
+
:human_readable_message => "Checking for PHP Coding standards errors",
|
197
|
+
:command => "phpcs --standard=PSR2 --extensions=php --encoding=utf8 --report=xml %{file}",
|
198
|
+
:line_handler => lambda { |line|
|
199
|
+
if line.include? "<warning "
|
200
|
+
return build_error_or_warning(
|
201
|
+
'warning',
|
202
|
+
line.scan(/line="([0-9]*)"/)[0][0],
|
203
|
+
line.scan(/>(.*)<\/warning>/)[0][0]
|
204
|
+
)
|
205
|
+
end
|
206
|
+
if line.include? "<error "
|
207
|
+
return build_error_or_warning(
|
208
|
+
'error',
|
209
|
+
line.scan(/line="([0-9]*)"/)[0][0],
|
210
|
+
line.scan(/>(.*)<\/error>/)[0][0]
|
211
|
+
)
|
212
|
+
end
|
213
|
+
}
|
214
|
+
},
|
215
|
+
{
|
216
|
+
:human_readable_message => "Checking for keywords in PHP-files",
|
217
|
+
:command => "egrep -no '(dump\\(|var_dump\\(|print_r\\(|exit|die|Zend_Debug::)' %{file}",
|
218
|
+
:line_handler => lambda { |line|
|
219
|
+
return build_error_or_warning(
|
220
|
+
'warning',
|
221
|
+
line.scan(/([0-9]*):/)[0][0],
|
222
|
+
"Keyword found: " + line.scan(/[0-9]*:(.*)/)[0][0]
|
223
|
+
)
|
224
|
+
}
|
225
|
+
}
|
226
|
+
]
|
227
|
+
|
228
|
+
check_files(files, methods)
|
229
|
+
end
|
230
|
+
|
231
|
+
def output_result_after_check(message, has_errors, has_warnings)
|
232
|
+
# as we append 7 characters ourself we should decrease the allowed maximum width.
|
233
|
+
say(".".rjust(72 - 7 - message.length, ".") + " ")
|
234
|
+
if has_errors
|
235
|
+
say("✘", :red)
|
236
|
+
elsif has_warnings
|
237
|
+
say("⚠", :yellow)
|
238
|
+
else
|
239
|
+
say("✔", :green)
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
def output_results(errors_and_warnings)
|
244
|
+
puts "\n"
|
245
|
+
|
246
|
+
if errors_and_warnings.empty?
|
247
|
+
say("Atta boy, no errors! ðº", :green)
|
248
|
+
return
|
249
|
+
end
|
250
|
+
|
251
|
+
# split into seperate arrays
|
252
|
+
errors = []
|
253
|
+
warnings = []
|
254
|
+
errors_and_warnings.each do |group,items|
|
255
|
+
items.each do |error_or_warning|
|
256
|
+
if error_or_warning[:type] == "error"
|
257
|
+
errors << error_or_warning
|
258
|
+
end
|
259
|
+
if error_or_warning[:type] == "warning"
|
260
|
+
warnings << error_or_warning
|
261
|
+
end
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
# some encouragement
|
266
|
+
if errors.empty? && !warnings.empty?
|
267
|
+
say("⚠ Yeah, only warnings!", :yellow)
|
268
|
+
end
|
269
|
+
if !errors.empty?
|
270
|
+
say("✘ Woops, errors! Check them below.", :red)
|
271
|
+
end
|
272
|
+
|
273
|
+
# output the warnings and errors
|
274
|
+
if !warnings.empty?
|
275
|
+
puts "\nWarnings\n--------\n"
|
276
|
+
warnings.each do |warning|
|
277
|
+
puts "• Warning: %{file}:%{line} - %{message}" % warning
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
if !errors.empty?
|
282
|
+
puts "\nErrors\n------\n"
|
283
|
+
errors.each do |error|
|
284
|
+
puts "• Error: %{file}:%{line} - %{message}" % error
|
285
|
+
end
|
286
|
+
end
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
desc 'check', "check the files"
|
291
|
+
def check(*files)
|
292
|
+
errors_and_warnings = {}
|
293
|
+
|
294
|
+
# Check the CSS files
|
295
|
+
css_files = find_files_by_extension(files, 'css')
|
296
|
+
if css_files.any?
|
297
|
+
errors_and_warnings['CSS'] = check_css_files(css_files)
|
298
|
+
end
|
299
|
+
|
300
|
+
# Check the SCSS files
|
301
|
+
scss_files = find_files_by_extension(files, 's(c|a)ss')
|
302
|
+
if scss_files.any?
|
303
|
+
errors_and_warnings['SCSS'] = check_scss_files(scss_files)
|
304
|
+
end
|
305
|
+
|
306
|
+
# Check the Coffee files
|
307
|
+
coffee_files = find_files_by_extension(files, 'coffee')
|
308
|
+
if coffee_files.any?
|
309
|
+
errors_and_warnings['Coffee'] = check_coffee_files(coffee_files)
|
310
|
+
end
|
311
|
+
|
312
|
+
# Check the JS files
|
313
|
+
js_files = find_files_by_extension(files, 'js')
|
314
|
+
if js_files.any?
|
315
|
+
errors_and_warnings['JS'] = check_js_files(js_files)
|
316
|
+
end
|
317
|
+
|
318
|
+
# Check the php files
|
319
|
+
php_files = find_files_by_extension(files, 'php')
|
320
|
+
if php_files.any?
|
321
|
+
errors_and_warnings['PHP'] = check_php_files(php_files)
|
322
|
+
end
|
323
|
+
|
324
|
+
output_results(errors_and_warnings)
|
325
|
+
end
|
326
|
+
end
|
data/lib/sumodev/version.rb
CHANGED
data/lib/sumodev.rb
CHANGED
@@ -9,6 +9,7 @@ class Sumodev < Thor
|
|
9
9
|
autoload :Push, 'sumodev/commands/push'
|
10
10
|
autoload :Project, 'sumodev/commands/project'
|
11
11
|
autoload :Box, 'sumodev/commands/box'
|
12
|
+
autoload :Hooks, 'sumodev/commands/hooks'
|
12
13
|
end
|
13
14
|
|
14
15
|
register Commands::Fork, 'fork', 'fork <command>', 'All commands concerning Fork applications'
|
@@ -17,5 +18,5 @@ class Sumodev < Thor
|
|
17
18
|
register Commands::Push, 'push', 'push <server>', 'Push the SSH keys to the server'
|
18
19
|
register Commands::Project, 'project', 'project <command>', 'All commands concerning projects'
|
19
20
|
register Commands::Box, 'box', 'box <command>', 'All commands concerning our Vagrant install'
|
21
|
+
register Commands::Hooks, 'hooks', 'hooks <command>', 'All commands concerning our git hooks'
|
20
22
|
end
|
21
|
-
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sumodev
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan De Poorter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -79,6 +79,7 @@ files:
|
|
79
79
|
- lib/sumodev/commands/box.rb
|
80
80
|
- lib/sumodev/commands/factr.rb
|
81
81
|
- lib/sumodev/commands/fork.rb
|
82
|
+
- lib/sumodev/commands/hooks.rb
|
82
83
|
- lib/sumodev/commands/project.rb
|
83
84
|
- lib/sumodev/commands/push.rb
|
84
85
|
- lib/sumodev/commands/ssh.rb
|