Browse code

Somehow I replaced Rakefile with oder version, oops

Brandon Mathis authored on 25/08/2011 at 14:52:43
Showing 1 changed files
... ...
@@ -1,10 +1,11 @@
1 1
 require "rubygems"
2 2
 require "bundler/setup"
3
+require "stringex"
3 4
 
4 5
 ## -- Rsync Deploy config -- ##
5 6
 # Be sure your public key is listed in your server's ~/.ssh/authorized_keys file
6
-ssh_user       = "user@domain.com"
7
-document_root  = "~/website.com/"
7
+ssh_user       = "mathisweb@octopress.org"
8
+document_root  = "~/octopress.org/"
8 9
 deploy_default = "rsync"
9 10
 
10 11
 # This will be configured for you when you run config_deploy
... ...
@@ -51,13 +52,35 @@ end
51 51
 desc "Watch the site and regenerate when it changes"
52 52
 task :watch do
53 53
   raise "### You haven't set anything up yet. First run `rake install` to set up an Octopress theme." unless File.directory?(source_dir)
54
-  system "trap 'kill $jekyllPid $compassPid' Exit; jekyll --auto & jekyllPid=$!; compass watch & compassPid=$!; wait"
54
+  puts "Starting to watch source with Jekyll and Compass."
55
+  jekyllPid = spawn("jekyll --auto")
56
+  compassPid = spawn("compass watch")
57
+
58
+  trap("INT") {
59
+	Process.kill(9, jekyllPid)
60
+	Process.kill(9, compassPid)
61
+	exit 0
62
+  }
63
+
64
+  Process.wait
55 65
 end
56 66
 
57 67
 desc "preview the site in a web browser"
58 68
 task :preview do
59 69
   raise "### You haven't set anything up yet. First run `rake install` to set up an Octopress theme." unless File.directory?(source_dir)
60
-  system "trap 'kill $jekyllPid $compassPid $rackPid' Exit; jekyll --auto & jekyllPid=$!; compass watch & compassPid=$!; rackup --port #{server_port} & rackPid=$!; wait"
70
+  puts "Starting to watch source with Jekyll and Compass. Starting Rack on port #{server_port}"
71
+  jekyllPid = spawn("jekyll --auto")
72
+  compassPid = spawn("compass watch")
73
+  rackupPid = spawn("rackup --port #{server_port}")
74
+
75
+  trap("INT") {
76
+	Process.kill(9, jekyllPid)
77
+	Process.kill(9, compassPid)
78
+	Process.kill(9, rackupPid)
79
+	exit 0
80
+  }
81
+
82
+  Process.wait
61 83
 end
62 84
 
63 85
 # usage rake new_post[my-new-post] or rake new_post['my new post'] or rake new_post (defaults to "new-post")
... ...
@@ -68,7 +91,7 @@ task :new_post, :title do |t, args|
68 68
   mkdir_p "#{source_dir}/#{posts_dir}"
69 69
   args.with_defaults(:title => 'new-post')
70 70
   title = args.title
71
-  filename = "#{source_dir}/#{posts_dir}/#{Time.now.strftime('%Y-%m-%d')}-#{title.downcase.gsub(/&/,'and').gsub(/[,'":\?!\(\)\[\]]/,'').gsub(/[\W\.]/, '-').gsub(/-+$/,'')}.#{new_post_ext}"
71
+  filename = "#{source_dir}/#{posts_dir}/#{Time.now.strftime('%Y-%m-%d')}-#{title.to_url}.#{new_post_ext}"
72 72
   puts "Creating new post: #{filename}"
73 73
   open(filename, 'w') do |post|
74 74
     system "mkdir -p #{source_dir}/#{posts_dir}/";
... ...
@@ -129,7 +152,7 @@ end
129 129
 
130 130
 desc "Clean out caches: _code_cache, _gist_cache, .sass-cache"
131 131
 task :clean do
132
-  system "rm -rf _code_cache/** _gist_cache/** .sass-cache/** source/stylesheets/screen.css"
132
+  rm_rf ["_code_cache/**", "_gist_cache/**", ".sass-cache/**", "source/stylesheets/screen.css"]
133 133
 end
134 134
 
135 135
 desc "Move sass to sass.old, install sass theme updates, replace sass/custom with sass.old/custom"
... ...
@@ -137,11 +160,11 @@ task :update_style, :theme do |t, args|
137 137
   theme = args.theme || 'classic'
138 138
   if File.directory?("sass.old")
139 139
     puts "removed existing sass.old directory"
140
-    system "rm -r sass.old"
140
+    rm_r "sass.old", :secure=>true
141 141
   end
142
-  system "mv sass sass.old"
142
+  mv "sass", "sass.old"
143 143
   puts "## Moved styles into sass.old/"
144
-  system "mkdir -p sass; cp -R #{themes_dir}/"+theme+"/sass/* sass/"
144
+  cp_r "#{themes_dir}/"+theme+"/sass/", "sass"
145 145
   cp_r "sass.old/custom/.", "sass/custom"
146 146
   puts "## Updated Sass ##"
147 147
 end
... ...
@@ -151,15 +174,16 @@ task :update_source, :theme do |t, args|
151 151
   theme = args.theme || 'classic'
152 152
   if File.directory?("#{source_dir}.old")
153 153
     puts "removed existing #{source_dir}.old directory"
154
-    system "rm -r #{source_dir}.old"
154
+    rm_r "#{source_dir}.old", :secure=>true
155 155
   end
156
-  system "mv #{source_dir} #{source_dir}.old"
156
+  mv source_dir, "#{source_dir}.old"
157 157
   puts "moved #{source_dir} into #{source_dir}.old/"
158
-  system "mkdir -p #{source_dir}; cp -R #{themes_dir}/"+theme+"/source/. #{source_dir}"
159
-  system "cp -Rn #{source_dir}.old/. #{source_dir}"
160
-  system "cp -Rf #{source_dir}.old/_includes/custom/. #{source_dir}/_includes/custom/"
161
-  system "mv -f #{source_dir}/index.html #{blog_index_dir}" if blog_index_dir != source_dir
162
-  system "cp -f #{source_dir}.old/index.html #{source_dir}" if blog_index_dir != source_dir
158
+  mkdir_p source_dir
159
+  cp_r "#{themes_dir}/"+theme+"/source/.", source_dir
160
+  cp_r "#{source_dir}.old/.", source_dir, :preserve=>true
161
+  cp_r "#{source_dir}.old/_includes/custom/.", "#{source_dir}/_includes/custom/"
162
+  mv "#{source_dir}/index.html", "#{blog_index_dir}", :force=>true if blog_index_dir != source_dir
163
+  cp "#{source_dir}.old/index.html", source_dir if blog_index_dir != source_dir
163 164
   puts "## Updated #{source_dir} ##"
164 165
 end
165 166
 
... ...
@@ -168,7 +192,19 @@ end
168 168
 ##############
169 169
 
170 170
 desc "Default deploy task"
171
-task :deploy => "#{deploy_default}" do
171
+multitask :deploy => [:copydot, "#{deploy_default}"] do
172
+end
173
+
174
+desc "copy dot files for deployment"
175
+task :copydot do
176
+  cd "#{source_dir}" do
177
+    exclusions = [".", "..", ".DS_Store"]
178
+    Dir[".*"].each do |file|
179
+      if !File.directory?(file) && !exclusions.include?(file)
180
+        cp(file, "../#{public_dir}");
181
+      end
182
+    end
183
+  end
172 184
 end
173 185
 
174 186
 desc "Deploy website via rsync"
... ...
@@ -178,7 +214,7 @@ task :rsync do
178 178
 end
179 179
 
180 180
 desc "deploy public directory to github pages"
181
-task :push do
181
+multitask :push do
182 182
   puts "## Deploying branch to Github Pages "
183 183
   (Dir["#{deploy_dir}/*"]).each { |f| rm_rf(f) }
184 184
   system "cp -R #{public_dir}/* #{deploy_dir}"