-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathRakefile
107 lines (95 loc) · 3.59 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
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
# adapted from http://octopress.org/
require "rubygems"
require "bundler/setup"
deploy_branch = "master"
public_dir = "_site" # compiled site directory
deploy_dir = "_deploy" # deploy directory (for Github pages deployment)
#######################
# Working with Jekyll #
#######################
desc "Generate jekyll site"
task :generate do
#TODO raise "### You haven't set anything up yet." unless File.directory?()
puts "## Generating Site with Jekyll"
system "jekyll build"
end
##############
# Deploying #
##############
desc "Default deploy task"
task :deploy do
Rake::Task[:push].execute
end
desc "Generate website and deploy"
task :gen_deploy => [:generate, :deploy] do
end
desc "copy dot files for deployment"
task :copydot, :source, :dest do |t, args|
FileList["#{args.source}/**/.*"].exclude("**/.", "**/..", "**/.DS_Store", "**/._*").each do |file|
cp_r file, file.gsub(/#{args.source}/, "#{args.dest}") unless File.directory?(file)
end
end
desc "deploy public directory to github pages"
multitask :push do
puts "## Deploying branch to Github Pages "
(Dir["#{deploy_dir}/*"]).each { |f| rm_rf(f) }
Rake::Task[:copydot].invoke(public_dir, deploy_dir)
puts "\n## copying #{public_dir} to #{deploy_dir}"
cp_r "#{public_dir}/.", deploy_dir
cd "#{deploy_dir}" do
system "git add ."
system "git add -u"
message = "Site updated at #{Time.now.utc}"
puts "\n## Commiting: #{message}"
system "git commit -m \"#{message}\""
puts "\n## Pushing generated #{deploy_dir} website"
system "git push origin #{deploy_branch} --force"
puts "\n## Github Pages deploy complete"
end
end
desc "Set up _deploy folder and deploy branch for Github Pages deployment"
task :setup_github_pages, :repo do |t, args|
if args.repo
repo_url = args.repo
else
puts "Enter the read/write url for your repository"
puts "(For example, '[email protected]:your_username/your_username.github.io)"
print "Repository url: "
repo_url = STDIN.gets.chomp
end
user = repo_url.match(/:([^\/]+)/)[1]
branch = (repo_url.match(/\/[\w-]+\.github\.(?:io|com)/).nil?) ? 'gh-pages' : 'master'
project = (branch == 'gh-pages') ? repo_url.match(/\/([^\.]+)/)[1] : ''
unless (`git remote -v` =~ /origin.+?all_about_you(?:\.git)?/).nil?
# If all_about_you is still the origin remote (from cloning) rename it to all_about_you
system "git remote rename origin all_about_you"
if branch == 'master'
# If this is a user/organization pages repository, add the correct origin remote
# and checkout the source branch for committing changes to the site source.
system "git remote add origin #{repo_url}"
puts "Added remote #{repo_url} as origin"
system "git config branch.master.remote origin"
puts "Set origin as default remote"
system "git branch -m master source"
puts "Master branch renamed to 'source' for committing your site source files"
end
end
url = "http://#{user}.github.io"
url += "/#{project}" unless project == ''
rm_rf deploy_dir
mkdir deploy_dir
cd "#{deploy_dir}" do
system "git init"
system "echo 'My Awesome Page is coming soon …' > index.html"
system "git add ."
system "git commit -m \"initial commit\""
system "git branch -m gh-pages" unless branch == 'master'
system "git remote add origin #{repo_url}"
rakefile = IO.read(__FILE__)
rakefile.sub!(/deploy_branch(\s*)=(\s*)(["'])[\w-]*["']/, "deploy_branch\\1=\\2\\3#{branch}\\3")
File.open(__FILE__, 'w') do |f|
f.write rakefile
end
end
puts "\n---\n## Now you can deploy to #{url} with `rake deploy` ##"
end