Sha256: 07bb75483d5a565d0ca1afb198a3d0a99ff7004b6826c12cbddc0109f31653ba

Contents?: true

Size: 1.76 KB

Versions: 2

Compression:

Stored size: 1.76 KB

Contents

require 'middleman-core/cli'
require 'fjords-client'

module Middleman
  module Cli
    # This class provides an "article" command for the middleman CLI.
    class Fjords < Thor
      # include Thor::Actions
      
      check_unknown_options!

      namespace :fjords

      # Tell Thor to exit with a nonzero exit code on failure
      def self.exit_on_failure?
        true
      end

      desc "fjords [options]", "Deploy to Fjords.cc"
      method_option :rebuild, :type => :boolean, :default => false, :desc => 'Rebuild project before deploying'
      def fjords
        shared_instance = ::Middleman::Application.server.inst
        opts = shared_instance.fjords_options

        if !::Fjords::Client.logged_in?
          if !opts.username || !opts.password
            puts "Username and password are required"
            exit(1)
          end

          ::Fjords::Client.login(opts.username, opts.password)
        end

        if options["rebuild"] || opts.rebuild
          puts "Rebuilding..."
          puts `bundle exec middleman build`
        end

        # puts "Deploying..."
        cmd = "bundle exec fjords push"
        cmd << %Q{ --path="#{shared_instance.build_dir}" --no-progress}
        if opts.no_zip
          cmd << %Q{ --no-zip}
        end
        if opts.domain
          cmd << %Q{ --domain="#{opts.domain}"}
          cmd << %Q{ --overwrite}
        end
        # cmd << %Q{ --domain-file="#{opts.domain_file}"} if opts.domain_file

        require 'pty'
        begin
          PTY.spawn(cmd) do |stdin, stdout, pid|
            begin
              stdin.each { |line| print line }
            rescue Errno::EIO
            end
          end
        rescue PTY::ChildExited
          # puts "The child process exited!"
        end

      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
middleman-fjords-1.0.3 lib/middleman-fjords/commands/fjords.rb
middleman-fjords-1.0.1.1 lib/middleman-fjords/commands/fjords.rb