This repository has been archived by the owner on Mar 20, 2018. It is now read-only.
/
Rakefile
57 lines (50 loc) · 1.69 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
require "rubygems"
require "bundler"
Bundler.setup
desc "remove files in output directory"
task :clean do
puts ">>> Removing output <<<"
Dir["#{site}/*"].each { |f| rm_rf(f) }
end
desc "Generate site files only"
task :generate_site => [:clean] do
puts "\n\n>>> Generating site files <<<"
system "bundle exec staticmatic build ."
end
desc "generate and deploy website to github user pages"
multitask :deploy_github do
deploy_branch = "gh-pages"
source_branch = "docs"
site = "site"
puts ">>> Deploying #{deploy_branch} branch to Github Pages <<<"
require 'git'
repo = Git.open('.')
Dir["src/site/*"].each {|f| cp(f, "./site")}
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, ".")}
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("origin", "gh-pages")
puts "\n>>> Github Pages deploy complete <<<\n"
repo.branch("#{source_branch}").checkout
end
task :preview do
require "staticmatic"
configuration = StaticMatic::Configuration.new
directory = "/users/steve/projects/restful-routing"
config_file = "#{directory}/src/configuration.rb"
if File.exists?(config_file)
config = File.read(config_file)
eval(config)
end
staticmatic = StaticMatic::Base.new(directory, configuration)
staticmatic.run("preview")
end