Class: Jekyll::Commands::Deploy

Inherits:
Command
  • Object
show all
Defined in:
lib/jekyll_deploy.rb

Class Method Summary collapse

Class Method Details

.clean_build(options) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'lib/jekyll_deploy.rb', line 37

def clean_build(options)
  options = configuration_from_options(options)
  destination = options['destination']

  if File.directory? destination
    FileUtils.rm_rf(destination)
  end

  Jekyll::Commands::Build.process(options)
end

.deploy_git(site_destination, repo, branch) ⇒ Object



48
49
50
51
52
53
54
55
56
# File 'lib/jekyll_deploy.rb', line 48

def deploy_git(site_destination, repo, branch)
  run_shell([
    "git init",
    "git add .",
    "git commit -m \"Build\"",
    "git remote add origin \"#{repo}\"",
    "git push origin master:#{branch} --force"
  ], site_destination)
end

.deploy_rsync(site_destination, host, user, directory) ⇒ Object



58
59
60
61
62
63
# File 'lib/jekyll_deploy.rb', line 58

def deploy_rsync(site_destination, host, user, directory)
  site_destination << '/' unless site_destination.end_with?('/')
  directory << '/' unless directory.end_with?('/')

  run_shell("rsync -avr --delete #{site_destination} #{user}@#{host}:#{directory}", Dir.pwd)
end

.init_with_program(prog) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/jekyll_deploy.rb', line 7

def init_with_program(prog)
  prog.command(:deploy) do |c|
    c.syntax "deploy"
    c.description 'Deploys the Jekyll site.'

    c.action do |args, options|
      options["serving"] = false
      Deploy.process(options)
    end
  end
end

.process(options) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/jekyll_deploy.rb', line 19

def process(options)
    clean_build(options)

    options = configuration_from_options(options)
    destination = options['destination']
    site = Jekyll::Site.new(options)
    settings = site.config['deployment']

    case settings['type']
      when 'git'
        deploy_git(destination, settings['repo'], settings['branch'])
      when 'rsync'
        deploy_rsync(destination, settings['host'], settings['user'], settings['directory'])
      else
        raise "Unknown deployment type #{settings['type']}"
    end
end

.run_shell(cmds, dir) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/jekyll_deploy.rb', line 65

def run_shell(cmds, dir)
  success = true
  cmds = [cmds] unless cmds.is_a? Array
  pwd_old = Dir.pwd

  Dir.chdir(dir)
  cmds.each { |cmd|
    if success and not system(cmd)
      success = false
    end
  }
  Dir.chdir(pwd_old)

  success
end