Sha256: ccf36c6badcab233f7a0d5b53cb48a356a2abe35f866598aabfdef847db22c15

Contents?: true

Size: 1.41 KB

Versions: 1

Compression:

Stored size: 1.41 KB

Contents

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"
      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

        host = shared_inst.options.host
        port = shared_inst.options.port
        user = shared_inst.options.user
        path = shared_inst.options.path

        # These only exists when the config.rb sets them!
        if (!host || !user || !path)
          raise Thor::Error.new "You need to activate the deploy extension in config.rb "
        end

        command = "rsync -avze '" + "ssh -p #{port}" + "' build/ #{user}@#{host}:#{path}"

        if options.has_key? "clean"
          clean = options.clean
        else
          clean = shared_inst.options.clean
        end

        if clean
          command += "--delete"
        end

        run command
      end

    end

    # Alias "d" to "deploy"
    Base.map({ "d" => "deploy" })

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
middleman-deploy-0.0.1 lib/middleman-deploy/commands.rb