Browse code

improved rake tasks for deployment, updated .gitignore

Brandon Mathis authored on 21/06/2011 at 20:11:07
Showing 2 changed files
... ...
@@ -4,6 +4,7 @@
4 4
 _gist_cache
5 5
 _code_cache
6 6
 _assets
7
+_deploy
7 8
 public
8 9
 source/_stash
9 10
 vendor
... ...
@@ -1,10 +1,11 @@
1 1
 require "rubygems"
2 2
 require "bundler/setup"
3 3
 
4
-site        = "public"    # compiled site directory
5
-source      = "source"    # source file directory
6
-stash       = "_stash"    # directory to stash posts for speedy generation
7
-posts       = "_posts"    # directory for blog files
4
+public_dir  = "public"    # compiled site directory
5
+source_dir  = "source"    # source file directory
6
+deploy_dir  = "_deploy"    # deploy directory (for Github pages deployment)
7
+stash_dir   = "_stash"    # directory to stash posts for speedy generation
8
+posts_dir   = "_posts"    # directory for blog files
8 9
 post_format = "markdown"  # file format for new posts when using the post rake task
9 10
 
10 11
 ## -- Rsync Deploy config -- ##
... ...
@@ -12,23 +13,16 @@ post_format = "markdown"  # file format for new posts when using the post rake t
12 12
 ssh_user      = "mathisweb@imathis.com"
13 13
 document_root = "~/dev.octopress.org/"
14 14
 
15
-## -- Github Pages deploy config -- ##
16
-# Read http://pages.github.com for guidance
17
-# You can deploy to github pages with `rake push_github` or change the default push task to :push_github
18
-source_branch = "source" # this compiles to your deploy branch
19
-deploy_branch = "master" # For user pages, use "master" for project pages use "gh-pages"
20
-
21
-
22 15
 desc "Initial setup for Octopress: copies the default theme into the path of Jekyll's generator. rake install defaults to rake install[classic] to install a different theme run rake install[some_theme_name]"
23 16
 task :install, :theme do |t, args|
24 17
   # copy theme into working Jekyll directories
25 18
   theme = args.theme || 'classic'
26 19
   puts "## Copying "+theme+" theme to Jekyll paths"
27
-  system "mkdir -p #{source}; cp -R themes/"+theme+"/source/ #{source}/"
20
+  system "mkdir -p #{source_dir}; cp -R themes/"+theme+"/source/ #{source_dir}/"
28 21
   system "mkdir -p sass; cp -R themes/"+theme+"/sass/ sass/"
29 22
   system "mkdir -p _plugins; cp -R themes/"+theme+"/_plugins/ _plugins/"
30
-  system "mkdir -p #{source}/#{posts}";
31
-  puts "## Layouts, images, and javascritps from the #{theme} theme have been installed into ./#{source}"
23
+  system "mkdir -p #{source_dir}/#{posts_dir}";
24
+  puts "## Layouts, images, and javascritps from the #{theme} theme have been installed into ./#{source_dir}"
32 25
   puts "## Sass stylesheet sources from the #{theme} theme have been installed into ./sass"
33 26
   puts "## Plugins from the #{theme} theme have been installed into ./_plugins"
34 27
 end
... ...
@@ -48,12 +42,12 @@ task :preview do
48 48
 end
49 49
 
50 50
 # usage rake post[my-new-post] or rake post['my new post'] or rake post (defaults to "new-post")
51
-desc "Begin a new post in #{source}/_posts"
51
+desc "Begin a new post in #{source_dir}/_posts"
52 52
 task :post, :filename do |t, args|
53 53
   require './_plugins/titlecase.rb'
54 54
   args.with_defaults(:filename => 'new-post')
55
-  open("#{source}/_posts/#{Time.now.strftime('%Y-%m-%d')}-#{args.filename.downcase.gsub(/[ _]/, '-')}.#{post_format}", 'w') do |post|
56
-    system "mkdir -p #{source}/#{posts}";
55
+  open("#{source_dir}/_posts/#{Time.now.strftime('%Y-%m-%d')}-#{args.filename.downcase.gsub(/[ _]/, '-')}.#{post_format}", 'w') do |post|
56
+    system "mkdir -p #{source_dir}/#{posts_dir}";
57 57
     post.puts "---"
58 58
     post.puts "title: #{args.filename.gsub(/[-_]/, ' ').titlecase}"
59 59
     post.puts "date: #{Time.now.strftime('%Y-%m-%d %H:%M')}"
... ...
@@ -65,16 +59,16 @@ end
65 65
 # usage rake isolate[my-post]
66 66
 desc "Move all other posts than the one currently being worked on to a temporary stash location (stash) so regenerating the site happens much quicker."
67 67
 task :isolate, :filename do |t, args|
68
-  stash_dir = "#{source}/#{stash}"
68
+  stash_dir = "#{source_dir}/#{stash_dir}"
69 69
   FileUtils.mkdir(stash_dir) unless File.exist?(stash_dir)
70
-  Dir.glob("#{source}/#{posts}/*.*") do |post|
70
+  Dir.glob("#{source_dir}/#{posts_dir}/*.*") do |post|
71 71
     FileUtils.mv post, stash_dir unless post.include?(args.filename)
72 72
   end
73 73
 end
74 74
 
75 75
 desc "Move all stashed posts back into the posts directory, ready for site generation."
76 76
 task :integrate do
77
-  FileUtils.mv Dir.glob("#{source}/#{stash}/*.*"), "#{source}/#{posts}/"
77
+  FileUtils.mv Dir.glob("#{source_dir}/#{stash_dir}/*.*"), "#{source_dir}/#{posts_dir}/"
78 78
 end
79 79
 
80 80
 desc "Clean out caches: _code_cache, _gist_cache, .sass-cache"
... ...
@@ -112,29 +106,25 @@ end
112 112
 desc "Deploy website via rsync"
113 113
 task :push_rsync do
114 114
   puts "## Deploying website via Rsync"
115
-  ok_failed system("rsync -avz --delete #{site}/ #{ssh_user}:#{document_root}")
115
+  ok_failed system("rsync -avz --delete #{public_dir}/ #{ssh_user}:#{document_root}")
116 116
 end
117 117
 
118
-desc "deploy website to github pages"
118
+desc "deploy public directory to github pages"
119 119
 multitask :push_github do
120
-  puts "## Deploying #{deploy_branch} branch to Github Pages "
121
-  require 'git'
122
-  repo = Git.open('.')
123
-  puts "\n## Checking out #{deploy_branch} branch \n"
124
-  repo.branch("#{deploy_branch}").checkout
125
-  (Dir["*"] - ["#{site}"]).each { |f| rm_rf(f) }
126
-  Dir["#{site}/*"].each {|f| mv(f, ".")}
127
-  rm_rf("#{site}")
128
-  puts "\n## Moving generated /#{site} files \n"
129
-  Dir["**/*"].each {|f| repo.add(f) }
130
-  repo.status.deleted.each {|f, s| repo.remove(f)}
131
-  puts "\n## Commiting: Site updated at #{Time.now.utc} \n"
132
-  message = ENV["MESSAGE"] || "Site updated at #{Time.now.utc}"
133
-  repo.commit(message)
134
-  puts "\n## Pushing generated /#{site} files to #{deploy_branch} branch\n"
135
-  repo.push
136
-  puts "\n## Github Pages deploy complete\n"
137
-  repo.branch("#{source_branch}").checkout
120
+  puts "## Deploying branch to Github Pages "
121
+  (Dir["#{deploy_dir}/*"]).each { |f| rm_rf(f) }
122
+  system "cp -R #{public_dir}/ #{deploy_dir}"
123
+  puts "\n## copying #{public_dir} to #{deploy_dir}"
124
+  cd "#{deploy_dir}" do
125
+    system "git add ."
126
+    system "git add -u"
127
+    puts "\n## Commiting: Site updated at #{Time.now.utc}"
128
+    message = "Site updated at #{Time.now.utc}"
129
+    system "git commit -m '#{message}'"
130
+    puts "\n## Pushing generated #{deploy_dir} website"
131
+    system "git push"
132
+    puts "\n## Github Pages deploy complete"
133
+  end
138 134
 end
139 135
 
140 136
 
... ...
@@ -144,3 +134,4 @@ task :list do
144 144
   puts "Tasks: #{(Rake::Task.tasks - [Rake::Task[:list]]).to_sentence}"
145 145
   puts "(type rake -T for more detail)\n\n"
146 146
 end
147
+