Module: CommonTasks

Included in:
JekyllGitDeploy
Defined in:
lib/helpers/common_tasks.rb

Constant Summary collapse

CONFIG_FILE =
"_config.yml"
CONFIG_DEFAULTS =
{
  "destination" => "_site",
  "deploy_branch" => "pages",
  "deploy_remote_name" => "deploy",
  "touch_file" => "Staticfile"
}
REQUIRED_CONFIGS =
%w(destination deploy_repo deploy_branch deploy_remote_name touch_file )

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/helpers/common_tasks.rb', line 44

def self.included(base)
  REQUIRED_CONFIGS.each do |method|
    define_method method do
      read_configs[method]
    end
  end
end

Instance Method Details

#checkout_target_branch(quiet = false) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/helpers/common_tasks.rb', line 33

def checkout_target_branch(quiet = false)
  unless current_branch == deploy_branch
    puts "\nStart to checkout to deploy branch: #{deploy_branch}".yellow unless quiet
    if `git show-branch #{deploy_branch} 2> /dev/null`.empty?  # the deploy branch didn't exist
      `git checkout -b #{deploy_branch}`
    else
      `git checkout #{deploy_branch}`
    end
  end
end

#commit_newest_siteObject



23
24
25
26
27
# File 'lib/helpers/common_tasks.rb', line 23

def commit_newest_site
  message = "Genereted site at #{Time.now}"
  puts "\ncommit the site: #{message}".yellow
  `git add -A . && git commit -m "#{message}"`
end

#current_branchObject



29
30
31
# File 'lib/helpers/common_tasks.rb', line 29

def current_branch
  `git rev-parse --abbrev-ref HEAD`.strip
end

#read_configsObject



13
14
15
16
17
18
19
20
21
# File 'lib/helpers/common_tasks.rb', line 13

def read_configs
  return @configs if @configs

  unless File.file?(CONFIG_FILE)
    raise "Can not find a config file, please check your current working directoy and ensure it is under the root of your jekyll site!".red
  end

  @configs = CONFIG_DEFAULTS.merge YAML.load_file("./#{CONFIG_FILE}")
end