-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_docs.rb
executable file
·46 lines (33 loc) · 1007 Bytes
/
build_docs.rb
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
#!/usr/bin/env ruby
require 'fileutils'
require 'open3'
stack_haddock_stderr = Open3.capture3('stack haddock')[1]
# Example: ".stack-work/install/x86_64-osx/lts-10.2/8.2.2/doc"
built_docs_dir = stack_haddock_stderr.lines.select do |x|
x.match(/\.stack-work/)
end.map do |x|
x.chomp.sub(/^.*\.stack-work/, './.stack-work')
end.select do |x|
x.match(/\/doc\//)
end.map do |x|
x.sub(/\/doc\/.*$/,'/doc')
end.first
puts stack_haddock_stderr
# Copy built docs to
if built_docs_dir && Dir.exist?(built_docs_dir)
puts "Built_docs_dir: #{built_docs_dir}"
unless File.exist?('.gitignore')
puts "No .gitignore in current directory, assuming you're not running this right and exiting"
exit
end
if Dir.exist?('doc/')
puts "Removing previous doc/ dir"
FileUtils.rm_rf 'doc/'
else
puts "No previous doc/ dir to remove"
end
FileUtils.cp_r built_docs_dir, 'doc/'
puts "Docs copied to doc/"
else
puts "Unable to find 'built_docs_dir', docs not copied to doc/"
end