-
Notifications
You must be signed in to change notification settings - Fork 4
/
Rakefile
48 lines (44 loc) · 1.37 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
require 'tmpdir'
task :clean do
Dir.chdir(Dir.tmpdir) do
sh("rm -rf screenplay-example")
end
end
namespace :docs do
task :code do
pwd = Dir.pwd
puts "Working in #{pwd}"
current_branch = `git rev-parse --abbrev-ref HEAD`
sh 'rm -rf code'
sh 'mkdir code'
Dir.chdir(Dir.tmpdir) do
sh("git clone --quiet #{pwd} screenplay-example") unless Dir.exists?('screenplay-example') && Dir.exists?('screenplay-example/.git')
Dir.chdir("screenplay-example") do
puts "Working in #{Dir.pwd}"
sh "git fetch origin"
sh "git config advice.detachedHead false"
sh "git branch -D code || echo no code branch"
sh "git checkout -b code &> /dev/null"
sh "git reset --hard origin/code"
commits = `git rev-list code`.split.reverse
puts commits
commits.each_with_index do |commit, i|
commit_message = `git show -s --format=%s #{commit}`.split("\n").first
dir = "#{pwd}/code/%02d-#{commit_message.downcase.gsub(/\W+/, "-")}" % i
sh "mkdir #{dir}"
sh "git checkout #{commit}"
sh "cp -R . #{dir}"
sh "rm -rf #{dir}/.git"
end
end
end
end
task :html do
require 'asciidoctor'
Asciidoctor.convert_file 'index.adoc',
safe: :unsafe,
to_dir: '.',
mkdirs: true
end
end
task :default => ['docs:code', 'docs:html']