This repository has been 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.8k
/
test.rake
86 lines (72 loc) · 2.72 KB
/
test.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# Copyright © Magento, Inc. All rights reserved.
# See COPYING.txt for license details.
# frozen_string_literal: true
namespace :test do
# Run html-proofer to check for broken links
desc 'Build site, check for broken links, write report to a file'
task links: %w[build links_no_build]
desc 'Check the existing _site for broken EXTERNAL links'
task :external_links do
puts 'Testing external links'
system 'bin/htmlproofer _site/ --external_only'
end
desc 'Check the existing _site for broken INTERNAL links'
task :html do
puts 'Checking HTML ...'.magenta
LinkChecker.check_site
end
desc 'Check the existing _site for broken links and report to a separate file'
task :links_no_build do
# Write console output (stderr only) to a file.
# Use this if you need to also capture stdout: https://stackoverflow.com/a/2480439
report = LinkChecker.md_report_path
$stderr.reopen(report, 'w+')
Rake::Task['test:html'].invoke
# We're expecting link validation errors, but unless we rescue from
# StandardError, rake will abort and won't run the convert task (https://stackoverflow.com/a/10048406).
# Wrapping task in a begin-rescue block prevent rake from aborting.
# Seems to prevent printing an error count though.
rescue StandardError => e
# Show how many lines contains the Markdown report
puts e.to_s.red
puts "To see the report, open the #{report} file.".red
end
desc 'Report about broken links in HTML'
task report: %w[links] do
puts 'Converting the link check report to HTML...'.magenta
Converter.to_html
end
desc 'Test Markdown style with mdl'
task :md do
puts 'Testing Markdown style with mdl ...'.magenta
print 'List the rules: $ '.magenta
sh 'bin/mdl -l --style=_checks/styles/style-rules-prod'
puts 'Linting ...'.magenta
output =
`bin/mdl \
--style=_checks/styles/style-rules-prod \
--ignore-front-matter \
--git-recurse \
-- .`
puts output.yellow
abort 'Fix the reported issues'.red unless output.empty?
puts 'No issues found'.green
end
desc 'Find unused images'
task :unused_images do
puts 'Running a task for finding unused images'.magenta
images = Dir['src/**/*.{png,svg,jpeg,jpg,ico}']
puts "The project contains a total of #{images.size} images."
puts 'Checking for unlinked images...'
Dir['src/**/*.{md,html,js,css}'].each do |file|
# Exclude symmlinks
next if File.symlink? file
images.delete_if { |image| File.read(file).include?(File.basename(image)) }
end
abort 'No unliked images' if images.empty?
images.each do |image|
puts "No links for #{image}".yellow
end
puts "Found #{images.size} dangling images".red
end
end