Added github pages support

master
Ben Cates 2012-08-29 23:50:23 -04:00
parent c074f8d907
commit 4de34e8948
3 changed files with 48 additions and 13 deletions

View File

@ -18,18 +18,26 @@ module Middleman
true
end
desc "deploy", "Copy build directory to a remote host over rsync"
desc "deploy", "Copy build directory to a remote host"
method_option "clean",
:type => :boolean,
:aliases => "-c",
:desc => "Remove orphaned files or directories on the remote host"
def deploy
shared_inst = ::Middleman::Application.server.inst
send("deploy_#{self.middleman_options.method}")
end
host = shared_inst.options.host
port = shared_inst.options.port
user = shared_inst.options.user
path = shared_inst.options.path
protected
def middleman_options
::Middleman::Application.server.inst.options
end
def deploy_rsync
host = self.middleman_options.host
port = self.middleman_options.port
user = self.middleman_options.user
path = self.middleman_options.path
# These only exists when the config.rb sets them!
if (!host || !user || !path)
@ -51,6 +59,30 @@ module Middleman
run command
end
def deploy_git
puts "## Deploying to Github Pages"
Dir.mktmpdir do |tmp|
# clone ./ with branch gh-pages to tmp
repo = Git.clone(ENV['MM_ROOT'], tmp)
repo.checkout('origin/gh-pages', :new_branch => 'gh-pages')
# copy ./build/* to tmp
FileUtils.cp_r(Dir.glob(File.join(ENV['MM_ROOT'], 'build', '*')), tmp)
# git add and commit in tmp
repo.add
repo.commit("Automated commit at #{Time.now.utc}")
# push from tmp to self
repo.push('origin', 'gh-pages')
# push to github
github_url = Git.open(ENV['MM_ROOT']).remote.url
repo.add_remote('github', github_url)
repo.push('github', 'gh-pages')
end
end
end
# Alias "d" to "deploy"

View File

@ -5,7 +5,7 @@ require "middleman-core"
module Middleman
module Deploy
class Options < Struct.new(:host, :port, :user, :path, :clean); end
class Options < Struct.new(:method, :host, :port, :user, :path, :clean); end
class << self
@ -17,6 +17,7 @@ module Middleman
options = Options.new(options_hash)
yield options if block_given?
options.method ||= :rsync
options.port ||= 22
options.clean ||= false
@ -25,8 +26,9 @@ module Middleman
app.send :include, Helpers
app.after_configuration do
if (!options.host || !options.user || !options.path)
raise <<EOF
if (options.method == :rsync)
if (!options.host || !options.user || !options.path)
raise <<EOF
ERROR: middleman-deploy is not setup correctly. host, user, and path
@ -39,6 +41,7 @@ activate :deploy do |deploy|
end
EOF
end
end
end
end

View File

@ -6,11 +6,11 @@ Gem::Specification.new do |s|
s.name = Middleman::Deploy::PACKAGE
s.version = Middleman::Deploy::VERSION
s.platform = Gem::Platform::RUBY
s.authors = ["Tom Vaughan"]
s.authors = ["Tom Vaughan","Ben Cates"]
s.email = ["thomas.david.vaughan@gmail.com"]
s.homepage = "http://tvaughan.github.com/middleman-deploy/"
s.summary = %q{Deploy a middleman built site over rsync.}
s.description = %q{Deploy a middleman built site over rsync.}
s.summary = %q{Deploy a middleman built site over rsync or to github pages.}
s.description = %q{Deploy a middleman built site over rsync or to github pages.}
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@ -21,5 +21,5 @@ Gem::Specification.new do |s|
s.add_runtime_dependency("middleman-core", [">= 3.0.0"])
# Additional dependencies
# s.add_runtime_dependency("gem-name", "gem-version")
s.add_runtime_dependency("git", "~> 1.2.0")
end