forked from internetisaiah/braze-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRakefile
More file actions
257 lines (218 loc) · 7.09 KB
/
Copy pathRakefile
File metadata and controls
257 lines (218 loc) · 7.09 KB
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
require 'fileutils'
require 'find'
require 'thread'
# File watching functionality
def watch_includes_folder
puts "Starting file watcher for _includes folder..."
load 'includes_watcher.rb'
watcher = IncludesWatcher.new
watcher.start
rescue Interrupt
puts "File watcher interrupted, shutting down..."
rescue => e
puts "File watcher error: #{e.message}"
end
def pipe(command)
output = ''
IO.popen(command) do |io|
until io.eof?
buffer = io.gets
output << buffer
puts buffer
end
end
output
end
task default: :serve
def fast_jekyll_build?
%w[1 true yes].include?(ENV.fetch('JEKYLL_FAST', '').downcase) ||
%w[1 true yes].include?(ENV.fetch('BRAZE_DOCS_FAST_BUILD', '').downcase)
end
def jekyll_build_configs(config_file, incremental: false)
incremental ||= fast_jekyll_build?
return config_file unless incremental
return config_file if config_file.include?('_incremental_config')
"#{config_file},_incremental_config.yml"
end
def jekyll_build(config_file = '_config.yml', lang = 'en', incremental: false)
public_folder = './public'
configs = jekyll_build_configs(config_file, incremental: incremental)
command = ['bundle', 'exec', 'jekyll', 'build', '--config', configs]
command << '--incremental' if incremental || fast_jekyll_build?
pipe(command)
if (lang != 'en')
index_file = File.join(public_folder, "index_#{lang}.html")
FileUtils.copy_file(index_file, File.join('_site', "index.html"))
FileUtils.copy_file(File.join("_site/docs/#{lang}", "404.html"), File.join('_site', "404.html"))
end
verify_llms_txt_artifacts(lang)
end
# Post-build sanity check: confirms the llms.txt / llms-full.txt files the
# llms_txt_generator plugin is supposed to emit are actually present on disk.
# Only enforced for the English build (other locales don't generate them).
def verify_llms_txt_artifacts(lang)
return unless lang == 'en'
return if %w[1 true yes].include?(ENV.fetch('SKIP_LLMS_TXT_VERIFY', '').downcase)
expected = %w[user_guide developer_guide api partners releases].flat_map do |collection|
%W[_site/#{collection}/llms.txt _site/#{collection}/llms-full.txt]
end
missing = expected.reject { |path| File.exist?(path) && File.size(path) > 0 }
if missing.empty?
puts "LLMS verify: all #{expected.length} llms.txt artifacts present in _site."
return
end
warn "LLMS verify: missing or empty artifacts after Jekyll build:"
missing.each { |path| warn " - #{path}" }
warn "LLMS verify: this means the llms_txt_generator plugin did not run."
warn "LLMS verify: set SKIP_LLMS_TXT_VERIFY=1 to bypass this check."
abort "LLMS verify: failing the build so the deploy doesn't ship without llms.txt files."
end
def jekyll_serve(config_file = '_config.yml')
if ENV["RACK_ENV"] == 'staging'
pipe "bundle exec jekyll s --port 5006 --config #{config_file}"
else
# Dropping .jekyll-metadata forces a full rebuild (slow). Omit unless you need
# a clean slate (asset pipeline oddities, stale incremental cache): JEKYLL_CLEAN=1 rake
if %w[1 true yes].include?(ENV.fetch('JEKYLL_CLEAN', '').downcase)
puts `rm -f .jekyll-metadata`
end
# Start file watcher in a separate thread
watcher_thread = Thread.new do
watch_includes_folder
end
# Set up signal handlers to stop the watcher thread
Signal.trap('INT') do
puts "\nStopping Jekyll serve and file watcher..."
watcher_thread.raise Interrupt
exit 0
end
Signal.trap('TERM') do
puts "\nStopping Jekyll serve and file watcher..."
watcher_thread.raise Interrupt
exit 0
end
begin
pipe "bundle exec jekyll s --port 5006 --incremental --config #{config_file},_incremental_config.yml"
ensure
# Ensure the watcher thread is stopped when Jekyll exits
watcher_thread.raise Interrupt if watcher_thread.alive?
watcher_thread.join(2) # Wait up to 2 seconds for clean shutdown
end
end
end
namespace :docs_en do
config_file = './_config.yml'
task :index do
if ENV["SITE_URL"] == 'https://www.braze.com' && ENV["RACK_ENV"] == 'production'
puts `bundle exec jekyll algolia --config #{config_file}`
end
end
task build: [:index] do
jekyll_build(config_file, 'en')
end
task build_fast: [:index] do
jekyll_build(config_file, 'en', incremental: true)
end
task :serve do
jekyll_serve(config_file)
end
task :serve_with_watch do
jekyll_serve(config_file)
end
task :proxy_serve do
pipe 'bundle exec ruby proxy.rb'
end
end
namespace :lang do
task :index, [:lang] do |t, args|
config_file = "./_config.yml,./_lang/_config_#{args[:lang]}.yml"
if ENV["SITE_URL"] == 'https://www.braze.com' && ENV["RACK_ENV"] == 'production'
puts `bundle exec jekyll algolia --config #{config_file}`
end
end
task :build, [:lang] => [:index] do |t, args|
jekyll_build("./_config.yml,./_lang/_config_#{args[:lang]}.yml", args[:lang])
end
task :build_fast, [:lang] => [:index] do |t, args|
jekyll_build("./_config.yml,./_lang/_config_#{args[:lang]}.yml", args[:lang], incremental: true)
end
task :serve, [:lang] do |t, args|
jekyll_serve("./_config.yml,./_lang/_config_#{args[:lang]}.yml")
end
task :serve_with_watch, [:lang] do |t, args|
jekyll_serve("./_config.yml,./_lang/_config_#{args[:lang]}.yml")
end
task :proxy_serve, [:lang] do |t, args|
pipe "bundle exec ruby proxy.rb #{args[:lang]}"
end
end
namespace :assets do
task :precompile do
print 'no-op'
end
end
# Usage: rake "lang[:lang]" ie
# rake "lang[:fr]"
# rake "lang[:ja]"
multitask :lang, [:lang] => [
'lang:serve',
'lang:proxy_serve'
]
multitask serve: [
'docs_en:serve', 'docs_en:proxy_serve'
]
multitask en: [
'docs_en:serve', 'docs_en:proxy_serve'
]
task :fr do
Rake::Task["lang"].invoke('fr')
end
task :ja do
Rake::Task["lang"].invoke('ja')
end
task :ko do
Rake::Task["lang"].invoke('ko')
end
task :pt_br do
Rake::Task["lang"].invoke('pt-br')
end
task :es do
Rake::Task["lang"].invoke('es')
end
task :de do
Rake::Task["lang"].invoke('de')
end
task :fr_build do
Rake::Task["lang:build"].invoke('fr')
end
task :ja_build do
Rake::Task["lang:build"].invoke('ja')
end
task :ko_build do
Rake::Task["lang:build"].invoke('ko')
end
task :pt_br_build do
Rake::Task["lang:build"].invoke('pt-br')
end
task :es_build do
Rake::Task["lang:build"].invoke('es')
end
task :de_build do
Rake::Task["lang:build"].invoke('de')
end
# Convenience tasks for file watching
task :serve_with_test_watch do
Rake::Task["docs_en:serve_with_watch"].invoke
end
task :serve_with_lint_watch do
Rake::Task["docs_en:serve_with_watch"].invoke
end
task :serve_with_build_watch do
Rake::Task["docs_en:serve_with_watch"].invoke
end
# Usage examples:
# rake serve_with_test_watch # Serve with file watching (same as serve_with_watch)
# rake serve_with_lint_watch # Serve with file watching (same as serve_with_watch)
# rake serve_with_build_watch # Serve with file watching (same as serve_with_watch)
# rake docs_en:serve_with_watch # Serve English docs with file watching
# rake "lang:serve_with_watch[fr]" # Serve French docs with file watching