-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
107 lines (92 loc) · 2.97 KB
/
Rakefile
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
require 'html-proofer'
require 'image_optim'
require 'English'
LIBS_DIR = '_libs'
BUILD_DIR = '_build'
NPM = `which npm`.chomp
WGET = `which wget`.chomp
JAMPACK = './node_modules/.bin/jampack'
JEKYLL_ENV = ENV['JEKYLL_ENV'] || 'development'
desc 'Jekyll build'
task :jekyll_build do
puts '--> Jekyll build'
system "rm -rf #{BUILD_DIR}"
config = File.exist?("_config_#{JEKYLL_ENV}.yml") ? ",_config_#{JEKYLL_ENV}.yml" : nil
system "jekyll build -d #{BUILD_DIR} --config _config.yml#{config}" || exit(1)
if JEKYLL_ENV == 'production'
system "jekyll build -d #{BUILD_DIR} --config _config.yml#{config}" || exit(1)
puts '--> Run jampack'
system "#{JAMPACK} #{BUILD_DIR}" || exit(1)
end
end
desc 'npm install'
task :npm_install do
puts '--> Grab front-end packages with npm'
system "#{NPM} install"
end
desc 'Minify all html'
task :minify_html do
puts '--> Minifying html'
system "find #{BUILD_DIR} -type f -name '*.html' " \
"| xargs -I '%' -P 4 -n 1 node_modules/.bin/html-minifier " \
'--collapse-whitespace --remove-comments --remove-optional-tags ' \
'--remove-redundant-attributes --remove-script-type-attributes ' \
'--remove-tag-whitespace --use-short-doctype --minify-css true ' \
"--conservativeCollapse --minify-js true '%' -o '%'"
end
desc 'Gzip'
task :gzip, [:ext] => [:gzip_all] do |_t, args|
puts "--> GZipping '#{args.ext}'"
system "find #{BUILD_DIR} -type f -name '*.#{args.ext}' -print0 | " \
"xargs -0 -I % -P 4 -n 1 sh -c 'gzip -9 < % > %.gz'"
end
desc 'GZip All'
task :gzip_all do
Rake::Task[:gzip].execute('html')
Rake::Task[:gzip].execute('css')
Rake::Task[:gzip].execute('js')
end
desc 'Test for 404s'
task :check_html do
puts '--> Check for broken links'
HTMLProofer.check_directory(
BUILD_DIR,
{
ext: '.html',
parallel: { in_processes: 4 },
url_ignore: ['#', '/twitter.com/', '/disqus.com/'],
validate_html: false,
disable_external: true
}
).run
end
desc 'Fix files permissions'
task :fix_files_permissions do
puts '--> Fix files permissions'
system "find #{BUILD_DIR} -type f | xargs -n 1 -P 4 chmod 644"
system "find #{BUILD_DIR} -type d | xargs -n 1 -P 4 chmod 755"
end
desc 'Full build task'
task :build do
puts '--> Start build'
Rake::Task['npm_install'].invoke
Rake::Task['jekyll_build'].invoke
Rake::Task['minify_html'].invoke
Rake::Task['gzip_all'].invoke
Rake::Task['fix_files_permissions'].invoke
Rake::Task['check_html'].invoke
puts '--> End'
end
desc 'Clean activities CSV'
task :clean_activites_csv do
ACTIVITIES = './_data/activities/'
# Clean whitespaces
system "find #{ACTIVITIES} -type f -name '*.csv' | \
xargs -n 1 -P 4 sed -i -e 's/^[ \t]*//' -e 's/[ \t]*$//'"
# Clean last blank line
system "find #{ACTIVITIES} -type f -name '*.csv' | \
xargs -n 1 -P 4 sed -i '/^ *$/d'"
# Clean useless line
system "find #{ACTIVITIES} -type f -name '*.csv' | \
xargs -n 1 -P 4 sed -i '/Activities by bdossantos/d'"
end