Class: Jekyll::Commands::Deploy

Inherits:
Command
  • Object
show all
Defined in:
lib/jekyll/commands/deploy.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.init_with_program(prog) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/jekyll/commands/deploy.rb', line 9

def init_with_program(prog)
  prog.command(:deploy) do |c|
    c.syntax 'deploy'
    c.description 'Deploys the contents of the currently built site.'
    c.option 'config',  '--config CONFIG_FILE[,CONFIG_FILE2,...]', Array, 'Custom configuration file'
    c.option 'destination', '-d', '--destination DESTINATION', 'The current folder will be generated into DESTINATION'
    c.option 'verbose', '-V', '--verbose', 'Print verbose output.'
    c.alias :d

    c.action do |args, options|
      Jekyll::Commands::Deploy.process(options)
    end
  end

  def process(options)
    # Adjust verbosity quickly
    Jekyll.logger.adjust_verbosity(options)

    options = configuration_from_options(options)

    deploy = options.fetch('deploy', [])
    if !deploy.is_a?(Array) || !deploy.all? { |d| d.is_a?(String) }
      Jekyll.logger.error "Invalid deploy options."
    elsif deploy.length == 0
      Jekyll.logger.error "No deploy commands specified."
    else
      Jekyll.logger.info "Working directory:", options['destination']
      deploy.each do |command|
        unless execute(command, options['destination'])
          Jekyll.logger.error "Deploy aborted."
          break
        end
      end
    end
  end

  def execute(command, directory)
    t = Time.now
    Jekyll.logger.info "Executing '#{command}'..."
    output, status = Open3.capture2(command, :chdir => directory)
    output.each_line { |line| Jekyll.logger.debug line.chomp }
    if status.success?
      Jekyll.logger.info "", "done in #{(Time.now - t).round(3)} seconds."
    else
      if status.exited?
        Jekyll.logger.error "", "failed with status code #{status.exitstatus} in #{(Time.now - t).round(3)} seconds."
      else
        Jekyll.logger.error "", "aborted in #{(Time.now - t).round(3)} seconds."
      end
    end
    status.success?
  end
end

Instance Method Details

#execute(command, directory) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/jekyll/commands/deploy.rb', line 45

def execute(command, directory)
  t = Time.now
  Jekyll.logger.info "Executing '#{command}'..."
  output, status = Open3.capture2(command, :chdir => directory)
  output.each_line { |line| Jekyll.logger.debug line.chomp }
  if status.success?
    Jekyll.logger.info "", "done in #{(Time.now - t).round(3)} seconds."
  else
    if status.exited?
      Jekyll.logger.error "", "failed with status code #{status.exitstatus} in #{(Time.now - t).round(3)} seconds."
    else
      Jekyll.logger.error "", "aborted in #{(Time.now - t).round(3)} seconds."
    end
  end
  status.success?
end

#process(options) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/jekyll/commands/deploy.rb', line 23

def process(options)
  # Adjust verbosity quickly
  Jekyll.logger.adjust_verbosity(options)

  options = configuration_from_options(options)

  deploy = options.fetch('deploy', [])
  if !deploy.is_a?(Array) || !deploy.all? { |d| d.is_a?(String) }
    Jekyll.logger.error "Invalid deploy options."
  elsif deploy.length == 0
    Jekyll.logger.error "No deploy commands specified."
  else
    Jekyll.logger.info "Working directory:", options['destination']
    deploy.each do |command|
      unless execute(command, options['destination'])
        Jekyll.logger.error "Deploy aborted."
        break
      end
    end
  end
end