-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Rakefile
163 lines (141 loc) · 4.2 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# Directories and files generated by this Rakefile
# - _includes: Used for Jekyll includes. Created by merging the
# _jekyll/_includes directories of the www + docs repos
# - assets/images/docs: Used for images from the docs repo.
$generated_files = [
'_includes',
'assets/images/docs',
'_data/docs',
]
# Configuration details for external repos (e.g. docs)
$external_repos = [
{
"repo" => "docs",
"destination" => "docs",
"branch" => "master"
},
]
# ---- Rake tasks
task :default => :serve
desc 'Set up the build environment'
task :init do
# Install packages
sh 'bundle config --local build.therubyracer --with-v8-dir=$(brew --prefix v8)'
sh 'bundle install'
# Clone the external repos
root = pwd
$external_repos.map{ |repo|
clone_repo(root, repo)
}
end
desc 'Clean up the generated site'
task :clean do
rm_rf '_site'
rm_rf '_deploy'
rm '.jekyll-metadata', :force => true
$generated_files.each{ |d|
rm_rf d
}
end
desc 'Pull the latest commits for the external repos'
task :pull do
# Make sure we've checked out the right branch
root = pwd
$external_repos.map{ |repo|
begin
cd "#{root}/#{repo["destination"]}"
pull_branch("#{repo["branch"]}")
rescue
$stderr.puts "Error when trying to pull #{repo["repo"]}. Did you forget to run `rake init_subs`?"
exit 1
end
}
cd root
end
# Merges assets from the www repo and the docs repo
desc 'Copy assets and includes from the docs repository'
task :copy_assets do
# Create each destination directory, if it doesn't already exist
['_includes'].each{ |dir_name|
FileUtils.mkdir_p(dir_name) unless Dir.exist?(dir_name)
}
assets_to_copy = [
{:source => '_jekyll/_includes/.', :target => '_includes/'},
{:source => 'docs/_jekyll/_includes/.', :target => '_includes/docs/'},
{:source => 'docs/_jekyll/_images/.', :target => 'assets/images/docs/'},
{:source => 'docs/_jekyll/_data/.', :target => '_data/docs/'},
]
assets_to_copy.each{ |asset|
FileUtils.cp_r(asset[:source], asset[:target], :verbose => true)
}
end
desc 'Build site with Jekyll'
task :build => ['clean', 'copy_assets'] do
jekyll('build')
end
desc 'Start server and regenerate files on change'
task :serve => ['copy_assets'] do
check_for_required_files(:warning => true)
jekyll('serve')
end
desc 'Start the server quickly, using an existing build, and regenerate files on change'
task :up do
jekyll('serve --skip-initial-build')
end
desc 'Start Python SimpleHTTPServer'
task :pyserve do
cd '_site'
sh 'python -m SimpleHTTPServer 8888'
end
desc 'Benchmark the Jekyll build'
task :benchmark do
require 'benchmark'
time = Benchmark.realtime do
Rake::Task[:build].invoke
end
puts "Time elapsed #{time*1000} milliseconds"
end
desc 'Build site with Jekyll'
task :generate => ['build'] do
end
# ---- Rake functions
# Run Jekyll
def jekyll(opts = '')
if ENV['dev']=='on'
dev = ' --plugins=_plugins,_plugins-dev'
else
dev = ''
end
sh "bundle exec jekyll #{opts}#{dev} --trace"
end
# Check if all generated files are present: by default abort if files aren't present, otherwise show a warning
def check_for_required_files(opts={})
missing_files = 0
$generated_files.each do |f|
if !File.exist?(f)
puts "Required file missing: #{f}"
missing_files +=1
end
end
if missing_files > 0
error = "#{missing_files} required files not found. Run `rake build` before deploying."
if opts[:warning] then puts error else fail error end
end
end
def pull_branch(branch_name)
sh "git checkout #{branch_name}"
sh "git pull"
end
# Git: clone a RethinkDB GitHub repository
def clone_repo(root, repo)
begin
destination = "#{root}/#{repo["destination"]}"
rm_rf destination
sh "git clone https://github.com/rethinkdb/#{repo["repo"]}.git #{destination}"
cd destination
sh "git checkout #{repo["branch"]}"
rescue Exception
$stderr.puts "Error while cloning #{repo["repo"]}"
exit 1
end
end