2012-08-20 19:52:29 +02:00
|
|
|
# Require core library
|
|
|
|
require "middleman-core"
|
|
|
|
|
|
|
|
# Extension namespace
|
2012-08-20 21:59:32 +02:00
|
|
|
module Middleman
|
|
|
|
module Deploy
|
2012-08-21 00:10:40 +02:00
|
|
|
class Options < Struct.new(:delete, :host, :port, :user, :path); end
|
2012-08-20 23:24:17 +02:00
|
|
|
|
2012-08-20 21:59:32 +02:00
|
|
|
class << self
|
2012-08-22 20:45:33 +02:00
|
|
|
def options
|
|
|
|
@@options
|
|
|
|
end
|
2012-08-20 23:24:17 +02:00
|
|
|
def registered(app, options_hash={}, &block)
|
|
|
|
options = Options.new(options_hash)
|
|
|
|
yield options if block_given?
|
|
|
|
|
2012-08-21 00:10:40 +02:00
|
|
|
options.delete ||= false
|
2012-08-20 23:24:17 +02:00
|
|
|
options.port ||= 22
|
2012-08-20 21:59:32 +02:00
|
|
|
|
2012-08-22 20:45:33 +02:00
|
|
|
@@options = options
|
|
|
|
|
|
|
|
app.send :include, Helpers
|
|
|
|
|
2012-08-20 21:59:32 +02:00
|
|
|
app.after_configuration do
|
2012-08-20 23:24:17 +02:00
|
|
|
if (!options.host || !options.user || !options.path)
|
|
|
|
raise <<EOF
|
|
|
|
|
|
|
|
|
|
|
|
ERROR: middleman-deploy is not setup correctly. host, user, and path
|
2012-08-22 19:04:11 +02:00
|
|
|
*must* be set in config.rb. For example:
|
2012-08-20 23:24:17 +02:00
|
|
|
|
|
|
|
activate :deploy do |deploy|
|
|
|
|
deploy.user = "tvaughan"
|
|
|
|
deploy.host = "www.example.com"
|
|
|
|
deploy.path = "/srv/www/site"
|
|
|
|
end
|
2012-08-20 21:59:32 +02:00
|
|
|
|
2012-08-20 23:24:17 +02:00
|
|
|
EOF
|
|
|
|
end
|
2012-08-20 21:59:32 +02:00
|
|
|
end
|
2012-08-20 19:52:29 +02:00
|
|
|
end
|
2012-08-20 21:59:32 +02:00
|
|
|
alias :included :registered
|
2012-08-20 19:52:29 +02:00
|
|
|
end
|
|
|
|
|
2012-08-22 20:45:33 +02:00
|
|
|
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
|
|
|
|
|
2012-08-20 21:59:32 +02:00
|
|
|
end
|
2012-08-20 19:52:29 +02:00
|
|
|
end
|