forked from codegram/markdownizer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
65 lines (54 loc) · 1.87 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
require 'bundler'
Bundler::GemHelper.install_tasks
# Bring in Rocco tasks
require 'rocco/tasks'
require 'rake/clean'
Rocco::make 'docs/', 'lib/markdownizer.rb'
desc 'Build markdownizer docs'
task :docs => :rocco
directory 'docs/'
desc 'Build docs and open in browser for the reading'
task :read => :docs do
sh 'open docs/lib/rocco.html'
end
# Make index.html a copy of markdownizer.html
file 'docs/index.html' => 'docs/lib/markdownizer.html' do |f|
cp 'docs/lib/markdownizer.html', 'docs/index.html', :preserve => true
end
task :docs => 'docs/index.html'
CLEAN.include 'docs/index.html'
# Alias for docs task
task :doc => :docs
# GITHUB PAGES ===============================================================
site = 'docs'
source_branch = 'master'
deploy_branch = 'gh-pages'
desc "generate and deploy website to github user pages"
multitask :pages do
puts ">>> Deploying #{deploy_branch} branch to Github Pages <<<"
require 'git'
repo = Git.open('.')
puts "\n>>> Checking out #{deploy_branch} branch <<<\n"
repo.branch("#{deploy_branch}").checkout
(Dir["*"] - [site]).each { |f| rm_rf(f) }
Dir["#{site}/*"].each {|f| mv(f, "index.html")}
rm_rf(site)
puts "\n>>> Moving generated site files <<<\n"
Dir["**/*"].each {|f| repo.add(f) }
repo.status.deleted.each {|f, s| repo.remove(f)}
puts "\n>>> Commiting: Site updated at #{Time.now.utc} <<<\n"
message = ENV["MESSAGE"] || "Site updated at #{Time.now.utc}"
repo.commit(message)
puts "\n>>> Pushing generated site to #{deploy_branch} branch <<<\n"
repo.push
puts "\n>>> Github Pages deploy complete <<<\n"
repo.branch("#{source_branch}").checkout
end
# TESTS =====================================================================
require 'rspec/core'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec) do |spec|
spec.pattern = FileList['spec/**/*_spec.rb']
end
task :default => :spec
task :test => [:spec]