-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rakefile
90 lines (74 loc) · 2.69 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
COMPILED_DIR = "adamliter.org"
DEST_DIR = "_site"
task :default => [:build]
desc "Build Jekyll site and copy files to COMPILED_DIR"
task :build do
Rake::Task["helper:wipe_dest_dir"].invoke
sh "jekyll build"
Rake::Task["helper:wipe_compiled_dir"].invoke
# Hack around jekyll build not dereferencing symlinks
Rake::Task["helper:force_dereference_bootstrap_js"].invoke
sh "cp -RL _site/* #{COMPILED_DIR}/"
Rake::Task["helper:kill_updates"].invoke
Rake::Task["helper:make_well_known"].invoke
end
desc "Serve Jekyll site locally for development and watch"
task :watch do
Rake::Task["helper:wipe_dest_dir"].invoke
Rake::Task["helper:kill_running_jekyll"].invoke
sh "jekyll serve -w"
end
desc "Serve Jekyll site locally for development purposes"
task :serve do
Rake::Task["helper:wipe_dest_dir"].invoke
Rake::Task["helper:kill_running_jekyll"].invoke
sh "jekyll serve -B"
Rake::Task["helper:force_dereference_bootstrap_js"].invoke
end
namespace :deploy do
desc "Check HTML output with htmlproofer"
task :proof do
sh "htmlproofer #{COMPILED_DIR} --only-4xx --checks=Links,Images,Scripts --allow-hash-href --enforce-https --ignore-status-codes 403"
end
desc "Deploy to production"
task :deploy_prod do
sh "rsync -avzHP #{COMPILED_DIR}/shiny/index.html -e ssh [email protected]:/srv/shiny-server/"
sh "rm -rf #{COMPILED_DIR}/shiny"
sh "rsync -avzHP --exclude='.git' --delete #{COMPILED_DIR}/ -e ssh [email protected]:/var/www/adamliter.org"
end
end
# Helper rake tasks
namespace :helper do
desc "Clean DEST_DIR"
task :wipe_dest_dir do
sh "rm -rf #{DEST_DIR}/" unless Dir["#{DEST_DIR}/*"].empty?
end
desc "Clean COMPILED_DIR"
task :wipe_compiled_dir do
sh "rm -r #{COMPILED_DIR}/*" unless Dir["#{COMPILED_DIR}/*"].empty?
end
desc "Kill the Jekyll server running in the background"
task :unserve do
sh "kill -9 $(pgrep jekyll)"
end
desc "Kill Jekyll if already running"
task :kill_running_jekyll do
unless `pgrep jekyll`.empty?
puts("Jekyll is already running. Killing already running process...")
Rake::Task["helper:unserve"].invoke
end
end
desc "Hack around Jekyll build not derefencing symlinks"
task :force_dereference_bootstrap_js do
sh "ln -sf ../../bootstrap/assets/javascripts/bootstrap.min.js #{DEST_DIR}/js/bootstrap.min.js"
end
desc "Remove individual post pages in updates"
task :kill_updates do
UPDATE_DIRS = Dir.glob("#{COMPILED_DIR}/updates/*").select { |f| File.directory? f }
UPDATE_DIRS.each { |dir| sh "rm -rf #{dir}" }
end
desc "Make the .well-known directory for letsencrypt renewal"
task :make_well_known do
sh "mkdir -p #{COMPILED_DIR}/.well-known"
end
end