class Middlesite::Cli

Public Instance Methods

build() click to toggle source
# File lib/middlesite/cli.rb, line 19
def build
  if options[:verbose]
    system "bundle exec middleman build --verbose"
  else
    system "bundle exec middleman build"
  end
end
bump(type="patch") click to toggle source
# File lib/middlesite/cli.rb, line 38
def bump(type="patch")
  # Get latest git tag
  raise Thor::Error, "Not a git repository!" unless Dir.exists?(".git")
  g = ::Git.open(".")
  raise Thor::Error, "Uncommitted git changes!" unless g.status.changed.empty?

  # checking for remote changes
  puts "Updating remote..."
  system "git remote update"
  raise Thor::Error, "Unmerged remote commits! Run: `git pull`!" unless g.gtree("HEAD..origin/master").log.first.nil?

  config = get_config()
  version = config["version"]

  # Bump version
  case type
  when "major"
    version = bump_major(version)
  when "minor"
    version = bump_minor(version)
  when "patch"
    version = bump_patch(version)
  else
    raise Thor::Error, "Unknown bump type!"
  end
  puts "Bumping version to: #{version}"

  # update config
  puts "Updating site config..."
  config["version"] = version
  set_config(config)

  # commit & add tag
  g.commit_all("release v#{version}")
  puts "Adding tag..."
  g.add_tag("v#{version}")
  g.repack

  # push
  puts "Pushing files..."
  g.push("origin", "master", true)
end
bump_major(version) click to toggle source
# File lib/middlesite/cli.rb, line 108
def bump_major(version)
  version = version.split(".")
  version[0] = version[0].to_i + 1
  version[1] = 0
  version[2] = 0
  version.join(".")
end
bump_minor(version) click to toggle source
# File lib/middlesite/cli.rb, line 100
def bump_minor(version)
  version = version.split(".")
  version[0] = version[0].to_i
  version[1] = version[1].to_i + 1
  version[2] = 0
  version.join(".")
end
bump_patch(version) click to toggle source
# File lib/middlesite/cli.rb, line 92
def bump_patch(version)
  version = version.split(".")
  version[0] = version[0].to_i
  version[1] = version[1].to_i
  version[2] = version[2].to_i + 1
  version.join(".")
end
deploy() click to toggle source
# File lib/middlesite/cli.rb, line 33
def deploy
  system "bundle exec middleman deploy"
end
get_config() click to toggle source
# File lib/middlesite/cli.rb, line 82
def get_config
  YAML::load(File.open("./data/site.yml"))
end
init() click to toggle source
# File lib/middlesite/cli.rb, line 9
def init
  puts "Installing gems..."
  system "bundle install"
  puts ""
  puts "Installing bower packages..."
  system "bower install"
end
server() click to toggle source
# File lib/middlesite/cli.rb, line 28
def server
  system "bundle exec middleman server"
end
set_config(config) click to toggle source
# File lib/middlesite/cli.rb, line 86
def set_config (config)
  File.open("./data/site.yml", "w") do |f|
    f.write(config.to_yaml)
  end
end