This repository was archived by the owner on Nov 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathcheck.rake
60 lines (46 loc) · 1.92 KB
/
check.rake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Copyright © Magento, Inc. All rights reserved.
# See COPYING.txt for license details.
# frozen_string_literal: true
namespace :check do
desc 'Optimize images in modified files, or by path (rake check:img path=path/to/dir/or/file).'
task :image_optim do
puts
puts 'Checking images ...'.magenta
path = ENV['path']
unless path
puts 'Looking in uncommitted files ...'.blue
modified_files = `git ls-files --modified --others --exclude-standard`.split("\n")
deleted_files = `git ls-files --deleted`.split("\n")
image_files_to_check = (modified_files - deleted_files).select do |file|
File.extname(file) =~ /\.(png|jpg|jpeg|gif)/i
end
next puts 'No images to check.'.magenta if image_files_to_check.empty?
path = image_files_to_check.join(' ')
end
system "bin/image_optim --no-pngout --no-svgo --recursive #{path}"
end
desc 'Check Markdown syntax in modified files or in a particular file or directory by path (e.g. path=mftf)'
task :mdl do
puts
puts 'Checking Markdown ...'.magenta
print 'List the rules: $ '.magenta
sh 'bin/mdl -l --style=_checks/styles/style-rules-dev'
puts 'Linting ...'.magenta
path = ENV['path']
unless path
puts 'Looking in uncommitted files ...'.blue
modified_files = `git ls-files --modified --others --exclude-standard`.split("\n")
deleted_files = `git ls-files --deleted`.split("\n")
md_files_to_check = (modified_files - deleted_files).select { |file| File.extname(file) == '.md' }
next puts 'No Markdown files to check.'.magenta if md_files_to_check.empty?
path = md_files_to_check.join(' ')
end
report = `bin/mdl --style=_checks/styles/style-rules-dev --ignore-front-matter -- #{path}`
if report.empty?
puts 'No issues found'.green
else
puts report.yellow
end
puts 'The rules are defined in _checks/styles/style-rules-dev'.magenta
end
end