this works as `middleman deploy`

master
Tom Vaughan 2012-08-22 11:45:33 -07:00
parent c2364978e1
commit 13ccf115ab
3 changed files with 51 additions and 5 deletions

View File

@ -1,5 +1,7 @@
require "middleman-core"
require "middleman-deploy/commands"
::Middleman::Extensions.register(:deploy) do
require "middleman-deploy/extension"
::Middleman::Deploy

View File

@ -1 +1,36 @@
require "middleman-core/cli"
require "middleman-deploy/extension"
module Middleman
module Cli
# This class provides a "deploy" command for the middleman CLI.
class Deploy < Thor
include Thor::Actions
check_unknown_options!
namespace :deploy
# Tell Thor to exit with a nonzero exit code on failure
def self.exit_on_failure?
true
end
desc "deploy", "Deploy to a remote host over rsync"
def deploy
shared_instance = ::Middleman::Application.server.inst
# This only exists when the config.rb sets it!
if shared_instance.respond_to? :deploy
shared_instance.deploy(self)
else
raise Thor::Error.new "You need to activate the deploy extension in config.rb "
end
end
end
# Alias "d" to "deploy"
Base.map({ "d" => "deploy" })
end
end

View File

@ -7,7 +7,9 @@ module Middleman
class Options < Struct.new(:delete, :host, :port, :user, :path); end
class << self
def options
@@options
end
def registered(app, options_hash={}, &block)
options = Options.new(options_hash)
yield options if block_given?
@ -15,6 +17,10 @@ module Middleman
options.delete ||= false
options.port ||= 22
@@options = options
app.send :include, Helpers
app.after_configuration do
if (!options.host || !options.user || !options.path)
raise <<EOF
@ -32,13 +38,16 @@ end
EOF
end
end
app.after_build do |builder|
builder.run "rsync -avze '" + "ssh -p #{options.port}" + "' #{"--delete" if options.delete == true} build/ #{options.user}@#{options.host}:#{options.path}"
end
end
alias :included :registered
end
module Helpers
def deploy(builder)
options = ::Middleman::Deploy.options
builder.run "rsync -avze '" + "ssh -p #{options.port}" + "' #{"--delete" if options.delete == true} build/ #{options.user}@#{options.host}:#{options.path}"
end
end
end
end