forked from basho/basho_docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
192 lines (160 loc) · 6.05 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
### Basho Docs' Rakefile
#
# This Rakefile is to be invoked with the `rake` Ruby Gem. It's best if the that
# Gem is installed using Bundler and the included Gemfile.
#
# This file will act as the canonical builder for the JavaScript/CoffeeScript
# and CSS/SCSS 'dynamic' files, which are compiled into static/js/ and
# static/css/ respectively.
#TODO<drew.pirrone.brusse@gmail>: Make sure the above description is correct and
# complete.
require_relative 'rake_libs/compile_js'
require_relative 'rake_libs/compile_css'
require_relative 'rake_libs/s3_deploy'
require_relative 'rake_libs/downloads_metadata_generator'
require_relative 'rake_libs/projects_metadata_generator'
$css_source = "./dynamic/css"
$css_dest = "./static/css"
$js_source = "./dynamic/js"
$js_dest = "./static/js"
$cache_dir = "./dynamic/.cache"
$hugo_dest = "./public" # Should always be set to `publishdir` from config.yml
### Rake directory definitions
directory "#{$js_dest}"
directory "#{$css_dest}"
directory "#{$cache_dir}"
#TODO<drew.pirrone.brusse@gmail>: Check to make sure Hugo's version is >= 0.15
######################################################################
### Rake Namespace and Task definitions
##########
# Default
Rake::TaskManager.record_task_metadata = true
task :default do
puts("Basho Documentation Generate System Usage:")
puts("")
Rake::application.options.show_tasks = :tasks # this solves sidewaysmilk problem
Rake::application.options.show_task_pattern = //
Rake::application.display_tasks_and_comments
end;
########
# Clean
#TODO<drew.pirrone.brusse@gmail>: These `rm -rf`s are maybe a bit much? Should
# we be more precise with what we delete (and, if so, how)?
desc "Clean dynamically generated content (does not clean Hugo content)"
task :clean => ['clean:js', 'clean:css']
namespace :clean do
desc "Clean dynamically generated JS"
task :js do
# The standalone/ directory may exist if we've extracted archived content
# (see deploy:fetch_archived_content). We don't want to remove those files.
js_file_list = Dir["#{$js_dest}/**/*"].reject {|f| /standalone/.match(f) }
js_file_list.each do |f|
log_deletion(f)
FileUtils.rm(f)
end
end
desc "Clean dynamically generated CSS"
task :css do
# The standalone/ directory may exist if we've extracted archived content
# (see deploy:fetch_archived_content). We don't want to remove those files.
css_file_list = Dir["#{$css_dest}/**/*"].reject {|f| /standalone/.match(f) }
css_file_list.each do |f|
log_deletion(f)
FileUtils.rm(f)
end
end
desc "Clean Hugo-generated content"
task :hugo do
log_deletion($hugo_dest)
FileUtils.rm_rf($hugo_dest)
end
end
########
# Build
desc "Compile compressed JS and compressed CSS"
task :build => ['clean', 'build:js', 'build:css']
namespace :build do
task :js => ["#{$js_dest}", 'clean:js'] do compile_js(debug: false); end
task :css => ["#{$css_dest}", 'clean:css'] do compile_css(debug: false); end
################
# Build : Debug
desc "Compile human-readable JS and compile human-readable CSS"
task :debug => ["#{$js_dest}", "#{$css_dest}",
'build:debug:js', 'build:debug:css']
namespace :debug do
desc "Compile human-readable JS"
task :js => ["#{$js_dest}"] do compile_js(debug: true); end
desc "Compile human-readable CSS"
task :css => ["#{$css_dest}"] do compile_css(debug: true); end
end
end
########
# Watch
desc "Rebuild compressed JS and CSS content on file saves"
task :watch do sh 'bundle exec guard -g css js'; end
namespace :watch do
task :js do sh 'bundle exec guard -g js'; end
task :css do sh 'bundle exec guard -g css'; end
################
# Watch : Debug
desc "Rebuild human-readable JS and CSS content on file saves"
task :debug => ['clean'] do sh 'bundle exec guard -g debug_js debug_css'; end
namespace :debug do
task :js do sh 'bundle exec guard -g debug_js'; end
task :css do sh 'bundle exec guard -g debug_css'; end
end
end
#######
# Hugo
desc "Generate the static site into #{$hugo_dest}"
task :hugo => ['clean:hugo'] do sh "hugo -d #{$hugo_dest}"; end
namespace :hugo do
#TODO<drew.pirrone.brusse@gmail>: Add in some way to specify ip/port.
desc "Run Hugo Server"
task :server do sh "hugo server"; end
end
#########
# Deploy
desc "Build and deploy static artifacts"
task :deploy => [
'clean',
'deploy:fetch_archived_content',
'build:js',
'build:css',
'hugo'
] do do_deploy(); end
namespace :deploy do
task :immediately_and_unsafely do do_deploy(); end
task :fetch_archived_content do do_fetch_archived_content(); end
end
#####################
# Metadata Generation
#
# These tasks should be run in response to a new version of any project being
# made available. When a new package is uploaded to our downloads host, we will
# need to run `rake metadata:generate_downloads`. When a new version or project
# is added to config.yaml, run `rake metadata:generate_projects`.
task :generate_metadata
namespace :metadata do
desc "Update all generative metadata files"
task :all => ['metadata:generate_downloads', 'metadata:generate_projects']
desc "Generate package URI information"
task :generate_downloads do generate_downloads_metadata(); end
desc "Generate JavaScript-readable project descriptions"
task :generate_projects do generate_projects_metadata(); end
end
######################################################################
### Helper/Compilation functions
# Prints " deleting #{target}" to the console, and color "deleting" red.
def log_deletion(target)
red = "\033[31m"
nc = "\033[0m" # no color
print " #{red}deleting#{nc} #{target}\n"
end
# Print " write #{target}" to the console, and color "write" green. This is
# designed to match the Compass log output on file writes.
def log_write(target)
green = "\033[32m"
nc = "\033[0m" # no color
print " #{green}write#{nc} #{target}\n"
end